mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #100] Can't switch focus when using Flex #76
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#76
Loading…
Add table
Add a link
Reference in a new issue
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?
Originally created by @arguablykomodo on GitHub (Apr 14, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/100
Let's say you have this example code:
if you were to compile and run this code, you would get the following output:
But for some reason, you cannot press TAB to switch over to the second button, there's just no way to switch.
Am i not doing this correctly? Or is it a bug? Are you allowed to switch focus when using Flex?
(I am using windows 10 and go 1.10.1)
@rivo commented on GitHub (Apr 14, 2018):
Primitives such as the button are independent of each other. So they wouldn't know what to do when Tab is pressed. And
Flexis just a layout primitive. It doesn't process any keys.You could use
Form. It allows you to add buttons. And it handles the Tab key, advancing the focus to the next button when it is pressed.Alternatively, you can install your own input handler on a button using
SetInputCapture(). You listen for the Tab key and callapp.SetFocus()to move the focus to a different button.Let me know if this helps.
@arguablykomodo commented on GitHub (Apr 14, 2018):
Thanks for the response! It really helps me a lot
@ethantrithon commented on GitHub (Feb 14, 2020):
is "app.SetFocus" the ONLY way to give focus to some other primitive? this seems rather hack-y to me, especially given the fact you might not have access to the actual application object at all times.
can we do this internally somehow? or if not, how is it done ideally?
@arguablykomodo commented on GitHub (Feb 14, 2020):
This is how i implemented it, and I must admit that it looks very hacky and it would be quite a hassle to work with this code if i were to add new UI elements. Maybe some system in which the app cycles through the different inputs in the order they were added would be more ideal.
@ghost commented on GitHub (Jan 19, 2021):
Just leaving this here for anyone else who wants to implement it. A small tweak on @SrKomodo's implementation to make it more generic. Putting all of your inputs into a slice and passing them to this function will cycle through each one in order.
Can be used in this context:
@rivo commented on GitHub (Jan 21, 2021):
Btw, if it helps, you can now intercept key events on the
FlexandGridlevel, too.