Commit 723f0646 authored by Adrien Plazas's avatar Adrien Plazas

examples: Add a complex HdyDialog example

This shows how to use HdyHeaderBar and HdyDialog to create a more
complex adaptive dialog.
parent 64d6e60e
Pipeline #21207 passed with stages
in 7 minutes and 52 seconds
......@@ -3,6 +3,7 @@
<gresource prefix="/sm/puri/handy/demo/ui">
<file preprocess="xml-stripblanks">hdy-demo-preferences-window.ui</file>
<file preprocess="xml-stripblanks">hdy-demo-window.ui</file>
<file preprocess="xml-stripblanks">hdy-dialog-complex-example.ui</file>
<file preprocess="xml-stripblanks">hdy-view-switcher-demo-window.ui</file>
<file compressed="true">style.css</file>
</gresource>
......
......@@ -273,6 +273,35 @@ dialog_action_clicked_cb (GtkButton *btn,
gtk_widget_show (dlg);
}
static void
dialog_complex_deeper_clicked_cb (GtkStack *stack)
{
gtk_stack_set_visible_child_name (stack, "sub");
}
static void
dialog_complex_back_clicked_cb (GtkStack *stack)
{
gtk_stack_set_visible_child_name (stack, "main");
}
static void
dialog_complex_clicked_cb (GtkButton *btn,
HdyDemoWindow *self)
{
g_autoptr (GtkBuilder) builder = gtk_builder_new_from_resource ("/sm/puri/handy/demo/ui/hdy-dialog-complex-example.ui");
GtkWidget *dlg, *back, *deeper, *stack;
dlg = GTK_WIDGET (gtk_builder_get_object (builder, "dialog"));
back = GTK_WIDGET (gtk_builder_get_object (builder, "back"));
deeper = GTK_WIDGET (gtk_builder_get_object (builder, "deeper"));
stack = GTK_WIDGET (gtk_builder_get_object (builder, "content_stack"));
g_signal_connect_swapped (deeper, "clicked", G_CALLBACK (dialog_complex_deeper_clicked_cb), stack);
g_signal_connect_swapped (back, "clicked", G_CALLBACK (dialog_complex_back_clicked_cb), stack);
gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (self));
gtk_widget_show (dlg);
}
static void
view_switcher_demo_clicked_cb (GtkButton *btn,
......@@ -359,6 +388,7 @@ hdy_demo_window_class_init (HdyDemoWindowClass *klass)
gtk_widget_class_bind_template_callback_full (widget_class, "adj_arrows_duration_value_changed_cb", G_CALLBACK(adj_arrows_duration_value_changed_cb));
gtk_widget_class_bind_template_callback_full (widget_class, "dialog_clicked_cb", G_CALLBACK(dialog_clicked_cb));
gtk_widget_class_bind_template_callback_full (widget_class, "dialog_action_clicked_cb", G_CALLBACK(dialog_action_clicked_cb));
gtk_widget_class_bind_template_callback_full (widget_class, "dialog_complex_clicked_cb", G_CALLBACK(dialog_complex_clicked_cb));
gtk_widget_class_bind_template_callback_full (widget_class, "view_switcher_demo_clicked_cb", G_CALLBACK(view_switcher_demo_clicked_cb));
}
......
......@@ -1225,6 +1225,13 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="label" translatable="yes">Complex Dialog</property>
<signal name="clicked" handler="dialog_complex_clicked_cb" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.16"/>
<requires lib="libhandy" version="0.0"/>
<object class="HdyDialog" id="dialog">
<property name="can_focus">False</property>
<property name="title">Handy Demo</property>
<signal name="key-press-event" handler="key_pressed_cb" after="yes" swapped="no"/>
<child type="titlebar">
<object class="HdyTitleBar">
<property name="visible">True</property>
<child>
<object class="GtkStack">
<property name="visible">True</property>
<property name="transition-type">slide-left-right</property>
<property name="visible-child-name" bind-source="content_stack" bind-property="visible-child-name" bind-flags="sync-create|bidirectional"/>
<signal name="notify::visible-child" handler="notify_header_visible_child_cb" swapped="no"/>
<child>
<object class="HdyHeaderBar" id="header_bar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">We need to go deeper</property>
<property name="show_close_button">True</property>
</object>
<packing>
<property name="name">main</property>
</packing>
</child>
<child>
<object class="HdyHeaderBar" id="sub_header_bar">
<property name="visible">True</property>
<property name="expand">True</property>
<child>
<object class="GtkButton" id="back">
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="valign">center</property>
<property name="use-underline">True</property>
<property name="visible">True</property>
<signal name="clicked" handler="back_clicked_cb"/>
<style>
<class name="image-button"/>
</style>
<child internal-child="accessible">
<object class="AtkObject" id="a11y-back">
<property name="accessible-name" translatable="yes">Back</property>
</object>
</child>
<child>
<object class="GtkImage" id="back_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-previous-symbolic</property>
<property name="icon_size">1</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="name">sub</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="visible">True</property>
<property name="border_width">0</property>
<child>
<object class="GtkStack" id="content_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="vexpand">True</property>
<property name="transition_type">slide-left-right</property>
<child>
<object class="GtkButton" id="deeper">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Go deeper</property>
<property name="halign">center</property>
<property name="valign">center</property>
</object>
<packing>
<property name="name">main</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="halign">center</property>
<property name="margin">12</property>
<property name="label" translatable="yes">That's too deep!</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
<property name="name">sub</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
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