Commit 8bdc6c91 authored by Zander Brown's avatar Zander Brown Committed by Adrien Plazas
Browse files

examples: Add the View Switcher page

This example presents a HdyViewSwitcher and a HdyViewSwitcherBar in
their own window. Currently both are visible at the same time, a later
commit should make only one visible at a time, depending on the
available width.
parent 308a117c
Pipeline #8410 passed with stage
in 4 minutes and 28 seconds
......@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/sm/puri/handy/demo/ui">
<file preprocess="xml-stripblanks">hdy-demo-window.ui</file>
<file preprocess="xml-stripblanks">hdy-view-switcher-demo-window.ui</file>
<file compressed="true">style.css</file>
</gresource>
</gresources>
......@@ -3,6 +3,7 @@
#include <glib/gi18n.h>
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
#include "hdy-view-switcher-demo-window.h"
struct _HdyDemoWindow
{
......@@ -275,6 +276,17 @@ dialog_action_clicked_cb (GtkButton *btn,
gtk_widget_show (dlg);
}
static void
view_switcher_demo_clicked_cb (GtkButton *btn,
HdyDemoWindow *self)
{
HdyViewSwitcherDemoWindow *window = hdy_view_switcher_demo_window_new ();
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (self));
gtk_widget_show (GTK_WIDGET (window));
}
HdyDemoWindow *
hdy_demo_window_new (GtkApplication *application)
{
......@@ -350,6 +362,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, "view_switcher_demo_clicked_cb", G_CALLBACK(view_switcher_demo_clicked_cb));
}
static void
......
......@@ -1196,6 +1196,112 @@
<property name="title">Dialog</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="expand">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin-bottom">32</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="pixel_size">128</property>
<property name="icon_name">view-more-horizontal-symbolic</property>
<property name="icon-size">0</property>
<property name="margin-bottom">18</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="opacity">0.5</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">View Switcher</property>
<property name="halign">center</property>
<property name="xalign">0</property>
<property name="margin-bottom">12</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="opacity">0.5</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Widgets to switch the window's view.</property>
<property name="justify">center</property>
<property name="use_markup">true</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="spacing">12</property>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="label" translatable="yes">Run the demo</property>
<signal name="clicked" handler="view_switcher_demo_clicked_cb" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="name">view-switcher</property>
<property name="title">View Switcher</property>
</packing>
</child>
</object>
</child>
</object>
......
#include "hdy-view-switcher-demo-window.h"
#include <glib/gi18n.h>
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
struct _HdyViewSwitcherDemoWindow
{
GtkWindow parent_instance;
};
G_DEFINE_TYPE (HdyViewSwitcherDemoWindow, hdy_view_switcher_demo_window, GTK_TYPE_WINDOW)
static void
hdy_view_switcher_demo_window_class_init (HdyViewSwitcherDemoWindowClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/handy/demo/ui/hdy-view-switcher-demo-window.ui");
}
static void
hdy_view_switcher_demo_window_init (HdyViewSwitcherDemoWindow *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
HdyViewSwitcherDemoWindow *
hdy_view_switcher_demo_window_new (void)
{
return g_object_new (HDY_TYPE_VIEW_SWITCHER_DEMO_WINDOW, NULL);
}
#pragma once
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define HDY_TYPE_VIEW_SWITCHER_DEMO_WINDOW (hdy_view_switcher_demo_window_get_type())
G_DECLARE_FINAL_TYPE (HdyViewSwitcherDemoWindow, hdy_view_switcher_demo_window, HDY, VIEW_SWITCHER_DEMO_WINDOW, GtkWindow)
HdyViewSwitcherDemoWindow *hdy_view_switcher_demo_window_new (void);
G_END_DECLS
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="libhandy" version="0.0"/>
<template class="HdyViewSwitcherDemoWindow" parent="GtkWindow">
<property name="can_focus">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin">24</property>
<property name="label" translatable="yes">World</property>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">World</property>
<property name="icon_name">help-about-symbolic</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin">24</property>
<property name="label" translatable="yes">Alarm</property>
</object>
<packing>
<property name="name">page2</property>
<property name="title" translatable="yes">Alarm</property>
<property name="icon_name">alarm-symbolic</property>
<property name="position">1</property>
<property name="needs_attention">True</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin">24</property>
<property name="label" translatable="yes">Stopwatch</property>
</object>
<packing>
<property name="name">page3</property>
<property name="title" translatable="yes">Stopwatch</property>
<property name="icon_name">document-print-symbolic</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin">24</property>
<property name="label" translatable="yes">Timer</property>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">Timer</property>
<property name="icon_name">weather-clear-symbolic</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="HdyViewSwitcherBar" id="switcher_bar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stack">stack</property>
<property name="reveal">True</property>
</object>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
<property name="title">HdyViewSwitcher Demo</property>
<child type="title">
<object class="HdyViewSwitcher" id="title_switcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stack">stack</property>
</object>
</child>
</object>
</child>
</template>
</interface>
......@@ -11,6 +11,7 @@ handy_demo_sources = [
handy_demo_resources,
'handy-demo.c',
'hdy-demo-window.c',
'hdy-view-switcher-demo-window.c',
libhandy_generated_headers,
]
......
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