From 783a711799a0576dd82eede465aca93202ba90b4 Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 22 Jun 2020 13:48:55 -0400 Subject: [PATCH] Customized themable scrollbars --- src/gui/Base/HScrollBar.qml | 29 +++++++++++++++++++++++++++++ src/themes/Glass.qpl | 12 ++++++++++++ src/themes/Midnight.qpl | 12 ++++++++++++ 3 files changed, 53 insertions(+) diff --git a/src/gui/Base/HScrollBar.qml b/src/gui/Base/HScrollBar.qml index dfc6f0e2..39cd7019 100644 --- a/src/gui/Base/HScrollBar.qml +++ b/src/gui/Base/HScrollBar.qml @@ -4,5 +4,34 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 ScrollBar { + id: scrollBar minimumSize: (Math.min(height / 1.5, 48) * theme.uiScale) / height + opacity: size < 1 && (active || hovered) ? 1 : 0 + padding: 0 + + background: Rectangle { + color: theme.controls.scrollbar.track + } + + contentItem: Item { + implicitWidth: theme.controls.scrollbar.width + + Rectangle { + anchors.fill: parent + anchors.leftMargin: theme.controls.scrollbar.sliderPadding + anchors.rightMargin: anchors.leftMargin + + radius: theme.controls.scrollbar.sliderRadius + color: + scrollBar.pressed ? theme.controls.scrollbar.pressedSlider : + sliderHover.hovered ? theme.controls.scrollbar.hoveredSlider : + theme.controls.scrollbar.slider + + Behavior on color { HColorAnimation {} } + + HoverHandler { id: sliderHover } + } + } + + Behavior on opacity { HNumberAnimation {} } } diff --git a/src/themes/Glass.qpl b/src/themes/Glass.qpl index 6dbfcfcd..cb8d116b 100644 --- a/src/themes/Glass.qpl +++ b/src/themes/Glass.qpl @@ -95,6 +95,18 @@ icons: // Generic UI controls controls: + scrollbar: + int width: theme.spacing + + color track: colors.strongBackground + + color slider: colors.accentElement + color hoveredSlider: colors.accentElement + color pressedSlider: colors.strongAccentElement + + int sliderPadding: 2 + int sliderRadius: theme.radius + box: int defaultWidth: minimumSupportedWidth color background: colors.mediumBackground diff --git a/src/themes/Midnight.qpl b/src/themes/Midnight.qpl index 93cac19a..daa4fd72 100644 --- a/src/themes/Midnight.qpl +++ b/src/themes/Midnight.qpl @@ -98,6 +98,18 @@ icons: // Generic UI controls controls: + scrollbar: + int width: theme.spacing + + color track: colors.strongBackground + + color slider: colors.accentElement + color hoveredSlider: colors.accentElement + color pressedSlider: colors.strongAccentElement + + int sliderPadding: 2 + int sliderRadius: theme.radius + box: int defaultWidth: minimumSupportedWidth color background: colors.mediumBackground