2
20
Fork
You've already forked nodgui
4

Handling focus #34

Open
opened 2025年09月29日 03:22:45 +02:00 by defaultxr · 7 comments
Contributor
Copy link

Hi.

I'm going back to my sequencer project now and I'm not sure how to handle this situation:

I have a text box, i.e. (make-text ...). I want the user to be able to press space to insert a space into the text box when it's selected/focused, but when the text box isn't focused, space should perform a different action.

I also want to be able to switch the currently-focused widget using <Ctrl-tab>. I have the text box, but I also have several canvases ((make-canvas ...)) - four by default, but it's possible for there to be more or less than that. So I'm not sure how to write a function that will cycle through each focusable widget in the correct order. I see that nodgui:bind-tag-set-focus-next is a function that exists and the warning in set-focus-next makes it sound like bind-tag-set-focus-next is what I will need to use, but it seems that it requires the currently-focused widget as its first argument, and I don't think Nodgui has a function to get the currently-focused widget. It looks like Tk has a focus_get function but it seems that Nodgui doesn't have this yet. I tried implementing it myself but I'm pretty sure I"m doing something wrong. I also thought maybe I could just use (event-widget event) in the function that <Ctrl-tab> is being bound to, but event-widget doesn't exist either.

So, I'm curious how you'd handle implementing something like this, if you have any suggestions.

Hi. I'm going back to my sequencer project now and I'm not sure how to handle this situation: I have a text box, i.e. `(make-text ...)`. I want the user to be able to press space to insert a space into the text box when it's selected/focused, but when the text box isn't focused, space should perform a different action. I also want to be able to switch the currently-focused widget using `<Ctrl-tab>`. I have the text box, but I also have several canvases (`(make-canvas ...)`) - four by default, but it's possible for there to be more or less than that. So I'm not sure how to write a function that will cycle through each focusable widget in the correct order. I see that `nodgui:bind-tag-set-focus-next` is a function that exists and the warning in `set-focus-next` makes it sound like `bind-tag-set-focus-next` is what I will need to use, but it seems that it requires the currently-focused widget as its first argument, and I don't think Nodgui has a function to get the currently-focused widget. It looks like Tk has a `focus_get` function but it seems that Nodgui doesn't have this yet. I tried implementing it myself but I'm pretty sure I"m doing something wrong. I also thought maybe I could just use `(event-widget event)` in the function that `<Ctrl-tab>` is being bound to, but `event-widget` doesn't exist either. So, I'm curious how you'd handle implementing something like this, if you have any suggestions.
Author
Contributor
Copy link

Also, I think (setf (text textbox) ...) has a bug? When I do (setf (text textbox) "[foo]") the textbox's text is set to \[foo\] (including the backslashes).

Also, I think `(setf (text textbox) ...)` has a bug? When I do `(setf (text textbox) "[foo]")` the textbox's text is set to `\[foo\]` (including the backslashes).
Author
Contributor
Copy link

Also, when I change (make-instance 'frame ...) to (make-instance 'scrolled-frame ...) it puts the scrollbar in a weird place. Does this happen for you? My use of (make-instance 'frame ...) works totally fine so I'm not sure what I would be doing wrong to make the scrollbar show up like this. The only change I made is changing 'frame to 'scrolled-frame.

Also, when I change `(make-instance 'frame ...)` to `(make-instance 'scrolled-frame ...)` it puts the scrollbar in a weird place. Does this happen for you? My use of `(make-instance 'frame ...)` works totally fine so I'm not sure what I would be doing wrong to make the scrollbar show up like this. The only change I made is changing `'frame` to `'scrolled-frame`.
Owner
Copy link

Hi!

@defaultxr wrote in #34 (comment):

Also, I think (setf (text textbox) ...) has a bug? When I do (setf (text textbox) "[foo]") the textbox's text is set to \[foo\] (including the backslashes).

This is definitely a bug. I am opening a separate issue for that.

Bye!
C.

Hi! @defaultxr wrote in https://codeberg.org/cage/nodgui/issues/34#issuecomment-7423219: > Also, I think `(setf (text textbox) ...)` has a bug? When I do `(setf (text textbox) "[foo]")` the textbox's text is set to `\[foo\]` (including the backslashes). This is definitely a bug. I am opening a separate issue for that. Bye! C.
Owner
Copy link

@defaultxr wrote in #34 (comment):

Also, when I change (make-instance 'frame ...) to (make-instance 'scrolled-frame ...) it puts the scrollbar in a weird place. Does this happen for you?

Honestly no, but despite being TK boring technology, sometimes it is able to surprise you anyway! 😄

Can you please, show a minimal example that reproduce the bug? Or, alternatively, instruction to reproduce the bug?

Bye!
C.

@defaultxr wrote in https://codeberg.org/cage/nodgui/issues/34#issuecomment-7423618: > Also, when I change `(make-instance 'frame ...)` to `(make-instance 'scrolled-frame ...)` it puts the scrollbar in a weird place. Does this happen for you? Honestly no, but despite being TK boring technology, sometimes it is able to surprise you anyway! 😄 Can you please, show a minimal example that reproduce the bug? Or, alternatively, instruction to reproduce the bug? Bye! C.
Owner
Copy link

@defaultxr wrote in #34 (comment):

Hi.

I'm going back to my sequencer project

Happy to hear that! 😄

It looks like Tk has a focus_get function but it seems that Nodgui doesn't have this yet.

I think should be implemented, if possible. Likely i just need just pass to the TK interpreter the command focus , without arguments.

Let's see if this works!

I tried implementing it myself but I'm pretty sure I"m doing something wrong. I also thought maybe I could just use (event-widget event) in the function that <Ctrl-tab> is being bound to, but event-widget doesn't exist either.

So, I'm curious how you'd handle implementing something like this, if you have any suggestions.

Maybe is fire-events a function that could help you?

https://codeberg.org/cage/nodgui/src/branch/master/src/events.lisp#L193

Thanks for helping improving the library!
C.

@defaultxr wrote in https://codeberg.org/cage/nodgui/issues/34#issue-2444059: > Hi. > > I'm going back to my sequencer project Happy to hear that! 😄 > It looks like Tk has a `focus_get` function but it seems that Nodgui doesn't have this yet. I think should be implemented, if possible. Likely i just need just pass to the TK interpreter the command `focus` , without arguments. Let's see if this works! > > > I tried implementing it myself but I'm pretty sure I"m doing something wrong. I also thought maybe I could just use `(event-widget event)` in the function that `<Ctrl-tab>` is being bound to, but `event-widget` doesn't exist either. > > So, I'm curious how you'd handle implementing something like this, if you have any suggestions. Maybe is `fire-events` a function that could help you? https://codeberg.org/cage/nodgui/src/branch/master/src/events.lisp#L193 Thanks for helping improving the library! C.
Owner
Copy link

Hi @defaultxr !

I have added a function: widget-with-focus that i think could help you (and other people too, i hope!). Please take a look the following code, when run, will print the widget that got the focus:

(defun test ()
 (with-nodgui ()
 (let* ((frame (make-instance 'frame))
 (button (make-instance 'button :text "test" :master frame)))
 (grid button 0 0)
 (grid frame 0 0)
 (force-focus button)
 (wait-complete-redraw)
 (format t
 "focus to ~a~%"
 (widget-with-focus)))))

Bye!
C.

Hi @defaultxr ! I have added a function: `widget-with-focus` that i think could help you (and other people too, i hope!). Please take a look the following code, when run, will print the widget that got the focus: ``` lisp (defun test () (with-nodgui () (let* ((frame (make-instance 'frame)) (button (make-instance 'button :text "test" :master frame))) (grid button 0 0) (grid frame 0 0) (force-focus button) (wait-complete-redraw) (format t "focus to ~a~%" (widget-with-focus))))) ``` Bye! C.
Owner
Copy link

@cage wrote in #34 (comment):

Hi @defaultxr !

Also, I think (setf (text textbox) ...) has a bug? When I do (setf (text textbox) "[foo]") the textbox's text is set to \[foo\] (including the backslashes).

I tried the code below but i was unable to reproduce the issue, can you please, provide some code to get the bug on my machine?

Thanks in advance!
C.

(in-package :nodgui)
(defun main ()
 (with-nodgui ()
 (let ((textarea (make-instance 'scrolled-text))
 (scrolled-textarea (make-instance 'text)))
 (grid-implicit (list textarea scrolled-textarea))
 (wait-complete-redraw)
 (setf (text textarea) "[foo]")
 (setf (text scrolled-textarea) "[bar]"))))
@cage wrote in https://codeberg.org/cage/nodgui/issues/34#issuecomment-7443964: Hi @defaultxr ! > > Also, I think `(setf (text textbox) ...)` has a bug? When I do `(setf (text textbox) "[foo]")` the textbox's text is set to `\[foo\]` (including the backslashes). I tried the code below but i was unable to reproduce the issue, can you please, provide some code to get the bug on my machine? Thanks in advance! C. ``` lisp (in-package :nodgui) (defun main () (with-nodgui () (let ((textarea (make-instance 'scrolled-text)) (scrolled-textarea (make-instance 'text))) (grid-implicit (list textarea scrolled-textarea)) (wait-complete-redraw) (setf (text textarea) "[foo]") (setf (text scrolled-textarea) "[bar]")))) ```
Sign in to join this conversation.
No Branch/Tag specified
master
development
v0.7.6.5
v0.7.6.4
v0.7.6.3
v0.7.6.2
v0.7.6.1
v0.7.6.0
v0.7.5.1
v0.7.5.0
v0.7.4.0
v0.7.3.5
v0.7.3.4
v0.7.3.3
v0.7.3.2
v0.7.3.1
v0.7.3.0
v0.7.2.1
v0.7.2.0
v0.7.1.3
v0.7.1.2
v0.7.1.1
v0.7.1.0
v0.7.0.4
v0.7.0.3
v0.7.0.2
v0.7.0.1
v0.7.0.0
v0.6.2.1
v0.6.2.0
v0.6.1.2
v0.6.1.1
v0.6.1.0
v0.4.9.6
v0.4.9.3
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cage/nodgui#34
Reference in a new issue
cage/nodgui
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?