Skip to content

Commit

Permalink
Add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Sep 18, 2024
1 parent a6f3bcb commit ec80037
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
9 changes: 2 additions & 7 deletions demo/GraniteDemo.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ public class Granite.Demo : Gtk.Application {
var overlaybar_view = new OverlayBarView ();
var toast_view = new ToastView ();
var settings_uris_view = new SettingsUrisView ();
var style_manager_view = new StyleManagerView ();
var utils_view = new UtilsView ();
var placeholder = new WelcomeView ();
var dialogs_view = new DialogsView (window);
var application_view = new ApplicationView ();

var main_stack = new Gtk.Stack ();
main_stack.add_titled (placeholder, "placeholder", "Placeholder");
main_stack.add_titled (style_manager_view, "style_manager", "StyleManager");
main_stack.add_titled (accel_label_view, "accel_label", "AccelLabel");
main_stack.add_titled (css_view, "css", "Style Classes");
main_stack.add_titled (date_time_picker_view, "pickers", "Date & Time");
Expand Down Expand Up @@ -94,9 +96,6 @@ public class Granite.Demo : Gtk.Application {
shrink_start_child = false
};

var granite_settings = Granite.Settings.get_default ();
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;

window.child = paned;
window.set_default_size (900, 600);
window.set_size_request (750, 500);
Expand All @@ -105,10 +104,6 @@ public class Granite.Demo : Gtk.Application {

add_window (window);
window.show ();

granite_settings.notify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
});
}

public static int main (string[] args) {
Expand Down
51 changes: 51 additions & 0 deletions demo/Views/StyleManagerView.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

public class StyleManagerView : Gtk.Box {
construct {
var label = new Gtk.Label (_("Override the application theme:"));

var dont_button = new Gtk.CheckButton.with_label (_("Use system theme")) {
active = true
};

var force_light = new Gtk.CheckButton.with_label (_("Force light theme")) {
group = dont_button
};

var force_dark = new Gtk.CheckButton.with_label (_("Force dark theme")) {
group = force_light
};

halign = CENTER;
valign = CENTER;
orientation = VERTICAL;
spacing = 6;
append (label);
append (dont_button);
append (force_light);
append (force_dark);

var style_manager = Granite.StyleManager.get_instance ();

dont_button.toggled.connect (() => {
if (dont_button.active) {
style_manager.color_scheme_override = NO_PREFERENCE;
}
});

force_light.toggled.connect (() => {
if (force_light.active) {
style_manager.color_scheme_override = LIGHT;
}
});

force_dark.toggled.connect (() => {
if (force_dark.active) {
style_manager.color_scheme_override = DARK;
}
});
}
}
1 change: 1 addition & 0 deletions demo/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ executable(
'Views/ModeButtonView.vala',
'Views/OverlayBarView.vala',
'Views/SettingsUrisView.vala',
'Views/StyleManagerView.vala',
'Views/ToastView.vala',
'Views/UtilsView.vala',
'Views/WelcomeView.vala',
Expand Down

0 comments on commit ec80037

Please sign in to comment.