mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-27 12:29:41 +00:00
198 lines
5.9 KiB
Text
198 lines
5.9 KiB
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
|
|
|
|
import { Palette, Typography, Icons } from "styling.slint";
|
|
import { SpinBoxBase } from "../common/spinbox-base.slint";
|
|
|
|
component SpinBoxButton inherits Rectangle {
|
|
callback clicked <=> i-touch-area.clicked;
|
|
|
|
in-out property <bool> pressed: self.enabled && i-touch-area.pressed;
|
|
in-out property <bool> enabled <=> i-touch-area.enabled;
|
|
in-out property <float> icon-opacity: 1;
|
|
in-out property <brush> icon-fill: Palette.on-primary;
|
|
|
|
width: root.height;
|
|
|
|
i-background := Rectangle {
|
|
width: 100%;
|
|
height: 100%;
|
|
border-radius: max(self.width, self.height) / 2;
|
|
background: Palette.primary;
|
|
}
|
|
|
|
i-state-layer := Rectangle {
|
|
x: 0;
|
|
y: 0;
|
|
opacity: 0;
|
|
width: i-background.width;
|
|
height: i-background.height;
|
|
border-radius: i-background.border-radius;
|
|
background: Palette.on-primary;
|
|
|
|
animate opacity { duration: 250ms; easing: ease; }
|
|
}
|
|
|
|
Rectangle {
|
|
width: 100%;
|
|
height: 100%;
|
|
|
|
@children
|
|
}
|
|
|
|
i-touch-area := TouchArea { }
|
|
|
|
states [
|
|
disabled when !root.enabled : {
|
|
i-background.background: Palette.on-surface;
|
|
i-background.opacity: 0.12;
|
|
icon-opacity: 0.38;
|
|
icon-fill: Palette.on-surface;
|
|
}
|
|
pressed when i-touch-area.pressed : {
|
|
i-state-layer.opacity: 0.12;
|
|
}
|
|
hover when i-touch-area.has-hover : {
|
|
i-state-layer.opacity: 0.08;
|
|
}
|
|
]
|
|
}
|
|
|
|
// Increment and decrement a value in the given range.
|
|
export component SpinBox {
|
|
callback edited(int /* value */);
|
|
|
|
in property <int> minimum <=> i-base.minimum;
|
|
in property <int> maximum <=> i-base.maximum;
|
|
in property <bool> enabled <=> i-base.enabled;
|
|
out property <bool> has-focus <=> i-text-input.has-focus;
|
|
in-out property <int> value <=> i-base.value;
|
|
|
|
forward-focus: i-text-input;
|
|
horizontal-stretch: 1;
|
|
vertical-stretch: 0;
|
|
min-width: i-layout.min-width;
|
|
min-height: max(56px, i-layout.min-height);
|
|
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;
|
|
|
|
i-base := SpinBoxBase {
|
|
width: 100%;
|
|
height: 100%;
|
|
|
|
edited(value) => {
|
|
i-text-input.text = value;
|
|
root.edited(value);
|
|
}
|
|
}
|
|
|
|
i-background := Rectangle {
|
|
border-radius: 4px;
|
|
border-width: 1px;
|
|
border-color: Palette.outline;
|
|
|
|
i-layout := HorizontalLayout {
|
|
padding-top: 8px;
|
|
padding-bottom: 8px;
|
|
padding-left: 16px;
|
|
padding-right: 12px;
|
|
spacing: 16px;
|
|
|
|
Rectangle {
|
|
clip: true;
|
|
|
|
i-text-input := TextInput {
|
|
vertical-alignment: center;
|
|
horizontal-alignment: left;
|
|
text: root.value;
|
|
// height: 100%;
|
|
color: Palette.on-surface;
|
|
// FIXME after Roboto font can be loaded
|
|
//font-family: Typography.body-large.font;
|
|
font-size: Typography.body-large.font-size;
|
|
font-weight: Typography.body-large.font-weight;
|
|
enabled: root.enabled;
|
|
horizontal-stretch: 1;
|
|
|
|
accepted => {
|
|
if (self.text == "") {
|
|
i-base.update-value(root.minimum);
|
|
}
|
|
}
|
|
|
|
edited => {
|
|
if (self.text == "") {
|
|
i-base.update-value(root.minimum);
|
|
return;
|
|
}
|
|
|
|
if (self.text.is-float()) {
|
|
i-base.update-value(root.value + 1);
|
|
return;
|
|
}
|
|
|
|
self.text = root.value;
|
|
}
|
|
}
|
|
|
|
i-touch-area := TouchArea {
|
|
clicked => {
|
|
i-text-input.focus();
|
|
}
|
|
}
|
|
}
|
|
|
|
VerticalLayout {
|
|
spacing: 4px;
|
|
|
|
SpinBoxButton {
|
|
enabled: root.enabled;
|
|
|
|
Image {
|
|
x: (parent.width - self.width) / 2;
|
|
y: (parent.height - self.height) / 2;
|
|
source: Icons.arrow-drop-up;
|
|
opacity: parent.icon-opacity;
|
|
colorize: parent.icon-fill;
|
|
}
|
|
|
|
clicked => {
|
|
i-base.increment();
|
|
}
|
|
}
|
|
|
|
SpinBoxButton {
|
|
enabled: root.enabled;
|
|
|
|
Image {
|
|
x: (parent.width - self.width) / 2;
|
|
y: (parent.height - self.height) / 2;
|
|
source: Icons.arrow-drop-down;
|
|
opacity: parent.icon-opacity;
|
|
colorize: parent.icon-fill;
|
|
}
|
|
|
|
clicked => {
|
|
i-base.decrement();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
states [
|
|
disabled when !root.enabled : {
|
|
i-background.border-color: Palette.on-surface;
|
|
i-background.opacity: 0.38;
|
|
i-text-input.opacity: 0.38;
|
|
}
|
|
focused when root.has-focus : {
|
|
i-background.border-width: 2px;
|
|
i-background.border-color: Palette.primary;
|
|
i-text-input.color: Palette.primary;
|
|
}
|
|
]
|
|
}
|