mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-03 07:04:34 +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
183 lines
5.4 KiB
Text
183 lines
5.4 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 { CupertinoPalette, CupertinoFontSettings, Icons } from "styling.slint";
|
|
import { FocusBorder } from "components.slint";
|
|
import { SpinBoxBase } from "../common/spinbox-base.slint";
|
|
|
|
component SpinBoxButton {
|
|
in property <bool> enabled <=> touch-area.enabled;
|
|
in property <image> icon <=> icon.source;
|
|
|
|
callback clicked <=> touch-area.clicked;
|
|
|
|
private property <brush> background: CupertinoPalette.accent-background;
|
|
private property <brush> icon-color: CupertinoPalette.accent-foreground;
|
|
|
|
min-width: 16px;
|
|
horizontal-stretch: 0;
|
|
|
|
states [
|
|
disabled when !touch-area.enabled : {
|
|
opacity: 0.5;
|
|
icon-color: CupertinoPalette.foreground-secondary;
|
|
}
|
|
pressed when touch-area.pressed : {
|
|
root.background: CupertinoPalette.secondary-accent-background;
|
|
}
|
|
]
|
|
|
|
Rectangle {
|
|
y: (parent.height - self.height) / 2;
|
|
width: 14px;
|
|
height: self.width;
|
|
|
|
animate background { duration: 150ms; }
|
|
|
|
if (root.enabled) : Rectangle {
|
|
width: 100%;
|
|
height: 100%;
|
|
border-radius: 4px;
|
|
background: root.background;
|
|
drop-shadow-blur: 3px;
|
|
drop-shadow-color: #00000066;
|
|
drop-shadow-offset-y: 0.5px;
|
|
|
|
Rectangle {
|
|
drop-shadow-blur: 2px;
|
|
drop-shadow-color: #00000026;
|
|
drop-shadow-offset-y: 1px;
|
|
border-radius: parent.border-radius;
|
|
background: root.background;
|
|
}
|
|
|
|
Rectangle {
|
|
drop-shadow-blur: 1px;
|
|
drop-shadow-color: #00000026;
|
|
drop-shadow-offset-y: 0.5px;
|
|
border-radius: parent.border-radius;
|
|
background: root.background;
|
|
}
|
|
|
|
Rectangle {
|
|
border-radius: parent.border-radius;
|
|
background: CupertinoPalette.dimmer;
|
|
opacity: 0.17;
|
|
}
|
|
|
|
}
|
|
|
|
icon := Image {
|
|
image-fit: contain;
|
|
colorize: root.icon-color;
|
|
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;
|
|
|
|
private property <brush> background: CupertinoPalette.control-background;
|
|
|
|
min-width: 128px;
|
|
min-height: max(22px, layout.min-height);
|
|
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 : {
|
|
base.color: CupertinoPalette.foreground-secondary;
|
|
root.background: CupertinoPalette.tertiary-control-background;
|
|
}
|
|
]
|
|
|
|
FocusBorder {
|
|
x: (parent.width - self.width) / 2;
|
|
y: (parent.height - self.height) / 2;
|
|
width: parent.width + 6px;
|
|
height: parent.height + 6px;
|
|
border-radius: 8px;
|
|
has-focus: root.has-focus;
|
|
}
|
|
|
|
Rectangle {
|
|
drop-shadow-blur: 0.25px;
|
|
drop-shadow-color: #00000066;
|
|
drop-shadow-offset-y: 0.25px;
|
|
border-radius: 5px;
|
|
background: root.background;
|
|
|
|
Rectangle {
|
|
drop-shadow-blur: 1px;
|
|
drop-shadow-color: #00000026;
|
|
drop-shadow-offset-y: 1px;
|
|
border-radius: parent.border-radius;
|
|
background: root.background;
|
|
border-width: 1px;
|
|
border-color: CupertinoPalette.decent-border;
|
|
opacity: root.enabled ? 1 : 0.5;
|
|
}
|
|
}
|
|
|
|
layout := HorizontalLayout {
|
|
padding-left: 7px;
|
|
padding-right: 2px;
|
|
spacing: 2px;
|
|
|
|
Rectangle {
|
|
clip: true;
|
|
horizontal-stretch: 1;
|
|
|
|
base := SpinBoxBase {
|
|
width: 100%;
|
|
color: CupertinoPalette.foreground;
|
|
font-size: CupertinoFontSettings.body.font-size;
|
|
font-weight: CupertinoFontSettings.body.font-weight;
|
|
selection-background-color: CupertinoPalette.selection-background;
|
|
selection-foreground-color: self.color;
|
|
}
|
|
}
|
|
|
|
SpinBoxButton {
|
|
visible: root.enabled;
|
|
icon: Icons.chevron-up;
|
|
enabled: root.enabled;
|
|
|
|
clicked => {
|
|
base.increment();
|
|
}
|
|
}
|
|
|
|
SpinBoxButton {
|
|
visible: root.enabled;
|
|
icon: Icons.chevron-down;
|
|
enabled: root.enabled;
|
|
|
|
clicked => {
|
|
base.decrement();
|
|
}
|
|
}
|
|
}
|
|
}
|