From 535d97ddc82bc7ce21ed7c6ac4d3468931fa4007 Mon Sep 17 00:00:00 2001 From: Danielle Fore Date: Wed, 24 Jan 2024 14:45:50 -0800 Subject: [PATCH 1/4] AbstractSettingsPage: Subclass Gtk.Widget --- lib/AbstractSettingsPage.vala | 20 +--------------- lib/AbstractSimpleSettingsPage.vala | 36 +++++++++++++++++++++++------ lib/meson.build | 1 + 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/AbstractSettingsPage.vala b/lib/AbstractSettingsPage.vala index 6fd1b852..380cacc4 100644 --- a/lib/AbstractSettingsPage.vala +++ b/lib/AbstractSettingsPage.vala @@ -7,10 +7,9 @@ * AbstractSettingsPage is a {@link Gtk.ScrolledWindow} subclass with properties used * by other Granite settings widgets. */ -public abstract class Switchboard.SettingsPage : Gtk.Box { +public abstract class Switchboard.SettingsPage : Gtk.Widget { protected string _icon_name; protected string _title; - private Gtk.ScrolledWindow scrolled; /** * Used to display a status icon overlayed on the display_widget in a Granite.SettingsSidebar @@ -66,21 +65,4 @@ public abstract class Switchboard.SettingsPage : Gtk.Box { _title = value; } } - - public new Gtk.Widget child { - get { - return scrolled.child; - } - set { - scrolled.child = value; - } - } - - construct { - scrolled = new Gtk.ScrolledWindow () { - hscrollbar_policy = Gtk.PolicyType.NEVER - }; - - append (scrolled); - } } diff --git a/lib/AbstractSimpleSettingsPage.vala b/lib/AbstractSimpleSettingsPage.vala index 053c813b..d671dd78 100644 --- a/lib/AbstractSimpleSettingsPage.vala +++ b/lib/AbstractSimpleSettingsPage.vala @@ -11,6 +11,7 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage { private Gtk.Label description_label; private string _description; + private Adw.Clamp content_area; /** * A {@link Gtk.Box} used as the action area for #this @@ -18,9 +19,16 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage public Gtk.Box action_area { get; construct; } /** - * A {@link Gtk.Grid} used as the content area for #this + * The child widget for the content area */ - public Gtk.Grid content_area { get; construct; } + public Gtk.Widget child { + get { + return content_area.child; + } + set { + content_area.child = value; + } + } /** * A {@link Gtk.Switch} that appears in the header area when #this.activatable is #true. #status_switch will be #null when #this.activatable is #false @@ -55,6 +63,10 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage } + static construct { + set_layout_manager_type (typeof (Gtk.BinLayout)); + } + class construct { set_css_name ("simplesettingspage"); } @@ -98,9 +110,11 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage header_area.attach (status_switch, 2, 0); } - content_area = new Gtk.Grid () { - column_spacing = 12, - row_spacing = 12, + var header_clamp = new Adw.Clamp () { + child = header_area + }; + + content_area = new Adw.Clamp () { vexpand = true }; content_area.add_css_class ("content-area"); @@ -111,11 +125,15 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage action_area.add_css_class ("buttonbox"); var grid = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - grid.append (header_area); + grid.append (header_clamp); grid.append (content_area); grid.append (action_area); - child = grid; + var scrolled = new Gtk.ScrolledWindow () { + child = grid, + hscrollbar_policy = NEVER + }; + scrolled.set_parent (this); notify["icon-name"].connect (() => { if (header_icon != null) { @@ -129,4 +147,8 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage } }); } + + ~SimpleSettingsPage () { + get_first_child ().unparent (); + } } diff --git a/lib/meson.build b/lib/meson.build index 6ce8ab2f..220c5408 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -9,6 +9,7 @@ config_header = configure_file( ) libswitchboard_deps = [ + adwaita_dep, glib_dep, gio_dep, gio_unix_dep, From 0d11a52e0b39ca71cb29c32234fe7a1a814f2583 Mon Sep 17 00:00:00 2001 From: Danielle Fore Date: Wed, 24 Jan 2024 17:12:47 -0800 Subject: [PATCH 2/4] Remove unused Abstract page --- lib/AbstractSettingsPage.vala | 68 ------------------- ...pleSettingsPage.vala => SettingsPage.vala} | 60 ++++++++++++---- lib/meson.build | 3 +- 3 files changed, 47 insertions(+), 84 deletions(-) delete mode 100644 lib/AbstractSettingsPage.vala rename lib/{AbstractSimpleSettingsPage.vala => SettingsPage.vala} (72%) diff --git a/lib/AbstractSettingsPage.vala b/lib/AbstractSettingsPage.vala deleted file mode 100644 index 380cacc4..00000000 --- a/lib/AbstractSettingsPage.vala +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2017–2021 elementary, Inc. (https://elementary.io) - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/** - * AbstractSettingsPage is a {@link Gtk.ScrolledWindow} subclass with properties used - * by other Granite settings widgets. - */ -public abstract class Switchboard.SettingsPage : Gtk.Widget { - protected string _icon_name; - protected string _title; - - /** - * Used to display a status icon overlayed on the display_widget in a Granite.SettingsSidebar - */ - public enum StatusType { - ERROR, - OFFLINE, - SUCCESS, - WARNING, - NONE - } - - /** - * Selects a colored icon to be displayed in a Granite.SettingsSidebar - */ - public StatusType status_type { get; set; default = StatusType.NONE; } - - /** - * A widget to display in place of an icon in a Granite.SettingsSidebar - */ - public Gtk.Widget? display_widget { get; construct; } - - /** - * A header to be sorted under in a Granite.SettingsSidebar - */ - public string? header { get; construct; } - - /** - * A status string to be displayed underneath the title in a Granite.SettingsSidebar - */ - public string status { get; set construct; } - - /** - * An icon name to be displayed in a Granite.SettingsSidebar - */ - public string? icon_name { - get { - return _icon_name; - } - construct set { - _icon_name = value; - } - } - - /** - * A title to be displayed in a Granite.SettingsSidebar - */ - public string title { - get { - return _title; - } - construct set { - _title = value; - } - } -} diff --git a/lib/AbstractSimpleSettingsPage.vala b/lib/SettingsPage.vala similarity index 72% rename from lib/AbstractSimpleSettingsPage.vala rename to lib/SettingsPage.vala index d671dd78..880c3f17 100644 --- a/lib/AbstractSimpleSettingsPage.vala +++ b/lib/SettingsPage.vala @@ -1,14 +1,54 @@ /* - * Copyright 2017–2022 elementary, Inc. (https://elementary.io) - * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2017–2021 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: LGPL-2.1-or-later */ /** - * SimpleSettingsPage is a widget divided into three sections: a predefined header, - * a content area, and an action area. + * SettingsPage is a {@link Gtk.Widget} subclass with properties used + * by Switchboard.SettingsSidebar */ +public abstract class Switchboard.SettingsPage : Gtk.Widget { + /** + * Used to display a status icon overlayed on the display_widget in a Granite.SettingsSidebar + */ + public enum StatusType { + ERROR, + OFFLINE, + SUCCESS, + WARNING, + NONE + } + + /** + * Selects a colored icon to be displayed in a Granite.SettingsSidebar + */ + public StatusType status_type { get; set; default = StatusType.NONE; } + + /** + * A widget to display in place of an icon in a Granite.SettingsSidebar + */ + public Gtk.Widget? display_widget { get; construct; } + + /** + * A header to be sorted under in a Granite.SettingsSidebar + */ + public string? header { get; construct; } + + /** + * A status string to be displayed underneath the title in a Granite.SettingsSidebar + */ + public string status { get; construct set; } + + /** + * An icon name to be displayed in a Granite.SettingsSidebar + */ + public string? icon_name { get; construct set; } + + /** + * A title to be displayed in a Granite.SettingsSidebar + */ + public string title { get; construct set ; } -public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage { private Gtk.Label description_label; private string _description; private Adw.Clamp content_area; @@ -55,14 +95,6 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage } } - /** - * Creates a new SimpleSettingsPage - * Deprecated: Subclass this instead. - */ - protected SimpleSettingsPage () { - - } - static construct { set_layout_manager_type (typeof (Gtk.BinLayout)); } @@ -148,7 +180,7 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage }); } - ~SimpleSettingsPage () { + ~SettingsPage () { get_first_child ().unparent (); } } diff --git a/lib/meson.build b/lib/meson.build index 220c5408..5f5f733e 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -20,8 +20,7 @@ libswitchboard_deps = [ ] libswitchboard_lib = library('switchboard-3', - 'AbstractSettingsPage.vala', - 'AbstractSimpleSettingsPage.vala', + 'SettingsPage.vala', 'PlugsManager.vala', 'Plug.vala', 'SettingsSidebarRow.vala', From 2b424acc15cd4a5f4993b846c502d2ef007cdf2a Mon Sep 17 00:00:00 2001 From: Danielle Fore Date: Wed, 24 Jan 2024 17:14:24 -0800 Subject: [PATCH 3/4] Copyright header date --- lib/SettingsPage.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SettingsPage.vala b/lib/SettingsPage.vala index 880c3f17..c6505a8a 100644 --- a/lib/SettingsPage.vala +++ b/lib/SettingsPage.vala @@ -1,5 +1,5 @@ /* - * Copyright 2017–2021 elementary, Inc. (https://elementary.io) + * Copyright 2017–2024 elementary, Inc. (https://elementary.io) * SPDX-License-Identifier: LGPL-2.1-or-later */ From 16116fe32098d4ad022855fe241f9d19221b3c7a Mon Sep 17 00:00:00 2001 From: Danielle Fore Date: Wed, 24 Jan 2024 17:18:55 -0800 Subject: [PATCH 4/4] Simplify some properties --- lib/SettingsPage.vala | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/SettingsPage.vala b/lib/SettingsPage.vala index c6505a8a..e372ae4b 100644 --- a/lib/SettingsPage.vala +++ b/lib/SettingsPage.vala @@ -47,11 +47,7 @@ public abstract class Switchboard.SettingsPage : Gtk.Widget { /** * A title to be displayed in a Granite.SettingsSidebar */ - public string title { get; construct set ; } - - private Gtk.Label description_label; - private string _description; - private Adw.Clamp content_area; + public string title { get; construct set; } /** * A {@link Gtk.Box} used as the action area for #this @@ -83,17 +79,9 @@ public abstract class Switchboard.SettingsPage : Gtk.Widget { /** * Creates a {@link Gtk.Label} with a page description in the header of #this */ - public string description { - get { - return _description; - } - construct set { - if (description_label != null) { - description_label.label = value; - } - _description = value; - } - } + public string description { get; construct set; } + + private Adw.Clamp content_area; static construct { set_layout_manager_type (typeof (Gtk.BinLayout)); @@ -122,7 +110,7 @@ public abstract class Switchboard.SettingsPage : Gtk.Widget { header_area.attach (title_label, 1, 0); if (description != null) { - description_label = new Gtk.Label (description) { + var description_label = new Gtk.Label (description) { selectable = true, use_markup = true, wrap = true, @@ -131,6 +119,8 @@ public abstract class Switchboard.SettingsPage : Gtk.Widget { header_area.attach (header_icon, 0, 0, 1, 2); header_area.attach (description_label, 1, 1, 2); + + bind_property ("description", description_label, "label"); } else { header_area.attach (header_icon, 0, 0); }