Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple default widgets #219

Open
ecton opened this issue Nov 24, 2024 · 1 comment
Open

Support multiple default widgets #219

ecton opened this issue Nov 24, 2024 · 1 comment

Comments

@ecton
Copy link
Member

ecton commented Nov 24, 2024

From a Discord discussion, @danbulant was asking about how to handle directing the enter key to submitting a form more easily than overriding on_key on everything. I pointed to Default widgets but the limitation is that they are one-per-window.

This spawned a thought for me: what if we can support multiple default widgets. Perhaps each time focus is shifted, an "active default" widget is chosen by determining which default widget available has the shortest "tree distance" between itself and the currently focused widget. This widget can then show the default styling, and as the keyboard focus shifts around the window the default widget will shift based on the tree distance.

What is the tree distance? I think it is the sum of the distance between each widget and the closest common ancestor. This should mean that form widgets that are contained within the same layout container will be preferred since the distance between the button and each widget and the layout container will be smaller than the distance to any other widget outside of that layout container.

@danbulant
Copy link
Contributor

Another idea would be to have a Form widget which would explicitly wrap the elements for submitting data, and have default button/widget send that event up (though that would require documentation that a form widget must exist as a parent somewhere - maybe window could panic if it received this event? Or window could accept those events and process them too?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants