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: Subclass Gtk.Widget #283

Merged
merged 6 commits into from
Jan 27, 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
86 changes: 0 additions & 86 deletions lib/AbstractSettingsPage.vala

This file was deleted.

106 changes: 75 additions & 31 deletions lib/AbstractSimpleSettingsPage.vala → lib/SettingsPage.vala
Original file line number Diff line number Diff line change
@@ -1,26 +1,70 @@
/*
* 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
*/
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
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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);
}
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -129,4 +169,8 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage
}
});
}

~SettingsPage () {
get_first_child ().unparent ();
}
}
4 changes: 2 additions & 2 deletions lib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ config_header = configure_file(
)

libswitchboard_deps = [
adwaita_dep,
glib_dep,
gio_dep,
gio_unix_dep,
Expand All @@ -19,8 +20,7 @@ libswitchboard_deps = [
]

libswitchboard_lib = library('switchboard-3',
'AbstractSettingsPage.vala',
'AbstractSimpleSettingsPage.vala',
'SettingsPage.vala',
'PlugsManager.vala',
'Plug.vala',
'SettingsSidebarRow.vala',
Expand Down