mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-27 12:29:41 +00:00
216 lines
No EOL
6 KiB
Text
216 lines
No EOL
6 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 { FocusBorder } from "components.slint";
|
|
import { SpinBoxBase } from "../common/spinbox-base.slint";
|
|
|
|
component SpinBoxButton {
|
|
private property <brush> background: Palette.accent;
|
|
private property <brush> icon-color: Palette.on-surface;
|
|
|
|
callback clicked <=> i-touch-area.clicked;
|
|
|
|
in property <bool> enabled <=> i-touch-area.enabled;
|
|
in property <image> icon <=> i-icon.source;
|
|
|
|
min-width: 16px;
|
|
horizontal-stretch: 0;
|
|
|
|
Rectangle {
|
|
y: (parent.height - self.height) / 2;
|
|
width: 14px;
|
|
height: self.width;
|
|
|
|
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: Palette.dimmer;
|
|
opacity: 0.17;
|
|
}
|
|
|
|
}
|
|
|
|
i-icon := Image {
|
|
image-fit: contain;
|
|
colorize: root.icon-color;
|
|
width: 12px;
|
|
|
|
animate colorize { duration: 150ms; }
|
|
}
|
|
|
|
animate background { duration: 150ms; }
|
|
}
|
|
|
|
i-touch-area := TouchArea {}
|
|
|
|
states [
|
|
disabled when !i-touch-area.enabled : {
|
|
opacity: 0.5;
|
|
icon-color: Palette.foreground-secondary;
|
|
}
|
|
pressed when i-touch-area.pressed : {
|
|
root.background: Palette.accent-secondary;
|
|
}
|
|
]
|
|
}
|
|
|
|
export component SpinBox {
|
|
private property <brush> background: Palette.surface;
|
|
|
|
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;
|
|
|
|
min-width: 128px;
|
|
min-height: max(22px, i-layout.min-height);
|
|
vertical-stretch: 0;
|
|
horizontal-stretch: 1;
|
|
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);
|
|
}
|
|
}
|
|
|
|
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: Palette.decent-border;
|
|
opacity: root.enabled ? 1 : 0.5;
|
|
}
|
|
}
|
|
|
|
i-layout := HorizontalLayout {
|
|
padding-left: 7px;
|
|
padding-right: 2px;
|
|
spacing: 2px;
|
|
|
|
Rectangle {
|
|
clip: true;
|
|
|
|
i-text-input := TextInput {
|
|
vertical-alignment: center;
|
|
horizontal-alignment: left;
|
|
color: Palette.foreground;
|
|
font-size: Typography.body.font-size;
|
|
font-weight: Typography.body.font-weight;
|
|
selection-background-color: Palette.accent-quaternary;
|
|
selection-foreground-color: self.color;
|
|
horizontal-stretch: 1;
|
|
text: root.value;
|
|
enabled: root.enabled;
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
SpinBoxButton {
|
|
visible: root.enabled;
|
|
icon: Icons.chevron-up;
|
|
enabled: root.enabled;
|
|
|
|
clicked => {
|
|
i-base.increment();
|
|
}
|
|
}
|
|
|
|
SpinBoxButton {
|
|
visible: root.enabled;
|
|
icon: Icons.chevron-down;
|
|
enabled: root.enabled;
|
|
|
|
clicked => {
|
|
i-base.decrement();
|
|
}
|
|
}
|
|
}
|
|
|
|
states [
|
|
disabled when !root.enabled : {
|
|
i-text-input.color: Palette.foreground-secondary;
|
|
root.background: Palette.surface-tertiary;
|
|
}
|
|
]
|
|
} |