Commit d98cfae5 authored by Adrien Plazas's avatar Adrien Plazas Committed by Guido Gunther
Browse files

example: Add the 'Search bar' page

This adds a demo of HdySearchBar.
parent c62c4a85
......@@ -9,12 +9,15 @@ struct _ExampleWindow
HdyLeaflet *header_box;
HdyLeaflet *content_box;
GtkButton *back;
GtkToggleButton *search_button;
GtkStackSidebar *sidebar;
GtkStack *stack;
GtkWidget *box_dialer;
HdyDialer *dialer;
GtkLabel *display;
GtkWidget *arrows;
HdySearchBar *search_bar;
GtkEntry *search_entry;
GtkListBox *column_listbox;
HdyHeaderGroup *header_group;
GtkAdjustment *adj_arrows_count;
......@@ -78,6 +81,16 @@ update (ExampleWindow *self)
hdy_header_group_set_focus (self->header_group, fold == HDY_FOLD_FOLDED ? GTK_HEADER_BAR (header_child) : NULL);
}
static void
update_header_bar (ExampleWindow *self)
{
const gchar *visible_child_name;
visible_child_name = gtk_stack_get_visible_child_name (GTK_STACK (self->stack));
gtk_widget_set_visible (GTK_WIDGET (self->search_button),
g_str_equal (visible_child_name, "search-bar"));
}
static void
example_window_notify_header_visible_child_cb (GObject *sender,
GParamSpec *pspec,
......@@ -100,6 +113,7 @@ example_window_notify_visible_child_cb (GObject *sender,
ExampleWindow *self)
{
hdy_leaflet_set_visible_child (self->content_box, GTK_WIDGET (self->stack));
update_header_bar (self);
}
static void
......@@ -263,6 +277,7 @@ example_window_constructed (GObject *object)
hdy_arrows_get_count (HDY_ARROWS (self->arrows)));
gtk_adjustment_set_value (self->adj_arrows_duration,
hdy_arrows_get_duration (HDY_ARROWS (self->arrows)));
hdy_search_bar_connect_entry (self->search_bar, self->search_entry);
}
......@@ -278,12 +293,15 @@ example_window_class_init (ExampleWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, header_box);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, content_box);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, back);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, search_button);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, sidebar);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, stack);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, box_dialer);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, dialer);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, display);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, arrows);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, search_bar);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, search_entry);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, column_listbox);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, header_group);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, adj_arrows_count);
......@@ -311,4 +329,5 @@ example_window_init (ExampleWindow *self)
gtk_list_box_set_header_func (self->column_listbox, list_box_separator_header_func, NULL, NULL);
hdy_leaflet_set_visible_child (self->content_box, GTK_WIDGET (self->stack));
update_header_bar (self);
}
......@@ -87,6 +87,34 @@
</child>
</object>
</child>
<child>
<object class="GtkToggleButton" id="search_button">
<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="active" bind-source="search_bar" bind-property="search-mode-enabled" bind-flags="sync-create|bidirectional"/>
<style>
<class name="image-button"/>
</style>
<child internal-child="accessible">
<object class="AtkObject" id="a11y-search">
<property name="accessible-name" translatable="yes">Back</property>
</object>
</child>
<child>
<object class="GtkImage" id="search_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">edit-find-symbolic</property>
<property name="icon_size">1</property>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
<packing>
<property name="name">content</property>
......@@ -674,6 +702,136 @@
<property name="title">Column</property>
</packing>
</child>
<child>
<object class="GtkOverlay">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child type="overlay">
<object class="HdySearchBar" id="search_bar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">fill</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<property name="show-close-button">True</property>
<child>
<object class="HdyColumn">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="maximum-width">600</property>
<child>
<object class="GtkSearchEntry" id="search_entry">
<property name="visible">True</property>
<property name="hexpand">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="margin_bottom">18</property>
<property name="pixel_size">128</property>
<property name="icon_name">edit-find-symbolic</property>
<property name="icon_size">0</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="margin_start">12</property>
<property name="margin_end">12</property>
<child>
<object class="GtkLabel">
<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_bottom">12</property>
<property name="label" translatable="yes">Search bar</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="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="margin_bottom">6</property>
<property name="label" translatable="yes">A search bar that gives your search entry all the space it needs.</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="label" translatable="yes">Try using it with an horizontaly expanded column to make your search entry adaptive.</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</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">search-bar</property>
<property name="title">Search bar</property>
</packing>
</child>
</object>
<packing>
<property name="name">content</property>
......
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