slint/internal/compiler/widgets/qt/slider.slint
Simon Hausmann 6fefe75a1c Don't require components that use forward-focus to be inlined
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.
2024-01-26 12:16:09 +01:00

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
}
}
}
}