-
Notifications
You must be signed in to change notification settings - Fork 578
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
Cooperation between focus components #6390
Comments
As a side-note: The reason why the above code doesn't work is because |
For the specific case of up and down in a LineEdit, Qt doesn't go to the beginning or end of the line with up or down. Most application have their own function (like up and down in a preselect) Although a Also related: #4337 I didn't fully understood routed event. How would it translate in Slint? Should FocusScope gain new callback such as |
The event system in WPF is really complex but powerful. You can work with predefined like key events and mouse events or you could also implement custom events. Then you can trigger events from a node e.g. from a custom controls, that bubbles from this node along the tree to the leafs and tunnels back to the origin node until the event is handled (accepted). Exampleexport component EventDemo {
FocusScope {
preview-key-pressed(event) => {
if event.text == Key.DownArrow {
// return accept to stop bubbling and to not handle additional arrow up in LineEdit
return accept;
}
// return reject to allow rest events to continue bubbleling
reject
}
key-pressed => {
// will not reached by events handled by the LineEdit
}
LineEdit {}
}
} In these example the key pressed event stares to bubble from the window. |
Let me just quickly reference event capturing in browsers, since nobody seems to have done that yet: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#usecapture. |
I think the web's model is likely one of legacy, but oddly the combination of capturing and bubbling still makes sense and would for us, too. So how would that look like in practice?
|
The capture concept is a bit strange. Right now, for example, the line edit intercept the key press event, but not the key release event, as can be shown in this example For pointer event it is easier to grab, but for the keyboard, there are repetition and many keys. Should there be a grab for each keys or for the whole keyboard?
That's hard to maintain as what happens if the focus changes between the two passes (because the "capture" event changes the focus, or changes the tree. Should that be forbidden? So in other word, I'm not sure |
Note that grab != capture. Capturing is just the name of the phase used in the DOM, it's not related to grabbing. |
If the focus event changes the focus somewhere along the way, the entire remaining part of capturing (or bubbling) is aborted anyway, isn't it? (unless the focus changes but the filter claims that it didn't handle it)
We could call it filter in the callbacks, but we need to give a name of this phase or way of propagating events to the target element in our documentation. |
(FWIW, I'm not entirely sold on this, I just wanted to outline how one possible solution could look like for Slint in a manner that we could explain/document and that resembles the web then) |
What I suggest is: When a key is pressed, the event first triggers the In retrospect, we probably should have had pressed (and released) event processed from parent to child only, from the beginning. But it is too late to change. Other name suggestion
|
|
I'm also not a fan of the term In terms of traversal, I think we should determine the path upfront, i.e. from the target focus element go back up forwards (parent, parent.parent, etc.) and collect all the possible interceptors, and then start with the outermost interceptor candidate, and work our way back towards the target focus element. |
Currently it is really hard to implement something like an autocomplete box. Where you need an element e.g.
LineEdit
to enter text to filter your list and to check for down arrow and up arrow key events to navigate between the items in your list.Example
The problem is if
LineEdit
has focus thenFocuScope
does not have focus and you cannot check if the arrow keys are pressed.We should start to think and define how a solution for this problem could looks like.
One thing that could be possible is something like Routed Events in WPF, with bubbling events from source to leafs and after that from the leafs back to source. An eventhandler that is part of this path can decided if it wants to handle (
accept
) the event or toreject
it, what means the next event handler has the opportunity to handle the event instead.The text was updated successfully, but these errors were encountered: