mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-08 20:58:40 +00:00

Achieve this by generating a `focus()` function for such components and call it from the outside. This replaces the previous focus handling with what should be cleaner: - Any `forward-focus: some-element;` is basically syntactic sugar for `public function focus() { some-element.focus(); }`. - The init code gets simplified to calling focus() on the root, if it's available. Since the `focus()` functions are now generated in the imports pass, they become visible in the style checker. That means the checker requires consistent focus handling between the styles.
30 lines
1,009 B
Text
30 lines
1,009 B
Text
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
|
|
|
|
export component Slider inherits NativeSlider {
|
|
out property <bool> has-focus: i-focus-scope.has-focus;
|
|
|
|
accessible-role: slider;
|
|
accessible-value: root.value;
|
|
accessible-value-minimum: root.minimum;
|
|
accessible-value-maximum: root.maximum;
|
|
accessible-value-step: (root.maximum - root.minimum) / 100;
|
|
forward-focus: i-focus-scope;
|
|
|
|
i-focus-scope := FocusScope {
|
|
x: 0;
|
|
width: 0;
|
|
|
|
key-pressed(event) => {
|
|
if (root.enabled && event.text == Key.RightArrow) {
|
|
root.value = Math.min(root.value + 1, root.maximum);
|
|
accept
|
|
} else if (root.enabled && event.text == Key.LeftArrow) {
|
|
root.value = Math.max(root.value - 1, root.minimum);
|
|
accept
|
|
} else {
|
|
reject
|
|
}
|
|
}
|
|
}
|
|
}
|