// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial import { Palette, Icons } from "styling.slint"; export component ScrollBar inherits Rectangle { private property track-size: root.horizontal ? root.width - 2 * root.offset : root.height - 2 * offset; private property step-size: 10px; private property offset: 2px; private property pad: 2px; in property enabled; out property has-hover: i-touch-area.has-hover; in-out property horizontal; in-out property maximum; in-out property page-size; in-out property value; background: transparent; i-border := Rectangle { x: 0; y: 0; width: !root.horizontal ? 0.8px : parent.width; height: !root.horizontal ? parent.height : 0.8px; background: transparent; } i-thumb := Rectangle { width: !root.horizontal ? parent.width - 2 * root.pad : root.maximum <= 0phx ? 0phx : max(32px, root.track-size * root.page-size / (root.maximum + root.page-size)); height: root.horizontal ? parent.height - 2 * root.pad : root.maximum <= 0phx ? 0phx : max(32px, root.track-size * (root.page-size / (root.maximum + root.page-size))); x: !root.horizontal ? (parent.width - self.width) / 2 : root.offset + (root.track-size - i-thumb.width) * (-root.value / root.maximum); y: root.horizontal ? (parent.height - self.height) / 2 : root.offset + (root.track-size - i-thumb.height) * (-root.value / root.maximum); border-radius: (root.horizontal ? self.height : self.width) / 2; background: Palette.foreground; opacity: 0.6; border-width: 0.8px; border-color: Palette.foreground-neg; animate width, height { duration: 100ms; easing: ease-out; } } i-touch-area := TouchArea { property pressed-value; width: parent.width; height: parent.height; pointer-event(event) => { if (event.button == PointerEventButton.left && event.kind == PointerEventKind.down) { self.pressed-value = -root.value; } } moved => { if (self.enabled && self.pressed) { root.value = -max(0px, min(root.maximum, self.pressed-value + ( root.horizontal ? (i-touch-area.mouse-x - i-touch-area.pressed-x) * (root.maximum / (root.track-size - i-thumb.width)) : (i-touch-area.mouse-y - i-touch-area.pressed-y) * (root.maximum / (root.track-size - i-thumb.height)) ))); } } scroll-event(event) => { if (root.horizontal && event.delta-x != 0) { root.value = max(-root.maximum, min(0px, root.value + event.delta-x)); return accept; } else if (!root.horizontal && event.delta-y != 0) { root.value = max(-root.maximum, min(0px, root.value + event.delta-y)); return accept; } reject } } states [ hover when i-touch-area.has-hover : { background: Palette.foreground.with-alpha(0.2); i-border.background: Palette.foreground.with-alpha(0.2); pad: 4px; } ] animate width, height, pad, background { duration: 150ms; easing: ease-out; } } export component ScrollView { in property enabled: true; out property visible-width <=> i-flickable.width; out property visible-height <=> i-flickable.height; in-out property viewport-width <=> i-flickable.viewport-width; in-out property viewport-height <=> i-flickable.viewport-height; in-out property viewport-x <=> i-flickable.viewport-x; in-out property viewport-y <=> i-flickable.viewport-y; // FIXME: remove. This property is currently set by the ListView and is used by the native style to draw the scrollbar differently when it has focus in-out property has-focus; min-height: 50px; min-width: 50px; horizontal-stretch: 1; vertical-stretch: 1; preferred-height: 100%; preferred-width: 100%; i-flickable := Flickable { x: 2px; y: 2px; interactive: false; viewport-y <=> i-vertical-bar.value; viewport-x <=> i-horizontal-bar.value; width: 100%; height: 100%; @children } i-vertical-bar := ScrollBar { enabled: root.enabled; x: parent.width - self.width; y: 0; width: self.has-hover ? 20px : 12px; height: i-horizontal-bar.visible ? parent.height - i-horizontal-bar.height : parent.height; horizontal: false; maximum: i-flickable.viewport-height - i-flickable.height; page-size: i-flickable.height; visible: i-flickable.viewport-height > i-flickable.height; } i-horizontal-bar := ScrollBar { enabled: root.enabled; width: i-vertical-bar.visible ? parent.width - i-vertical-bar.width : parent.width; height: self.has-hover ? 20px : 12px; y: parent.height - self.height; x: 0; horizontal: true; maximum: i-flickable.viewport-width - i-flickable.width; page-size: i-flickable.width; visible: i-flickable.viewport-width > i-flickable.width; } }