Skip to content

Commit

Permalink
AbstractSettingsPage: Subclass Gtk.Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Jan 24, 2024
1 parent 62403e8 commit 535d97d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
20 changes: 1 addition & 19 deletions lib/AbstractSettingsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
36 changes: 29 additions & 7 deletions lib/AbstractSimpleSettingsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@
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
*/
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 Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
Expand All @@ -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) {
Expand All @@ -129,4 +147,8 @@ public abstract class Switchboard.SimpleSettingsPage : Switchboard.SettingsPage
}
});
}

~SimpleSettingsPage () {
get_first_child ().unparent ();
}
}
1 change: 1 addition & 0 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 Down

0 comments on commit 535d97d

Please sign in to comment.