Skip to content

Commit

Permalink
library: add PreferencesWindow entry (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
halfmexican committed Jun 3, 2023
1 parent 6ea4060 commit ca34702
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 0 deletions.
182 changes: 182 additions & 0 deletions src/Library/demos/Preferences Window/main.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
using Gtk 4.0;
using Adw 1;

Adw.PreferencesWindow pref_window {
default-width: 800;
default-height: 600;
title: _("Preferences");

Adw.PreferencesPage appearance_page {
title: _("Appearance");
icon-name: "brush-monitor-symbolic";

Adw.PreferencesGroup {
title: _("Color Settings");
description: _("Change the color-scheme of the application.");

Adw.ActionRow {
title: _("Use Dark Mode");
activatable-widget: dm_switch;

[suffix]
Switch dm_switch {
halign: center;
valign: center;
}
}
}

Adw.PreferencesGroup {
title: _("Text Settings");
description: _("Customize the appearance of text in the application.");

Adw.ActionRow {
title: _("Font Size");

[suffix]
Gtk.SpinButton {
halign: center;
valign: center;
adjustment:
Gtk.Adjustment {
lower: 5;
upper: 20;
step-increment: 1;
value: 11;
};
}
}

Adw.ActionRow {
title: _("Font Color");

[suffix]
Gtk.ColorDialogButton {
halign: center;
valign: center;
dialog: ColorDialog {};
}
}
}

Adw.PreferencesGroup {
title: _("API References");

Box {
orientation: horizontal;
margin-top: 12;

LinkButton {
label: _("PreferencesWindow");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.3/class.PreferencesWindow.html";
}

LinkButton {
label: _("PreferencesPage");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.3/class.PreferencesPage.html";
}

LinkButton {
label: _("PreferencesGroup");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.3/class.PreferencesGroup.html";
}

LinkButton {
label: _("PreferencesRow");
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.3/class.PreferencesRow.html";
}
}
}
}

Adw.PreferencesPage {
title: _("Behavior");
icon-name: "settings-symbolic";

Adw.PreferencesGroup {
title: _("Interaction Settings");
description: _("Change how the app behaves during user interaction.");

// Adw.PreferencesGroup can have suffix widgets like Adw.ActionRows
[header-suffix]
Button{
halign: center;
valign: center;
icon-name: "settings-symbolic";
}

Adw.ActionRow {
title: _("Run on Startup");
activatable-widget: startup_switch;

[suffix]
Switch startup_switch {
halign: center;
valign: center;
}
}

Adw.ActionRow {
title: _("Show Toast");
activatable-widget: toast_button;

[suffix]
Button toast_button {
halign: center;
valign: center;
label: _("show toast");
icon-name: "bread-symbolic";
}
}
}

Adw.PreferencesGroup {
title: _("Data Settings");
description: _("Manage user data related settings.");

Adw.ActionRow {
title: _("Enable Telemetry");
activatable-widget: telemetry_switch;

[suffix]
Switch telemetry_switch{
halign: center;
valign: center;
}
}

Adw.ActionRow {
title: _("Enable Auto-Updates");
activatable-widget: update_switch;

[suffix]
Switch update_switch {
halign: center;
valign: center;
}
}

Adw.ActionRow subpage_row {
title: _("Additional Preferences");
activatable: true;

[suffix]
Gtk.Image {
icon-name: "go-next-symbolic";
styles ["dim-label"]
}
}
}
}
}

Adw.StatusPage subpage {
description: _("Custom Subpage");

Gtk.Button subpage_button {
label: _("Go back");
halign: center;
valign: center;
styles ["suggested-action", "pill"]
}
}
37 changes: 37 additions & 0 deletions src/Library/demos/Preferences Window/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Adw from "gi://Adw";

const pref_window = workbench.builder.get_object("pref_window");
const dm_switch = workbench.builder.get_object("dm_switch");
const subpage = workbench.builder.get_object("subpage");
const subpage_row = workbench.builder.get_object("subpage_row");
const subpage_button = workbench.builder.get_object("subpage_button");
const toast_button = workbench.builder.get_object("toast_button");
const style_manager = Adw.StyleManager.get_default();

dm_switch.active = style_manager.dark;

dm_switch.connect("notify::active", () => {
// When the Switch is toggled, set the color scheme
if (dm_switch.active) {
style_manager.color_scheme = Adw.ColorScheme.FORCE_DARK;
} else {
style_manager.color_scheme = Adw.ColorScheme.FORCE_LIGHT;
}
});

// Preferences windows can display subpages
subpage_row.connect("activated", () => {
pref_window.present_subpage(subpage);
});

subpage_button.connect("clicked", () => {
pref_window.close_subpage();
});

toast_button.connect("clicked", () => {
const toast = new Adw.Toast({
title: "Preferences windows can display toasts",
});

pref_window.add_toast(toast);
});
7 changes: 7 additions & 0 deletions src/Library/demos/Preferences Window/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Preferences Window",
"category": "user_interface",
"description": "A window containing an application's preferences",
"panels": ["ui", "preview"],
"autorun": true
}

0 comments on commit ca34702

Please sign in to comment.