mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-09 13:18:58 +00:00
129 lines
No EOL
4.2 KiB
Text
129 lines
No EOL
4.2 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// 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 <bool> horizontal;
|
|
in-out property<length> maximum;
|
|
in-out property<length> page-size;
|
|
// this is always negative and bigger than -maximum
|
|
in-out property<length> value;
|
|
in-out property<bool> 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 <length> 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 <length> viewport-width <=> fli.viewport-width;
|
|
in-out property <length> viewport-height <=> fli.viewport-height;
|
|
in-out property <length> viewport-x <=> fli.viewport-x;
|
|
in-out property <length> viewport-y <=> fli.viewport-y;
|
|
out property <length> visible-width <=> fli.width;
|
|
out property <length> visible-height <=> fli.height;
|
|
in property <bool> enabled: true;
|
|
in-out property <bool> 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;
|
|
}
|
|
} |