Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SettingsPage: use gicon instead of icon_name #289

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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