slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.09k stars 576 forks source link

Cascading Keyboard Events #4337

Open Kees-van-Beilen opened 8 months ago

Kees-van-Beilen commented 8 months ago

Currently creating buttons that have keyboard shortcuts attached to them is a pain. I recommend something similar to FocusScope with a small change, where on objects with focus can accept or reject a keyboard event. In case of rejection the event gets cascaded to its children.

Would this be possible?

hunger commented 8 months ago

So you want some keyboard shortcut that will trigger some Button. I guess those should work with any element having focus and as long as your application has window focus?

In case there is a global shortcut conflicting with a shortcut on a focused TextArea, which one should get triggered? Would you expect the Button with that shortcut to get triggered or the action on the focused TextEdit to be taken?

ogoffart commented 8 months ago

This was also discussed in https://github.com/slint-ui/slint/discussions/4063 I think we should indeed have a filter-key-pressed or something on the FocusScope.

Kees-van-Beilen commented 8 months ago

I think we should mimic something likes Apple's first responder system. Though, how hard would it be to implement waterfall events? It could be an option on the FocusScope. If a waterfall-unused-events (at least for key events now) bool sounds good, I'll implement it.