Commit 9926209a authored by Adrien Plazas's avatar Adrien Plazas

example: Add app menu with dark theme toggle

This will help testing app menus, popovers and the dark mode on the
phone.
parent 662d7a5b
Pipeline #955 passed with stage
in 1 minute and 55 seconds
......@@ -3,6 +3,25 @@
<interface>
<requires lib="gtk+" version="3.16"/>
<requires lib="libhandy" version="0.0"/>
<object class="GtkPopover" id="menu_popover">
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="spacing">6</property>
<property name="margin">18</property>
<property name="orientation">vertical</property>
<property name="width_request">200</property>
<child>
<object class="GtkModelButton">
<property name="action-name">app.dark-theme</property>
<property name="can-focus">True</property>
<property name="text" translatable="yes">Dark theme</property>
<property name="visible">True</property>
</object>
</child>
</object>
</child>
</object>
<object class="GtkAdjustment" id="adj_arrows_count">
<property name="lower">1</property>
<property name="upper">10</property>
......@@ -38,6 +57,24 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">Handy Widget Factory</property>
<child>
<object class="GtkMenuButton" id="menu_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="popover">menu_popover</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">open-menu-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
<packing>
<property name="name">sidebar</property>
......
......@@ -4,6 +4,21 @@
#include "example-window.h"
static void
set_dark_theme (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
GtkSettings *settings = gtk_settings_get_default ();
g_object_set (G_OBJECT (settings),
"gtk-application-prefer-dark-theme",
g_variant_get_boolean (state),
NULL);
g_simple_action_set_state (action, state);
}
static void
startup (GtkApplication *app)
{
......@@ -33,8 +48,14 @@ main (int argc,
{
GtkApplication *app;
int status;
static GActionEntry app_entries[] = {
{ "dark-theme", NULL, NULL, "false", set_dark_theme },
};
app = gtk_application_new ("sm.puri.Handy.Example", G_APPLICATION_FLAGS_NONE);
g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries, G_N_ELEMENTS (app_entries),
app);
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
g_signal_connect (app, "activate", G_CALLBACK (show_window), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment