Description
Feature Description
Currently the FocusScope can either be enabled, which makes it focusable by tabulator key or mouse click, or disabled, which does not make it focusable at all. However, in some cases one wants to make a component focusable only by keyboard or only by mouse click. In Qt this can be controlled with the Qt::FocusPolicy
on any widget. I think a property like that would make sense on the FocusScope.
In addition, when an element gets focus, in some cases we need to know the reason why it got the focus. A basic example is a text input which selects the whole text when it gets the focus by keyboard, but not when it is clicked.
Currently we can only react on the has-focus
property:
component MySpecialTextEdit {
TextInput {
changed has-focus => {
if self.has-focus {
self.select-all(); // Should be done only by keyboard focus, not by mouse click!
}
}
}
}
I think FocusScope should have a callback like focused(reason: FocusReason)
so we can decide on the passed focus reason what we want to do. Possibly the focus()
function should also get a parameter to pass the reason, but it may not be needed as tab-focus and click-focus is handled internally in FocusScope.
Interestingly in Qt the Qt::FocusReason
contains even several more focus reasons. It may make sense to consider carefully which of them make sense for Slint too.
Btw, a focus-lost()
callback might be useful too. Actually there's already a focus-changed-event()
but it does not seem to have any advantage over a changed has-focus => {}
handler, it does not even tell if it was a focus-in or focus-out 🤔
Product Impact
No response