From 99d49f787befa23ba626da1ea3d3b22dc608d363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 26 Oct 2023 13:39:38 +0200 Subject: [PATCH] slider: Request a size Sliders (and level bars) currently don't request any size, so it's up to the caller (or stylesheet) to explicitly set a size big enough to fit the bar/handle. That's rather unexpected, we should request the size we need ourselves. Closes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7133 Part-of: --- js/ui/barLevel.js | 20 ++++++++++++++++++++ js/ui/slider.js | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/js/ui/barLevel.js b/js/ui/barLevel.js index 8ff648c17..1b4b7f940 100644 --- a/js/ui/barLevel.js +++ b/js/ui/barLevel.js @@ -259,6 +259,26 @@ export const BarLevel = GObject.registerClass({ cr.$dispose(); } + vfunc_get_preferred_height(_forWidth) { + const themeNode = this.get_theme_node(); + const height = this._getPreferredHeight(); + return themeNode.adjust_preferred_height(height, height); + } + + vfunc_get_preferred_width(_forHeight) { + const themeNode = this.get_theme_node(); + const width = this._getPreferredWidth(); + return themeNode.adjust_preferred_width(width, width); + } + + _getPreferredHeight() { + return this._barLevelHeight + this._barLevelBorderWidth; + } + + _getPreferredWidth() { + return this._overdriveSeparatorWidth + this._barLevelBorderWidth; + } + _getCurrentValue() { return this._value; } diff --git a/js/ui/slider.js b/js/ui/slider.js index f154cea40..69288e7c6 100644 --- a/js/ui/slider.js +++ b/js/ui/slider.js @@ -75,6 +75,18 @@ export const Slider = GObject.registerClass({ cr.$dispose(); } + _getPreferredHeight() { + const barHeight = super._getPreferredHeight(); + const handleHeight = 2 * this._handleRadius + this._handleBorderWidth; + return Math.max(barHeight, handleHeight); + } + + _getPreferredWidth() { + const barWidth = super._getPreferredWidth(); + const handleWidth = 2 * this._handleRadius + this._handleBorderWidth; + return Math.max(barWidth, handleWidth); + } + vfunc_button_press_event(event) { return this.startDragging(event); }