// Copyright © SixtyFPS GmbH // 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 { callback clicked <=> i-touch-area.clicked; in property icon <=> i-icon.source; min-width: 28px; horizontal-stretch: 0; states [ pressed when i-touch-area.pressed : { i-background.background: Palette.subtle; } ] i-background := Rectangle { border-radius: 3px; i-icon := Image { image-fit: contain; colorize: Palette.text-secondary; width: 12px; animate colorize { duration: 150ms; } } } i-touch-area := TouchArea {} } export component SpinBox { in property minimum <=> i-base.minimum; in property maximum <=> i-base.maximum; in property enabled <=> i-base.enabled; out property has-focus <=> i-text-input.has-focus; in-out property value <=> i-base.value; callback edited( /* value */ int); min-width: 128px; min-height: 30px; 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; states [ disabled when !root.enabled : { i-background.background: Palette.control-disabled; i-background.border-color: Palette.control-stroke; i-text-input.color: Palette.text-disabled; i-text-input.selection-foreground-color: Palette.text-on-accent-disabled; } focused when root.has-focus : { i-background.background: Palette.control-input-active; i-background.border-color: Palette.control-stroke; i-focus-border.background: Palette.accent-default; } ] i-base := SpinBoxBase { width: 100%; height: 100%; edited(value) => { i-text-input.text = value; root.edited(value); } } i-background := Rectangle { border-radius: 4px; background: Palette.control-default; border-width: 1px; border-color: Palette.text-control-border; i-layout := HorizontalLayout { padding-left: 12px; padding-right: 2px; padding-top: 4px; padding-bottom: 4px; spacing: 4px; Rectangle { clip: true; i-text-input := TextInput { vertical-alignment: center; horizontal-alignment: left; color: Palette.text-primary; font-size: Typography.body.font-size; font-weight: Typography.body.font-weight; selection-background-color: Palette.accent-selected-text; selection-foreground-color: Palette.text-on-accent-primary; horizontal-stretch: 1; text: root.value; enabled: root.enabled; accepted => { if (!self.text.is-float()) { self.text = root.value; } } edited => { if (self.text.is-float()) { i-base.update-value(self.text.to-float()); } } } i-touch-area := TouchArea { clicked => { i-text-input.focus(); } } } SpinBoxButton { visible: root.enabled; icon: Icons.chevron-up; clicked => { i-base.increment(); } } SpinBoxButton { visible: root.enabled; icon: Icons.chevron-down; clicked => { i-base.decrement(); } } } i-focus-border := Rectangle { x: parent.border-radius; y: parent.height - self.height; width: parent.width - 2 * parent.border-radius; height: 2px; } } }