// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.0 OR LicenseRef-Slint-commercial import { Palette } from "styling.slint"; component ScrollBar inherits Rectangle { in-out property horizontal; in-out property maximum; in-out property page-size; // this is always negative and bigger than -maximum in-out property value; in-out property enabled <=> i-touch-area.enabled; i-state-layer := Rectangle { width: 100%; height: 100%; background: Palette.primary; border-radius: 4px; opacity: 0; visible: i-handle.width > 0 && i-handle.height > 0; animate opacity { duration: 250ms; easing: ease; } } i-handle := Rectangle { x: !root.horizontal ? 0phx : (root.width - i-handle.width) * (-root.value / root.maximum); y: root.horizontal ? 0phx : (root.height - i-handle.height) * (-root.value / root.maximum); width: !root.horizontal ? parent.width : root.maximum <= 0phx ? 0phx : max(32px, parent.width * max(root.page-size / (root.maximum + root.page-size))); height: root.horizontal ? parent.height : root.maximum <= 0phx ? 0phx : max(32px, parent.height * (root.page-size / (root.maximum + root.page-size))); i-background := Rectangle { width: 100%; height: 100%; border-radius: 4px; border-color: Palette.outline; border-width: 1px; } } 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.width - i-handle.width)) : (i-touch-area.mouse-y - i-touch-area.pressed-y) * (root.maximum / (root.height - i-handle.height)) ))); } } } states [ disabled when !i-touch-area.enabled : { i-background.border-color: Palette.on-surface; i-handle.opacity: 0.12; } hover when i-touch-area.has-hover : { i-state-layer.opacity: 0.08; } pressed when i-touch-area.has-hover : { i-state-layer.opacity: 0.12; } ] } // Scrollview contains a viewport that is bigger than the view and can be scrolled. export component ScrollView { in-out property viewport-width <=> fli.viewport-width; in-out property viewport-height <=> fli.viewport-height; in-out property viewport-x <=> fli.viewport-x; in-out property viewport-y <=> fli.viewport-y; out property visible-width <=> fli.width; out property visible-height <=> fli.height; in property enabled: true; in-out property has-focus; min-height: 50px; min-width: 50px; horizontal-stretch: 1; vertical-stretch: 1; preferred-height: 100%; preferred-width: 100%; Rectangle { background: Palette.surface; } fli := Flickable { x:0;y:0; interactive: false; viewport-y <=> vbar.value; viewport-x <=> hbar.value; width: parent.width - vbar.width - 4px; height: parent.height - hbar.height - 4px; @children } vbar := ScrollBar { width: 8px; x: fli.width + fli.x; y: fli.y; height: fli.height; horizontal: false; maximum: fli.viewport-height - fli.height; page-size: fli.height; enabled: root.enabled; } hbar := ScrollBar { height: 8px; y: fli.height + fli.y; x: fli.x; width: fli.width; horizontal: true; maximum: fli.viewport-width - fli.width; page-size: fli.width; enabled: root.enabled; } }