add ranges to drawing settings schema

* It is no longer required to clamp the setting value in area.js.
* Add a "range" property, completed with another 'step' property, to PixelSpinButton in order to directly initiate the lower and upper values of the adjustment from the relevant setting range.
* Not related: fix an inversion between Pango and Cairo in element.js.
This commit is contained in:
abakkk 2020-09-09 12:12:29 +02:00
parent 03b73862cc
commit 56008f3041
5 changed files with 50 additions and 22 deletions

10
area.js
View File

@ -241,7 +241,7 @@ var DrawingArea = new Lang.Class({
while (this.squareAreaSize * 2 < Math.min(this.monitor.width, this.monitor.height))
this.squareAreaSize *= 2;
} else {
this.squareAreaSize = Math.max(64, Me.drawingSettings.get_uint('square-area-size'));
this.squareAreaSize = Me.drawingSettings.get_uint('square-area-size');
}
this.areaBackgroundColor = getClutterColorFromString(Me.drawingSettings.get_string('background-color'), 'BLACK');
@ -251,16 +251,16 @@ var DrawingArea = new Lang.Class({
this.gridLineSpacing = Math.round(this.monitor.width / (5 * GRID_TILES_HORIZONTAL_NUMBER));
this.gridLineWidth = this.gridLineSpacing / 20;
} else {
this.gridLineSpacing = Math.max(1, Me.drawingSettings.get_uint('grid-line-spacing'));
this.gridLineWidth = Math.round(Math.max(0.1, Me.drawingSettings.get_double('grid-line-width')) * 100) / 100;
this.gridLineSpacing = Me.drawingSettings.get_uint('grid-line-spacing');
this.gridLineWidth = Math.round(Me.drawingSettings.get_double('grid-line-width') * 100) / 100;
}
this.dashOffset = Math.round(Me.drawingSettings.get_double('dash-offset') * 100) / 100;
if (Me.drawingSettings.get_boolean('dash-array-auto')) {
this.dashArray = [0, 0];
} else {
let on = Math.round(Math.max(0, Me.drawingSettings.get_double('dash-array-on')) * 100) / 100;
let off = Math.round(Math.max(0, Me.drawingSettings.get_double('dash-array-off')) * 100) / 100;
let on = Math.round(Me.drawingSettings.get_double('dash-array-on') * 100) / 100;
let off = Math.round(Me.drawingSettings.get_double('dash-array-off') * 100) / 100;
this.dashArray = [on, off];
}
},

View File

@ -35,18 +35,18 @@ var getPangoFontFamilies = function() {
};
const getFillRuleSvgName = function(fillRule) {
return fillRule == Pango.FillRule.EVEN_ODD ? 'evenodd' : 'nonzero';
return fillRule == Cairo.FillRule.EVEN_ODD ? 'evenodd' : 'nonzero';
};
const getLineCapSvgName = function(lineCap) {
return lineCap == Pango.LineCap.BUTT ? 'butt' :
lineCap == Pango.LineCap.SQUASH ? 'square' :
return lineCap == Cairo.LineCap.BUTT ? 'butt' :
lineCap == Cairo.LineCap.SQUASH ? 'square' :
'round';
};
const getLineJoinSvgName = function(lineJoin) {
return lineJoin == Pango.LineJoin.MITER ? 'miter' :
lineJoin == Pango.LineJoin.BEVEL ? 'bevel' :
return lineJoin == Cairo.LineJoin.MITER ? 'miter' :
lineJoin == Cairo.LineJoin.BEVEL ? 'bevel' :
'round';
};

View File

@ -181,8 +181,8 @@ const DrawingPage = new GObject.Class({
let squareAreaAutoButton = new Gtk.CheckButton({ label: _("Auto"),
name: this.schema.get_key('square-area-auto').get_summary(),
tooltip_text: this.schema.get_key('square-area-auto').get_description() });
let squareAreaSizeButton = new PixelSpinButton({ width_chars: 5, digits: 0,
adjustment: Gtk.Adjustment.new(0, 64, 32768, 1, 10, 0),
let squareAreaSizeButton = new PixelSpinButton({ width_chars: 5, digits: 0, step: 1,
range: this.schema.get_key('square-area-size').get_range(),
name: this.schema.get_key('square-area-size').get_summary(),
tooltip_text: this.schema.get_key('square-area-size').get_description() });
this.settings.bind('square-area-auto', squareAreaAutoButton, 'active', 0);
@ -204,12 +204,12 @@ const DrawingPage = new GObject.Class({
let gridLineAutoButton = new Gtk.CheckButton({ label: _("Auto"),
name: this.schema.get_key('grid-line-auto').get_summary(),
tooltip_text: this.schema.get_key('grid-line-auto').get_description() });
let gridLineWidthButton = new PixelSpinButton({ width_chars: 5, digits: 1,
adjustment: Gtk.Adjustment.new(0, 0.1, 10, 0.1, 1, 0),
let gridLineWidthButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 0.1,
range: this.schema.get_key('grid-line-width').get_range(),
name: this.schema.get_key('grid-line-width').get_summary(),
tooltip_text: this.schema.get_key('grid-line-width').get_description() });
let gridLineSpacingButton = new PixelSpinButton({ width_chars: 5, digits: 1,
adjustment: Gtk.Adjustment.new(0, 1, 16384, 1, 10, 0),
let gridLineSpacingButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 1,
range: this.schema.get_key('grid-line-spacing').get_range(),
name: this.schema.get_key('grid-line-spacing').get_summary(),
tooltip_text: this.schema.get_key('grid-line-spacing').get_description() });
this.settings.bind('grid-line-auto', gridLineAutoButton, 'active', 0);
@ -241,12 +241,12 @@ const DrawingPage = new GObject.Class({
let dashArrayAutoButton = new Gtk.CheckButton({ label: _("Auto"),
name: this.schema.get_key('dash-array-auto').get_summary(),
tooltip_text: this.schema.get_key('dash-array-auto').get_description() });
let dashArrayOnButton = new PixelSpinButton({ width_chars: 5, digits: 1,
adjustment: Gtk.Adjustment.new(0, 0, 16384, 0.1, 1, 0),
let dashArrayOnButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 0.1,
range: this.schema.get_key('dash-array-on').get_range(),
name: this.schema.get_key('dash-array-on').get_summary(),
tooltip_text: this.schema.get_key('dash-array-on').get_description() });
let dashArrayOffButton = new PixelSpinButton({ width_chars: 5, digits: 1,
adjustment: Gtk.Adjustment.new(0, 0, 16384, 0.1, 1, 0),
let dashArrayOffButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 0.1,
range: this.schema.get_key('dash-array-off').get_range(),
name: this.schema.get_key('dash-array-off').get_summary(),
tooltip_text: this.schema.get_key('dash-array-off').get_description() });
this.settings.bind('dash-array-auto', dashArrayAutoButton, 'active', 0);
@ -260,8 +260,8 @@ const DrawingPage = new GObject.Class({
toolsListBox.add(dashArrayRow);
let dashOffsetRow = new PrefRow({ label: this.schema.get_key('dash-offset').get_summary() });
let dashOffsetButton = new PixelSpinButton({ width_chars: 5, digits: 1,
adjustment: Gtk.Adjustment.new(0, -16384, 16384, 0.1, 1, 0),
let dashOffsetButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 0.1,
range: this.schema.get_key('dash-offset').get_range(),
name: this.schema.get_key('dash-offset').get_summary(),
tooltip_text: this.schema.get_key('dash-offset').get_description() });
this.settings.bind('dash-offset', dashOffsetButton, 'value', 0);
@ -523,6 +523,28 @@ const PixelSpinButton = new GObject.Class({
Name: 'DrawOnYourScreenPixelSpinButton',
GTypeName: 'DrawOnYourScreenPixelSpinButton',
Extends: Gtk.SpinButton,
Properties: {
'range': GObject.param_spec_variant('range', 'range', 'GSettings range',
GLib.VariantType.new('(sv)'), null, GObject.ParamFlags.WRITABLE),
'step': GObject.ParamSpec.double('step', 'step', 'step increment',
GObject.ParamFlags.WRITABLE,
0, 1000, 1)
},
set range(range) {
let [type, variant] = range.deep_unpack();
if (type == 'range') {
let [min, max] = variant.deep_unpack();
this.adjustment.set_lower(min);
this.adjustment.set_upper(max);
}
},
set step(step) {
this.adjustment.set_step_increment(step);
this.adjustment.set_page_increment(step * 10);
},
// Add 'px' unit.
vfunc_output: function() {

Binary file not shown.

View File

@ -48,16 +48,19 @@
<description>Compute the lengths from the line width</description>
</key>
<key type="d" name="dash-array-on">
<range min="0.1" max="16384"/>
<default>5</default>
<summary>Dash array on</summary>
<description>The dash length in pixels</description>
</key>
<key type="d" name="dash-array-off">
<range min="0.1" max="16384"/>
<default>15</default>
<summary>Dash array off</summary>
<description>The gap between the dashes in pixels</description>
</key>
<key type="d" name="dash-offset">
<range min="-16384" max="16384"/>
<default>0</default>
<summary>Dash offset</summary>
<description>The dash offset in pixels</description>
@ -73,11 +76,13 @@
<description>Compute the lengths from the screen size</description>
</key>
<key type="u" name="grid-line-spacing">
<range min="1" max="16384"/>
<default>10</default>
<summary>Grid overlay line spacing</summary>
<description>The gap between lines in pixels</description>
</key>
<key type="d" name="grid-line-width">
<range min="0.1" max="10"/>
<default>0.5</default>
<summary>Grid overlay line width</summary>
<description>The line width in pixels</description>
@ -102,6 +107,7 @@
<description>Compute the size of the square area from the screen size</description>
</key>
<key type="u" name="square-area-size">
<range min="64" max="32768"/>
<default>512</default>
<summary>Square area size</summary>
<description>The size of the square area in pixels</description>