-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
library: add PreferencesWindow entry (#297)
- Loading branch information
1 parent
6ea4060
commit ca34702
Showing
3 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |