From 8ed6e302b0ff214ec4277dfd20a44b840ba88e6a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 20 May 2026 20:33:27 +0200 Subject: [PATCH] Small cleanups: reuse Util.clamp in OSD; PanelSlider hover via _hot OSD reimplemented clamp() inline when Util already has one. PanelSlider's knob-scale binding read `mouseArea.containsMouse` directly instead of going through a `_hot` like the other interactive controls (TextField, NumberField, Dropdown). Mirror them so future style work has a single property to override. --- shell/Ui/PanelSlider.qml | 3 ++- shell/plugins/osd/Osd.qml | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/shell/Ui/PanelSlider.qml b/shell/Ui/PanelSlider.qml index 019f3d49..b7ec9495 100644 --- a/shell/Ui/PanelSlider.qml +++ b/shell/Ui/PanelSlider.qml @@ -28,6 +28,7 @@ Item { readonly property real range: Math.max(0.0001, maximum - minimum) readonly property real progress: Math.max(0, Math.min(1, (liveValue - minimum) / range)) + readonly property bool _hot: mouseArea.containsMouse || root.dragging Rectangle { id: track @@ -64,7 +65,7 @@ Item { border.width: Math.max(1, Style.space(2)) anchors.verticalCenter: track.verticalCenter x: Math.max(0, Math.min(track.width - width, track.width * root.progress - width / 2)) - scale: mouseArea.containsMouse || root.dragging ? 1.15 : 1.0 + scale: root._hot ? 1.15 : 1.0 Behavior on x { enabled: !root.dragging diff --git a/shell/plugins/osd/Osd.qml b/shell/plugins/osd/Osd.qml index 6d431658..ad06180d 100644 --- a/shell/plugins/osd/Osd.qml +++ b/shell/plugins/osd/Osd.qml @@ -15,8 +15,6 @@ Item { property bool hasProgress: true property int duration: 1200 - function clamp(v, min, max) { return Math.max(min, Math.min(max, v)) } - function iconFor(name, percent) { var n = String(name || "").toLowerCase() if (n === "volume-muted" || n === "volume-mute" || n === "muted" || n === "mute") return "" @@ -41,7 +39,7 @@ Item { maxValue = Math.max(1, parseInt(rawMax || "100", 10)) var parsed = parseInt(rawValue || "0", 10) hasProgress = rawValue !== "" && !isNaN(parsed) && rawMessage === "" - value = hasProgress ? clamp(parsed, 0, maxValue) : 0 + value = hasProgress ? Util.clamp(parsed, 0, maxValue) : 0 message = String(rawMessage || (hasProgress ? (rawProgressText || Math.round(value * 100 / maxValue) + "%") : "")) icon = iconFor(iconName, hasProgress ? Math.round(value * 100 / maxValue) : -1) var parsedDuration = parseInt(rawDuration || "1200", 10)