// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.0 OR LicenseRef-Slint-commercial import { md } from "md.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 <=> touch.enabled; state_layer := Rectangle { width: 100%; height: 100%; background: md.sys.color.primary; border-radius: 4px; opacity: 0; visible: handle.width > 0 && handle.height > 0; animate opacity { duration: 250ms; easing: ease; } } handle := Rectangle { x: !root.horizontal ? 0phx : (root.width - handle.width) * (-root.value / root.maximum); y: root.horizontal ? 0phx : (root.height - 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))); container := Rectangle { width: 100%; height: 100%; border-radius: 4px; border-color: md.sys.color.outline; border-width: 1px; } } touch := 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 ? (touch.mouse-x - touch.pressed-x) * (root.maximum / (root.width - handle.width)) : (touch.mouse-y - touch.pressed-y) * (root.maximum / (root.height - handle.height)) ))); } } } states [ disabled when !touch.enabled : { container.border-color: md.sys.color.on-surface; handle.opacity: 0.12; } hover when touch.has-hover : { state-layer.opacity: 0.08; } pressed when touch.has-hover : { 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: md.sys.color.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; } }