Skip to content

Commit 3c9e460

Browse files
Move Text settings to their own page (#297)
* Move Text settings to their own page * Clean up single-use methods Co-authored-by: Cassidy James Blaede <cassidy@elementary.io>
1 parent d322ef4 commit 3c9e460

5 files changed

Lines changed: 133 additions & 125 deletions

File tree

po/POTFILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ src/Translations.vala
55
src/Views/Appearance.vala
66
src/Views/Dock.vala
77
src/Views/Multitasking.vala
8+
src/Views/Text.vala
89
src/Views/Wallpaper.vala
910
src/Widgets/SolidColorContainer.vala
1011
src/Widgets/WallpaperContainer.vala

src/Plug.vala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class PantheonShell.Plug : Switchboard.Plug {
3434
settings.set ("desktop/appearance", "appearance");
3535
settings.set ("desktop/dock", "dock");
3636
settings.set ("desktop/multitasking", "multitasking");
37+
settings.set ("desktop/text", "text");
3738

3839
// DEPRECATED
3940
settings.set ("desktop/wallpaper", "wallpaper");
@@ -54,12 +55,13 @@ public class PantheonShell.Plug : Switchboard.Plug {
5455
wallpaper_view = new Wallpaper (this);
5556

5657
var multitasking = new Multitasking ();
58+
var appearance = new Appearance ();
59+
var text = new Text ();
5760

5861
stack = new Gtk.Stack ();
5962
stack.add_titled (wallpaper_view, "wallpaper", _("Wallpaper"));
60-
61-
var appearance = new Appearance ();
6263
stack.add_titled (appearance, "appearance", _("Appearance"));
64+
stack.add_titled (text, "text", _("Text"));
6365

6466
if (GLib.Environment.find_program_in_path ("plank") != null) {
6567
var dock = new Dock ();
@@ -101,6 +103,9 @@ public class PantheonShell.Plug : Switchboard.Plug {
101103
case "dock":
102104
stack.set_visible_child_name ("dock");
103105
break;
106+
case "text":
107+
stack.set_visible_child_name ("text");
108+
break;
104109
case "multitasking":
105110
stack.set_visible_child_name ("multitasking");
106111
break;
@@ -120,8 +125,9 @@ public class PantheonShell.Plug : Switchboard.Plug {
120125
search_results.set ("%s%s".printf (display_name, _("Appearance")), "appearance");
121126
search_results.set ("%s%s%s".printf (display_name, _("Appearance"), _("Dark style")), "appearance");
122127
search_results.set ("%s%s%s".printf (display_name, _("Appearance"), _("Accent color")), "appearance");
123-
search_results.set ("%s%s%s".printf (display_name, _("Appearance"), _("Text size")), "appearance");
124-
search_results.set ("%s%s%s".printf (display_name, _("Appearance"), _("Dyslexia-friendly text")), "appearance");
128+
search_results.set ("%s%s".printf (display_name, _("Text")), "text");
129+
search_results.set ("%s%s%s".printf (display_name, _("Text"), _("Size")), "text");
130+
search_results.set ("%s%s%s".printf (display_name, _("Text"), _("Dyslexia-friendly")), "text");
125131
search_results.set ("%s%s".printf (display_name, _("Multitasking")), "multitasking");
126132
search_results.set ("%s%s%s".printf (display_name, _("Multitasking"), _("Hot Corners")), "multitasking");
127133
search_results.set ("%s%s%s".printf (display_name, _("Multitasking"), _("Move windows to a new workspace")), "multitasking");

src/Views/Appearance.vala

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@ public class PantheonShell.Appearance : Gtk.Grid {
2222
private const string INTERFACE_SCHEMA = "org.gnome.desktop.interface";
2323
private const string STYLESHEET_KEY = "gtk-theme";
2424
private const string STYLESHEET_PREFIX = "io.elementary.stylesheet.";
25-
private const string TEXT_SIZE_KEY = "text-scaling-factor";
26-
27-
private const string DYSLEXIA_KEY = "dyslexia-friendly-support";
28-
private const string FONT_KEY = "font-name";
29-
private const string DOCUMENT_FONT_KEY = "document-font-name";
30-
private const string MONOSPACE_FONT_KEY = "monospace-font-name";
31-
32-
private const string OD_REG_FONT = "OpenDyslexic Regular 9";
33-
private const string OD_DOC_FONT = "OpenDyslexic Regular 10";
34-
private const string OD_MON_FONT = "OpenDyslexicMono Regular 10";
35-
36-
private const double[] TEXT_SCALE = {0.75, 1, 1.25, 1.5};
37-
38-
private Granite.Widgets.ModeButton text_size_modebutton;
3925

4026
private enum AccentColor {
4127
NO_PREFERENCE,
@@ -178,48 +164,6 @@ public class PantheonShell.Appearance : Gtk.Grid {
178164
schedule_grid.add (to_label);
179165
schedule_grid.add (to_time);
180166

181-
var text_size_label = new Gtk.Label (_("Text size:")) {
182-
halign = Gtk.Align.END,
183-
margin_top = 24
184-
};
185-
186-
text_size_modebutton = new Granite.Widgets.ModeButton () {
187-
margin_top = 24
188-
};
189-
text_size_modebutton.append_text (_("Small"));
190-
text_size_modebutton.append_text (_("Default"));
191-
text_size_modebutton.append_text (_("Large"));
192-
text_size_modebutton.append_text (_("Larger"));
193-
194-
var dyslexia_font_label = new Gtk.Label (_("Dyslexia-friendly text:")) {
195-
halign = Gtk.Align.END
196-
};
197-
198-
var dyslexia_font_switch = new Gtk.Switch () {
199-
halign = Gtk.Align.START
200-
};
201-
202-
var dyslexia_font_description_label = new Gtk.Label (
203-
_("Bottom-heavy shapes and increased character spacing can help improve legibility and reading speed.")
204-
) {
205-
max_width_chars = 60,
206-
wrap = true,
207-
xalign = 0
208-
};
209-
dyslexia_font_description_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
210-
211-
/* Rows 0 to 3 are for the dark style UI that gets attached only if we
212-
* can connect to the DBus API
213-
*
214-
* Row 4 and 5 are for accent color UI that gets constructed only if the
215-
* current stylesheet is supported (begins with the STYLESHEET_PREFIX)
216-
*/
217-
attach (text_size_label, 0, 8);
218-
attach (text_size_modebutton, 1, 8, 2);
219-
attach (dyslexia_font_label, 0, 9);
220-
attach (dyslexia_font_switch, 1, 9);
221-
attach (dyslexia_font_description_label, 1, 10, 2);
222-
223167
Pantheon.AccountsService? pantheon_act = null;
224168

225169
string? user_path = null;
@@ -412,22 +356,6 @@ public class PantheonShell.Appearance : Gtk.Grid {
412356
attach (accent_grid, 1, 4, 2);
413357
attach (accent_info, 1, 5, 2);
414358
}
415-
416-
update_text_size_modebutton (interface_settings);
417-
418-
interface_settings.changed.connect (() => {
419-
update_text_size_modebutton (interface_settings);
420-
});
421-
422-
text_size_modebutton.mode_changed.connect (() => {
423-
set_text_scale (interface_settings, text_size_modebutton.selected);
424-
});
425-
426-
dyslexia_font_switch.set_active (update_dyslexia_font_switch (interface_settings));
427-
428-
dyslexia_font_switch.state_set.connect (() => {
429-
toggle_dyslexia_support (interface_settings, dyslexia_font_switch.get_active () );
430-
});
431359
}
432360

433361
private class PrefersAccentColorButton : Gtk.RadioButton {
@@ -474,55 +402,6 @@ public class PantheonShell.Appearance : Gtk.Grid {
474402
}
475403
}
476404

477-
private void toggle_dyslexia_support (GLib.Settings interface_settings, bool state) {
478-
if (state == true) {
479-
interface_settings.set_string (FONT_KEY, OD_REG_FONT);
480-
interface_settings.set_string (DOCUMENT_FONT_KEY, OD_DOC_FONT);
481-
interface_settings.set_string (MONOSPACE_FONT_KEY, OD_MON_FONT);
482-
}
483-
else {
484-
interface_settings.reset (FONT_KEY);
485-
interface_settings.reset (DOCUMENT_FONT_KEY);
486-
interface_settings.reset (MONOSPACE_FONT_KEY);
487-
}
488-
}
489-
490-
private bool update_dyslexia_font_switch (GLib.Settings interface_settings) {
491-
var interface_font = interface_settings.get_string (FONT_KEY);
492-
var document_font = interface_settings.get_string (DOCUMENT_FONT_KEY);
493-
var monospace_font = interface_settings.get_string (MONOSPACE_FONT_KEY);
494-
495-
if (interface_font == OD_REG_FONT || document_font == OD_DOC_FONT || monospace_font == OD_MON_FONT ) {
496-
return true;
497-
}
498-
499-
else {
500-
return false;
501-
}
502-
}
503-
504-
private int get_text_scale (GLib.Settings interface_settings) {
505-
double text_scaling_factor = interface_settings.get_double (TEXT_SIZE_KEY);
506-
507-
if (text_scaling_factor <= TEXT_SCALE[0]) {
508-
return 0;
509-
} else if (text_scaling_factor <= TEXT_SCALE[1]) {
510-
return 1;
511-
} else if (text_scaling_factor <= TEXT_SCALE[2]) {
512-
return 2;
513-
} else {
514-
return 3;
515-
}
516-
}
517-
518-
private void set_text_scale (GLib.Settings interface_settings, int option) {
519-
interface_settings.set_double (TEXT_SIZE_KEY, TEXT_SCALE[option]);
520-
}
521-
522-
private void update_text_size_modebutton (GLib.Settings interface_settings) {
523-
text_size_modebutton.set_active (get_text_scale (interface_settings));
524-
}
525-
526405
private static DateTime double_date_time (double dbl) {
527406
var hours = (int) dbl;
528407
var minutes = (int) Math.round ((dbl - hours) * 60);

src/Views/Text.vala

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright 2021 elementary, Inc. (https://elementary.io)
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 3 of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public
15+
* License along with this program; if not, write to the
16+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+
* Boston, MA 02110-1301 USA
18+
*
19+
*/
20+
21+
public class PantheonShell.Text : Gtk.Grid {
22+
private const string TEXT_SIZE_KEY = "text-scaling-factor";
23+
24+
private const string DYSLEXIA_KEY = "dyslexia-friendly-support";
25+
private const string FONT_KEY = "font-name";
26+
private const string DOCUMENT_FONT_KEY = "document-font-name";
27+
private const string MONOSPACE_FONT_KEY = "monospace-font-name";
28+
29+
private const string OD_REG_FONT = "OpenDyslexic Regular 9";
30+
private const string OD_DOC_FONT = "OpenDyslexic Regular 10";
31+
private const string OD_MON_FONT = "OpenDyslexicMono Regular 10";
32+
33+
private const double[] TEXT_SCALE = {0.75, 1, 1.25, 1.5};
34+
35+
private Granite.Widgets.ModeButton text_size_modebutton;
36+
37+
construct {
38+
var text_size_label = new Gtk.Label (_("Size:")) {
39+
halign = Gtk.Align.END
40+
};
41+
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"));
47+
48+
var dyslexia_font_label = new Gtk.Label (_("Dyslexia-friendly:")) {
49+
halign = Gtk.Align.END,
50+
margin_top = 18
51+
};
52+
53+
var dyslexia_font_switch = new Gtk.Switch () {
54+
halign = Gtk.Align.START,
55+
margin_top = 18
56+
};
57+
58+
var dyslexia_font_description_label = new Gtk.Label (
59+
_("Bottom-heavy shapes and increased character spacing can help improve legibility and reading speed.")
60+
) {
61+
max_width_chars = 60,
62+
wrap = true,
63+
xalign = 0
64+
};
65+
dyslexia_font_description_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
66+
67+
column_spacing = 12;
68+
halign = Gtk.Align.CENTER;
69+
row_spacing = 6;
70+
margin_start = margin_end = 12;
71+
margin_bottom = 24;
72+
attach (text_size_label, 0, 0);
73+
attach (text_size_modebutton, 1, 0, 2);
74+
attach (dyslexia_font_label, 0, 1);
75+
attach (dyslexia_font_switch, 1, 1);
76+
attach (dyslexia_font_description_label, 1, 2, 2);
77+
78+
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);
82+
83+
text_size_modebutton.set_active (get_text_scale (interface_settings));
84+
85+
interface_settings.changed.connect (() => {
86+
text_size_modebutton.set_active (get_text_scale (interface_settings));
87+
});
88+
89+
text_size_modebutton.mode_changed.connect (() => {
90+
interface_settings.set_double (TEXT_SIZE_KEY, TEXT_SCALE[text_size_modebutton.selected]);
91+
});
92+
93+
dyslexia_font_switch.active = interface_font == OD_REG_FONT || document_font == OD_DOC_FONT || monospace_font == OD_MON_FONT;
94+
95+
dyslexia_font_switch.state_set.connect (() => {
96+
if (dyslexia_font_switch.active) {
97+
interface_settings.set_string (FONT_KEY, OD_REG_FONT);
98+
interface_settings.set_string (DOCUMENT_FONT_KEY, OD_DOC_FONT);
99+
interface_settings.set_string (MONOSPACE_FONT_KEY, OD_MON_FONT);
100+
} else {
101+
interface_settings.reset (FONT_KEY);
102+
interface_settings.reset (DOCUMENT_FONT_KEY);
103+
interface_settings.reset (MONOSPACE_FONT_KEY);
104+
}
105+
});
106+
}
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+
}
121+
}

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plug_files = files(
66
'Views/Appearance.vala',
77
'Views/Dock.vala',
88
'Views/Multitasking.vala',
9+
'Views/Text.vala',
910
'Views/Wallpaper.vala',
1011
'Widgets/SolidColorContainer.vala',
1112
'Widgets/WallpaperContainer.vala',

0 commit comments

Comments
 (0)