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

Add HdySearchBar

This is similar to GtkSearchBar except it allows the central widget
(typically a GtkEntry) to fill all the available space. This is needed
to manage an entry's width via a HdyColumn, letting the entry (and by
extention the search bar) have a limited maximum width while allowing it
to shrink to accomodate smaller windows.
parent e7812490
......@@ -43,6 +43,7 @@
<xi:include href="xml/hdy-dialer-cycle-button.xml"/>
<xi:include href="xml/hdy-header-group.xml"/>
<xi:include href="xml/hdy-leaflet.xml"/>
<xi:include href="xml/hdy-search-bar.xml"/>
<xi:include href="xml/hdy-title-bar.xml"/>
</chapter>
......
......@@ -19,6 +19,7 @@
</properties>
</glade-widget-class>
<glade-widget-class name="HdyLeaflet" generic-name="leaflet" title="Leaflet"/>
<glade-widget-class name="HdySearchBar" generic-name="searchbar" title="Search Bar"/>
<glade-widget-class name="HdyTitleBar" generic-name="titlebar" title="Title Bar"/>
</glade-widget-classes>
......@@ -28,6 +29,7 @@
<glade-widget-class-ref name="HdyDialer"/>
<glade-widget-class-ref name="HdyHeaderGroup"/>
<glade-widget-class-ref name="HdyLeaflet"/>
<glade-widget-class-ref name="HdySearchBar"/>
<glade-widget-class-ref name="HdyTitleBar"/>
</glade-widget-group>
</glade-catalog>
......@@ -3,5 +3,6 @@
<gresource prefix="/sm/puri/handy/dialer/ui">
<file preprocess="xml-stripblanks">hdy-dialer.ui</file>
<file preprocess="xml-stripblanks">hdy-dialer-button.ui</file>
<file preprocess="xml-stripblanks">hdy-search-bar.ui</file>
</gresource>
</gresources>
......@@ -34,6 +34,7 @@ G_BEGIN_DECLS
#include "hdy-header-group.h"
#include "hdy-leaflet.h"
#include "hdy-main.h"
#include "hdy-search-bar.h"
#include "hdy-string-utf8.h"
#include "hdy-title-bar.h"
......
This diff is collapsed.
/*
* Copyright (C) 2017 Purism SPC
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#pragma once
#if !defined(_HANDY_INSIDE) && !defined(HANDY_COMPILATION)
#error "Only <handy.h> can be included directly."
#endif
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define HDY_TYPE_SEARCH_BAR (hdy_search_bar_get_type())
G_DECLARE_DERIVABLE_TYPE (HdySearchBar, hdy_search_bar, HDY, SEARCH_BAR, GtkBin)
struct _HdySearchBarClass
{
GtkBinClass parent_class;
};
GtkWidget *hdy_search_bar_new (void);
void hdy_search_bar_connect_entry (HdySearchBar *self,
GtkEntry *entry);
gboolean hdy_search_bar_get_search_mode (HdySearchBar *self);
void hdy_search_bar_set_search_mode (HdySearchBar *self,
gboolean search_mode);
gboolean hdy_search_bar_get_show_close_button (HdySearchBar *self);
void hdy_search_bar_set_show_close_button (HdySearchBar *self,
gboolean visible);
gboolean hdy_search_bar_handle_event (HdySearchBar *self,
GdkEvent *event);
G_END_DECLS
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="HdySearchBar" parent="GtkBin">
<child>
<object class="GtkRevealer" id="revealer">
<property name="visible">True</property>
<property name="hexpand">True</property>
<child>
<object class="GtkBox" id="tool_box">
<property name="visible">True</property>
<property name="border-width">6</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="start">
<property name="visible">True</property>
<property name="halign">start</property>
<property name="orientation">vertical</property>
</object>
</child>
<child>
<object class="GtkBox" id="end">
<property name="visible">True</property>
<property name="halign">end</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="close_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">1</property>
<property name="relief">none</property>
<style>
<class name="close"/>
</style>
<child>
<object class="GtkImage" id="close_image">
<property name="visible">True</property>
<property name="icon-size">1</property>
<property name="icon-name">window-close-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</template>
<object class="GtkSizeGroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="start"/>
<widget name="end"/>
</widgets>
</object>
</interface>
......@@ -57,6 +57,7 @@ src_headers = [
'hdy-header-group.h',
'hdy-leaflet.h',
'hdy-main.h',
'hdy-search-bar.h',
'hdy-string-utf8.h',
'hdy-title-bar.h',
]
......@@ -84,6 +85,7 @@ src_sources = [
'hdy-header-group.c',
'hdy-leaflet.c',
'hdy-main.c',
'hdy-search-bar.c',
'hdy-string-utf8.c',
'hdy-title-bar.c',
]
......
......@@ -23,6 +23,7 @@ test_names = [
'test-dialer',
'test-dialer-cycle-button',
'test-header-group',
'test-search-bar',
'test-string-utf8',
]
......
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
static void
test_hdy_search_bar_add (void)
{
g_autoptr (HdySearchBar) bar = NULL;
GtkWidget *entry;
bar = g_object_ref_sink (HDY_SEARCH_BAR (hdy_search_bar_new ()));
g_assert_nonnull (bar);
entry = gtk_entry_new ();
g_assert_nonnull (entry);
gtk_container_add (GTK_CONTAINER (bar), entry);
}
static void
test_hdy_search_bar_connect_entry (void)
{
g_autoptr (HdySearchBar) bar = NULL;
GtkWidget *box, *entry;
bar = g_object_ref_sink (HDY_SEARCH_BAR (hdy_search_bar_new ()));
g_assert_nonnull (bar);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
g_assert_nonnull (box);
entry = gtk_entry_new ();
g_assert_nonnull (entry);
gtk_container_add (GTK_CONTAINER (box), entry);
gtk_container_add (GTK_CONTAINER (bar), box);
hdy_search_bar_connect_entry (bar, GTK_ENTRY (entry));
}
static void
test_hdy_search_bar_search_mode (void)
{
g_autoptr (HdySearchBar) bar = NULL;
bar = g_object_ref_sink (HDY_SEARCH_BAR (hdy_search_bar_new ()));
g_assert_nonnull (bar);
g_assert_false (hdy_search_bar_get_search_mode (bar));
hdy_search_bar_set_search_mode (bar, TRUE);
g_assert_true (hdy_search_bar_get_search_mode (bar));
hdy_search_bar_set_search_mode (bar, FALSE);
g_assert_false (hdy_search_bar_get_search_mode (bar));
}
static void
test_hdy_search_bar_show_close_button (void)
{
g_autoptr (HdySearchBar) bar = NULL;
bar = g_object_ref_sink (HDY_SEARCH_BAR (hdy_search_bar_new ()));
g_assert_nonnull (bar);
g_assert_false (hdy_search_bar_get_show_close_button (bar));
hdy_search_bar_set_show_close_button (bar, TRUE);
g_assert_true (hdy_search_bar_get_show_close_button (bar));
hdy_search_bar_set_show_close_button (bar, FALSE);
g_assert_false (hdy_search_bar_get_show_close_button (bar));
}
gint
main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
g_test_add_func("/Handy/SearchBar/add", test_hdy_search_bar_add);
g_test_add_func("/Handy/SearchBar/connect_entry", test_hdy_search_bar_connect_entry);
g_test_add_func("/Handy/SearchBar/search_mode", test_hdy_search_bar_search_mode);
g_test_add_func("/Handy/SearchBar/show_close_button", test_hdy_search_bar_show_close_button);
return g_test_run();
}
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