Skip to content

Commit

Permalink
Move TextScale to widget
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Mar 6, 2024
1 parent 5653a91 commit 3218bac
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 51 deletions.
4 changes: 2 additions & 2 deletions data/Indicator.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* SPDX-FileCopyrightText: 2023 elementary, Inc. (https://elementary.io)
*/

quicksettings box.font-size,
quicksettings scalebox,
quicksettings .togglebox {
padding: 0.666rem; /* 6px */
}

quicksettings box.font-size scale {
quicksettings scalebox scale {
margin: 0.666rem 0.666rem 0; /* 6px */
}

Expand Down
1 change: 1 addition & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ src/Widgets/EndSessionDialog.vala
src/Widgets/RotationToggle.vala
src/Widgets/SessionBox.vala
src/Widgets/SettingsToggle.vala
src/Widgets/TextScale.vala
49 changes: 1 addition & 48 deletions src/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ public class QuickSettings.PopoverWidget : Gtk.Box {
private const string FDO_ACCOUNTS_PATH = "/org/freedesktop/Accounts";

private Gtk.Popover? popover;
private Gtk.Button zoom_in_button;
private Gtk.Button zoom_out_button;
private Settings interface_settings;

public PopoverWidget (Wingpanel.IndicatorManager.ServerType server_type) {
Object (server_type: server_type);
Expand Down Expand Up @@ -116,58 +113,14 @@ public class QuickSettings.PopoverWidget : Gtk.Box {
toggle_box.add (screen_reader);
toggle_box.add (onscreen_keyboard);

zoom_out_button = new Gtk.Button.from_icon_name ("format-text-smaller-symbolic") {
tooltip_text = _("Decrease text size")
};
zoom_out_button.get_style_context ().add_class ("circular");

var zoom_adjustment = new Gtk.Adjustment (-1, 0.75, 1.75, 0.05, 0, 0);

var zoom_scale = new Gtk.Scale (HORIZONTAL, zoom_adjustment) {
draw_value = false,
hexpand = true
};
zoom_scale.add_mark (1, BOTTOM, null);
zoom_scale.add_mark (1.5, BOTTOM, null);

zoom_in_button = new Gtk.Button.from_icon_name ("format-text-larger-symbolic") {
tooltip_text = _("Increase text size")
};
zoom_in_button.get_style_context ().add_class ("circular");

var font_size_box = new Gtk.Box (HORIZONTAL, 0);
font_size_box.get_style_context ().add_class ("font-size");
font_size_box.add (zoom_out_button);
font_size_box.add (zoom_scale);
font_size_box.add (zoom_in_button);

scale_box.add (font_size_box);

interface_settings = new Settings ("org.gnome.desktop.interface");
interface_settings.bind ("text-scaling-factor", zoom_adjustment, "value", DEFAULT);
interface_settings.changed["text-scaling-factor"].connect (update_zoom_buttons);
update_zoom_buttons ();

zoom_in_button.clicked.connect (() => {
zoom_adjustment.value += 0.05;
});

zoom_out_button.clicked.connect (() => {
zoom_adjustment.value += -0.05;
});
scale_box.add (new TextScale ());

var applications_settings = new Settings ("org.gnome.desktop.a11y.applications");
applications_settings.bind ("screen-keyboard-enabled", onscreen_keyboard, "active", DEFAULT);
applications_settings.bind ("screen-reader-enabled", screen_reader, "active", DEFAULT);
}
}

private void update_zoom_buttons () {
var scaling_factor = interface_settings.get_double ("text-scaling-factor");
zoom_in_button.sensitive = scaling_factor < 1.75;
zoom_out_button.sensitive = scaling_factor > 0.75;
}

private async Pantheon.AccountsService? setup_accounts_services () {
unowned GLib.DBusConnection connection;
string path;
Expand Down
59 changes: 59 additions & 0 deletions src/Widgets/TextScale.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/

public class QuickSettings.TextScale : Gtk.Box {
private Gtk.Button zoom_in_button;
private Gtk.Button zoom_out_button;
private Settings interface_settings;

class construct {
set_css_name ("scalebox");
}

construct {
zoom_out_button = new Gtk.Button.from_icon_name ("format-text-smaller-symbolic") {
tooltip_text = _("Decrease text size")
};
zoom_out_button.get_style_context ().add_class ("circular");

var zoom_adjustment = new Gtk.Adjustment (-1, 0.75, 1.75, 0.05, 0, 0);

var zoom_scale = new Gtk.Scale (HORIZONTAL, zoom_adjustment) {
draw_value = false,
hexpand = true
};
zoom_scale.add_mark (1, BOTTOM, null);
zoom_scale.add_mark (1.5, BOTTOM, null);

zoom_in_button = new Gtk.Button.from_icon_name ("format-text-larger-symbolic") {
tooltip_text = _("Increase text size")
};
zoom_in_button.get_style_context ().add_class ("circular");

get_style_context ().add_class ("font-size");
add (zoom_out_button);
add (zoom_scale);
add (zoom_in_button);

interface_settings = new Settings ("org.gnome.desktop.interface");
interface_settings.bind ("text-scaling-factor", zoom_adjustment, "value", DEFAULT);
interface_settings.changed["text-scaling-factor"].connect (update_zoom_buttons);
update_zoom_buttons ();

zoom_in_button.clicked.connect (() => {
zoom_adjustment.value += 0.05;
});

zoom_out_button.clicked.connect (() => {
zoom_adjustment.value += -0.05;
});
}

private void update_zoom_buttons () {
var scaling_factor = interface_settings.get_double ("text-scaling-factor");
zoom_in_button.sensitive = scaling_factor < 1.75;
zoom_out_button.sensitive = scaling_factor > 0.75;
}
}
3 changes: 2 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ sources = [
'Widgets' / 'EndSessionDialog.vala',
'Widgets' / 'RotationToggle.vala',
'Widgets' / 'SettingsToggle.vala',
'Widgets' / 'SessionBox.vala'
'Widgets' / 'SessionBox.vala',
'Widgets' / 'TextScale.vala',
]

shared_module(
Expand Down

0 comments on commit 3218bac

Please sign in to comment.