// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 import { CosmicPalette } from "styling.slint"; import { StateLayerBase } from "components.slint"; import { SliderBase } from "../common/slider-base.slint"; export component Slider { in property orientation <=> base.orientation; in property maximum <=> base.maximum; in property minimum <=> base.minimum; in property step <=> base.step; in property enabled <=> base.enabled; out property has-focus: base.has-focus; in-out property value <=> base.value; callback changed <=> base.changed; callback released <=> base.released; min-width: base.vertical ? 20px : 0px; min-height: base.vertical ? 0px : 20px; vertical-stretch: base.vertical ? 1 : 0; horizontal-stretch: base.vertical ? 0 : 1; accessible-role: slider; accessible-enabled: root.enabled; accessible-value: root.value; accessible-value-minimum: root.minimum; accessible-value-maximum: root.maximum; accessible-value-step: min(root.step, (root.maximum - root.minimum) / 100); forward-focus: base; states [ disabled when !root.enabled : { opacity: 0.5; } ] rail := Rectangle { width: base.vertical ? 4px : parent.width; height: base.vertical ? parent.height : 4px; background: CosmicPalette.neutral-6-background; border-radius: 2px; } track := Rectangle { x: base.vertical ? (parent.width - self.width) / 2 : 0; y: base.vertical ? 0 : (parent.height - self.height) / 2; width: base.vertical ? rail.width : thumb.x + (thumb.width / 2); height: base.vertical ? thumb.y + (thumb.height / 2) : rail.height; background: CosmicPalette.secondary-accent-background; border-radius: rail.border-radius; } thumb := Rectangle { x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.width - self.width); y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.height - self.height) : (parent.height - self.height) / 2; width: 20px; height: self.width; border-radius: 10px; background: CosmicPalette.accent-background; StateLayerBase { width: parent.width + 8px; height: parent.height + 8px; border-radius: max(self.width, self.height) / 2; enabled: root.enabled; focus-boder-margin: 0px; pressed: base.handle-pressed; has-hover: base.has-hover; has-focus: root.has-focus; } } base := SliderBase { width: 100%; height: 100%; handle-x: thumb.x; handle-y: thumb.y; handle-width: thumb.width; handle-height: thumb.height; } }