mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 04:45:13 +00:00

Instead of having all style duplicated and re-using a base, we just hack into the funciton that queries the dark/light theme based on the style suffix known at compile time. This removes one of the problem that happens when trying to work on the widget style with the extension, as it relies on include path hacks
128 lines
3.9 KiB
Text
128 lines
3.9 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
import { FluentPalette, FluentFontSettings, Icons } from "styling.slint";
|
|
import { SpinBoxBase } from "../common/spinbox-base.slint";
|
|
|
|
component SpinBoxButton {
|
|
callback clicked <=> touch-area.clicked;
|
|
|
|
in property <image> icon <=> icon.source;
|
|
|
|
min-width: 28px;
|
|
horizontal-stretch: 0;
|
|
|
|
states [
|
|
pressed when touch-area.pressed : {
|
|
background.background: FluentPalette.subtle;
|
|
}
|
|
]
|
|
|
|
background := Rectangle {
|
|
border-radius: 3px;
|
|
|
|
icon := Image {
|
|
image-fit: contain;
|
|
colorize: FluentPalette.text-secondary;
|
|
width: 12px;
|
|
|
|
animate colorize { duration: 150ms; }
|
|
}
|
|
}
|
|
|
|
touch-area := TouchArea {}
|
|
}
|
|
|
|
export component SpinBox {
|
|
in property <int> minimum <=> base.minimum;
|
|
in property <int> maximum <=> base.maximum;
|
|
in property <bool> enabled <=> base.enabled;
|
|
in property <int> step-size <=> base.step-size;
|
|
out property <bool> has-focus <=> base.has-focus;
|
|
in-out property <int> value <=> base.value;
|
|
|
|
callback edited <=> base.edited;
|
|
|
|
min-width: 128px;
|
|
min-height: 30px;
|
|
vertical-stretch: 0;
|
|
horizontal-stretch: 1;
|
|
forward-focus: base;
|
|
|
|
accessible-role: spinbox;
|
|
accessible-value: root.value;
|
|
accessible-value-minimum: root.minimum;
|
|
accessible-value-maximum: root.maximum;
|
|
accessible-value-step: (root.maximum - root.minimum) / 100;
|
|
accessible-action-set-value(v) => { if v.is-float() { base.update-value(v.to-float()); } }
|
|
accessible-action-increment => { base.increment(); }
|
|
accessible-action-decrement => { base.decrement(); }
|
|
|
|
states [
|
|
disabled when !root.enabled : {
|
|
background.background: FluentPalette.control-disabled;
|
|
background.border-color: FluentPalette.border;
|
|
base.color: FluentPalette.text-disabled;
|
|
base.selection-foreground-color: FluentPalette.text-accent-foreground-disabled;
|
|
}
|
|
focused when root.has-focus : {
|
|
background.background: FluentPalette.control-input-active;
|
|
background.border-color: FluentPalette.border;
|
|
focus-border.background: FluentPalette.accent-background;
|
|
}
|
|
]
|
|
|
|
background := Rectangle {
|
|
border-radius: 4px;
|
|
background: FluentPalette.control-background;
|
|
border-width: 1px;
|
|
border-color: FluentPalette.text-control-border;
|
|
|
|
layout := HorizontalLayout {
|
|
padding-left: 12px;
|
|
padding-right: 2px;
|
|
padding-top: 4px;
|
|
padding-bottom: 4px;
|
|
spacing: 4px;
|
|
|
|
Rectangle {
|
|
clip: true;
|
|
horizontal-stretch: 1;
|
|
|
|
base := SpinBoxBase {
|
|
width: 100%;
|
|
color: FluentPalette.control-foreground;
|
|
font-size: FluentFontSettings.body.font-size;
|
|
font-weight: FluentFontSettings.body.font-weight;
|
|
selection-background-color: FluentPalette.selection-background;
|
|
selection-foreground-color: FluentPalette.accent-foreground;
|
|
}
|
|
}
|
|
|
|
SpinBoxButton {
|
|
visible: root.enabled;
|
|
icon: Icons.chevron-up;
|
|
|
|
clicked => {
|
|
base.increment();
|
|
}
|
|
}
|
|
|
|
SpinBoxButton {
|
|
visible: root.enabled;
|
|
icon: Icons.chevron-down;
|
|
|
|
clicked => {
|
|
base.decrement();
|
|
}
|
|
}
|
|
}
|
|
|
|
focus-border := Rectangle {
|
|
x: parent.border-radius;
|
|
y: parent.height - self.height;
|
|
width: parent.width - 2 * parent.border-radius;
|
|
height: 2px;
|
|
}
|
|
}
|
|
}
|