[gnome-shell] barLevel: Support maxValue higher than 1
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] barLevel: Support maxValue higher than 1
- Date: Tue, 31 Jul 2018 18:20:54 +0000 (UTC)
commit 3f756dc6086715d3c5a2faf78d7f6c379dbdd52d
Author: Didier Roche <didrocks ubuntu com>
Date: Fri Feb 9 14:02:21 2018 +0100
barLevel: Support maxValue higher than 1
Ensure that both barLevel and slider can support a higher maxValue than 1
and computes various positions based on it.
It defaults to 1 if not set.
https://bugzilla.gnome.org/show_bug.cgi?id=790280.
js/ui/barLevel.js | 19 +++++++++++++++----
js/ui/slider.js | 8 ++++----
2 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/barLevel.js b/js/ui/barLevel.js
index 2b35496b4..1a1cc58eb 100644
--- a/js/ui/barLevel.js
+++ b/js/ui/barLevel.js
@@ -14,7 +14,8 @@ var BarLevel = new Lang.Class({
if (isNaN(value))
// Avoid spreading NaNs around
throw TypeError('The bar level value must be a number');
- this._value = Math.max(Math.min(value, 1), 0);
+ this._maxValue = 1;
+ this._value = Math.max(Math.min(value, this._maxValue), 0);
this._barLevelWidth = 0;
if (params == undefined)
@@ -44,7 +45,15 @@ var BarLevel = new Lang.Class({
if (isNaN(value))
throw TypeError('The bar level value must be a number');
- this._value = Math.max(Math.min(value, 1), 0);
+ this._value = Math.max(Math.min(value, this._maxValue), 0);
+ this.actor.queue_repaint();
+ },
+
+ setMaximumValue(value) {
+ if (isNaN(value))
+ throw TypeError('The bar level max value must be a number');
+
+ this._maxValue = Math.max(value, 1);
this.actor.queue_repaint();
},
@@ -72,7 +81,9 @@ var BarLevel = new Lang.Class({
const TAU = Math.PI * 2;
- let endX = barLevelBorderRadius + (width - 2 * barLevelBorderRadius) * this._value;
+ let endX = 0;
+ if (this._maxValue > 0)
+ endX = barLevelBorderRadius + (width - 2 * barLevelBorderRadius) * this._value / this._maxValue;
/* background bar */
cr.arc(width - barLevelBorderRadius - barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * 3
/ 4, TAU * 1 / 4);
@@ -118,7 +129,7 @@ var BarLevel = new Lang.Class({
},
_getMaximumValue(actor) {
- return 1;
+ return this._maxValue;
},
_setCurrentValue(actor, value) {
diff --git a/js/ui/slider.js b/js/ui/slider.js
index c1e2ea6a6..65ff8ca8a 100644
--- a/js/ui/slider.js
+++ b/js/ui/slider.js
@@ -51,7 +51,7 @@ var Slider = new Lang.Class({
const TAU = Math.PI * 2;
- let handleX = handleRadius + (width - 2 * handleRadius) * this._value;
+ let handleX = handleRadius + (width - 2 * handleRadius) * this._value / this._maxValue;
let handleY = height / 2;
let color = themeNode.get_foreground_color();
@@ -159,7 +159,7 @@ var Slider = new Lang.Class({
delta = -dy * SLIDER_SCROLL_STEP;
}
- this._value = Math.min(Math.max(0, this._value + delta), 1);
+ this._value = Math.min(Math.max(0, this._value + delta), this._maxValue);
this.actor.queue_repaint();
this.emit('value-changed', this._value);
@@ -181,7 +181,7 @@ var Slider = new Lang.Class({
let key = event.get_key_symbol();
if (key == Clutter.KEY_Right || key == Clutter.KEY_Left) {
let delta = key == Clutter.KEY_Right ? 0.1 : -0.1;
- this._value = Math.max(0, Math.min(this._value + delta, 1));
+ this._value = Math.max(0, Math.min(this._value + delta, this._maxValue));
this.actor.queue_repaint();
this.emit('drag-begin');
this.emit('value-changed', this._value);
@@ -207,7 +207,7 @@ var Slider = new Lang.Class({
newvalue = 1;
else
newvalue = (relX - handleRadius) / (width - 2 * handleRadius);
- this._value = newvalue;
+ this._value = newvalue * this._maxValue;
this.actor.queue_repaint();
this.emit('value-changed', this._value);
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]