Skip to content

Commit

Permalink
SettingsPage: use gicon instead of icon_name (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Feb 1, 2024
1 parent f455c88 commit 5aa90d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/SettingsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public abstract class Switchboard.SettingsPage : Gtk.Widget {
public string status { get; construct set; }

/**
* An icon name to be displayed in a Granite.SettingsSidebar
* An icon to be displayed in the header and sidebar
*/
public string? icon_name { get; construct set; }
public Icon icon { get; construct set; default = new ThemedIcon ("preferences-other"); }

/**
* A title to be displayed in a Granite.SettingsSidebar
Expand Down Expand Up @@ -90,7 +90,7 @@ public abstract class Switchboard.SettingsPage : Gtk.Widget {
}

construct {
var header_icon = new Gtk.Image.from_icon_name (icon_name) {
var header_icon = new Gtk.Image.from_gicon (icon) {
icon_size = Gtk.IconSize.LARGE,
valign = Gtk.Align.START
};
Expand Down Expand Up @@ -161,9 +161,9 @@ public abstract class Switchboard.SettingsPage : Gtk.Widget {
grid.append (action_bar);
grid.set_parent (this);

notify["icon-name"].connect (() => {
notify["icon"].connect (() => {
if (header_icon != null) {
header_icon.icon_name = icon_name;
header_icon.gicon = icon;
}
});

Expand Down
21 changes: 11 additions & 10 deletions lib/SettingsSidebarRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ private class Switchboard.SettingsSidebarRow : Gtk.ListBoxRow {

public unowned SettingsPage page { get; construct; }

public string icon_name {
private Icon _icon;
public Icon icon {
get {
return _icon_name;
return _icon;
}
set {
_icon_name = value;
_icon = value;
if (display_widget is Gtk.Image) {
((Gtk.Image) display_widget).icon_name = value;
((Gtk.Image) display_widget).icon_size = Gtk.IconSize.LARGE;
((Gtk.Image) display_widget).gicon = value;
}
}
}
Expand All @@ -65,7 +65,6 @@ private class Switchboard.SettingsSidebarRow : Gtk.ListBoxRow {
private Gtk.Image status_icon;
private Gtk.Label status_label;
private Gtk.Label title_label;
private string _icon_name;
private string _title;

public SettingsSidebarRow (SettingsPage page) {
Expand Down Expand Up @@ -96,9 +95,11 @@ private class Switchboard.SettingsSidebarRow : Gtk.ListBoxRow {
};
status_label.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);

if (page.icon_name != null) {
display_widget = new Gtk.Image ();
icon_name = page.icon_name;
if (page.icon != null) {
display_widget = new Gtk.Image () {
icon_size = LARGE
};
icon = page.icon;
} else {
display_widget = page.display_widget;
}
Expand All @@ -115,7 +116,7 @@ private class Switchboard.SettingsSidebarRow : Gtk.ListBoxRow {
child = grid;

header = page.header;
page.bind_property ("icon-name", this, "icon-name", BindingFlags.DEFAULT);
page.bind_property ("icon", this, "icon", BindingFlags.DEFAULT);
page.bind_property ("status", this, "status", BindingFlags.DEFAULT);
page.bind_property ("status-type", this, "status-type", BindingFlags.DEFAULT);
page.bind_property ("title", this, "title", BindingFlags.DEFAULT);
Expand Down

0 comments on commit 5aa90d6

Please sign in to comment.