diff --git a/lib/AbstractSettingsPage.vala b/lib/AbstractSettingsPage.vala deleted file mode 100644 index 6fd1b852..00000000 --- a/lib/AbstractSettingsPage.vala +++ /dev/null @@ -1,86 +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.Box { - 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 - */ - 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; - } - } - - 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/SettingsPage.vala similarity index 53% rename from lib/AbstractSimpleSettingsPage.vala rename to lib/SettingsPage.vala index 053c813b..e372ae4b 100644 --- a/lib/AbstractSimpleSettingsPage.vala +++ b/lib/SettingsPage.vala @@ -1,16 +1,53 @@ /* - * Copyright 2017–2022 elementary, Inc. (https://elementary.io) - * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2017–2024 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; } -public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage { - private Gtk.Label description_label; - private string _description; + /** + * 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; } /** * A {@link Gtk.Box} used as the action area for #this @@ -18,9 +55,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 @@ -35,24 +79,12 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage /** * 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; } - /** - * Creates a new SimpleSettingsPage - * Deprecated: Subclass this instead. - */ - protected SimpleSettingsPage () { + private Adw.Clamp content_area; + static construct { + set_layout_manager_type (typeof (Gtk.BinLayout)); } class construct { @@ -78,7 +110,7 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage 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, @@ -87,6 +119,8 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage 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); } @@ -98,9 +132,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 +147,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 +169,8 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage } }); } + + ~SettingsPage () { + get_first_child ().unparent (); + } } diff --git a/lib/meson.build b/lib/meson.build index 6ce8ab2f..5f5f733e 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, @@ -19,8 +20,7 @@ libswitchboard_deps = [ ] libswitchboard_lib = library('switchboard-3', - 'AbstractSettingsPage.vala', - 'AbstractSimpleSettingsPage.vala', + 'SettingsPage.vala', 'PlugsManager.vala', 'Plug.vala', 'SettingsSidebarRow.vala',