Skip to content

Commit 5fb9449

Browse files
Text sizescale (#298)
* Move Text settings to their own page * Text: Use a scale for text size * Add spinbutton, remove labels, fix keyboard Co-authored-by: Cassidy James Blaede <cassidy@elementary.io>
1 parent 068b727 commit 5fb9449

1 file changed

Lines changed: 29 additions & 36 deletions

File tree

src/Views/Text.vala

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
*/
2020

2121
public class PantheonShell.Text : Gtk.Grid {
22-
private const string TEXT_SIZE_KEY = "text-scaling-factor";
23-
2422
private const string DYSLEXIA_KEY = "dyslexia-friendly-support";
2523
private const string FONT_KEY = "font-name";
2624
private const string DOCUMENT_FONT_KEY = "document-font-name";
@@ -30,20 +28,23 @@ public class PantheonShell.Text : Gtk.Grid {
3028
private const string OD_DOC_FONT = "OpenDyslexic Regular 10";
3129
private const string OD_MON_FONT = "OpenDyslexicMono Regular 10";
3230

33-
private const double[] TEXT_SCALE = {0.75, 1, 1.25, 1.5};
34-
35-
private Granite.Widgets.ModeButton text_size_modebutton;
31+
private uint scale_timeout;
3632

3733
construct {
38-
var text_size_label = new Gtk.Label (_("Size:")) {
34+
var size_label = new Gtk.Label (_("Size:")) {
3935
halign = Gtk.Align.END
4036
};
4137

42-
text_size_modebutton = new Granite.Widgets.ModeButton ();
43-
text_size_modebutton.append_text (_("Small"));
44-
text_size_modebutton.append_text (_("Default"));
45-
text_size_modebutton.append_text (_("Large"));
46-
text_size_modebutton.append_text (_("Larger"));
38+
var size_adjustment = new Gtk.Adjustment (-1, 0.75, 1.5, 0.05, 0, 0);
39+
40+
var size_scale = new Gtk.Scale (Gtk.Orientation.HORIZONTAL, size_adjustment) {
41+
draw_value = false,
42+
hexpand = true
43+
};
44+
size_scale.add_mark (1, Gtk.PositionType.TOP, null);
45+
size_scale.add_mark (1.25, Gtk.PositionType.TOP, null);
46+
47+
var size_spinbutton = new Gtk.SpinButton (size_adjustment, 0.25, 2);
4748

4849
var dyslexia_font_label = new Gtk.Label (_("Dyslexia-friendly:")) {
4950
halign = Gtk.Align.END,
@@ -69,26 +70,32 @@ public class PantheonShell.Text : Gtk.Grid {
6970
row_spacing = 6;
7071
margin_start = margin_end = 12;
7172
margin_bottom = 24;
72-
attach (text_size_label, 0, 0);
73-
attach (text_size_modebutton, 1, 0, 2);
73+
attach (size_label, 0, 0);
74+
attach (size_scale, 1, 0);
75+
attach (size_spinbutton, 2, 0);
7476
attach (dyslexia_font_label, 0, 1);
7577
attach (dyslexia_font_switch, 1, 1);
7678
attach (dyslexia_font_description_label, 1, 2, 2);
7779

7880
var interface_settings = new Settings ("org.gnome.desktop.interface");
79-
var interface_font = interface_settings.get_string (FONT_KEY);
80-
var document_font = interface_settings.get_string (DOCUMENT_FONT_KEY);
81-
var monospace_font = interface_settings.get_string (MONOSPACE_FONT_KEY);
81+
interface_settings.bind ("text-scaling-factor", size_adjustment, "value", SettingsBindFlags.GET);
8282

83-
text_size_modebutton.set_active (get_text_scale (interface_settings));
83+
// Setting scale is slow, so we wait while pressed to keep UI responsive
84+
size_adjustment.value_changed.connect (() => {
85+
if (scale_timeout != 0) {
86+
GLib.Source.remove (scale_timeout);
87+
}
8488

85-
interface_settings.changed.connect (() => {
86-
text_size_modebutton.set_active (get_text_scale (interface_settings));
89+
scale_timeout = Timeout.add (300, () => {
90+
scale_timeout = 0;
91+
interface_settings.set_double ("text-scaling-factor", size_adjustment.value);
92+
return false;
93+
});
8794
});
8895

89-
text_size_modebutton.mode_changed.connect (() => {
90-
interface_settings.set_double (TEXT_SIZE_KEY, TEXT_SCALE[text_size_modebutton.selected]);
91-
});
96+
var interface_font = interface_settings.get_string (FONT_KEY);
97+
var document_font = interface_settings.get_string (DOCUMENT_FONT_KEY);
98+
var monospace_font = interface_settings.get_string (MONOSPACE_FONT_KEY);
9299

93100
dyslexia_font_switch.active = interface_font == OD_REG_FONT || document_font == OD_DOC_FONT || monospace_font == OD_MON_FONT;
94101

@@ -104,18 +111,4 @@ public class PantheonShell.Text : Gtk.Grid {
104111
}
105112
});
106113
}
107-
108-
private int get_text_scale (GLib.Settings interface_settings) {
109-
double text_scaling_factor = interface_settings.get_double (TEXT_SIZE_KEY);
110-
111-
if (text_scaling_factor <= TEXT_SCALE[0]) {
112-
return 0;
113-
} else if (text_scaling_factor <= TEXT_SCALE[1]) {
114-
return 1;
115-
} else if (text_scaling_factor <= TEXT_SCALE[2]) {
116-
return 2;
117-
} else {
118-
return 3;
119-
}
120-
}
121114
}

0 commit comments

Comments
 (0)