Commit 83ee5ec4 authored by Adrien Plazas's avatar Adrien Plazas Committed by Guido Gunther

Add HdyComboRow

parent 816cc31c
......@@ -39,6 +39,7 @@
<xi:include href="xml/hdy-action-row.xml"/>
<xi:include href="xml/hdy-arrows.xml"/>
<xi:include href="xml/hdy-column.xml"/>
<xi:include href="xml/hdy-combo-row.xml"/>
<xi:include href="xml/hdy-dialer.xml"/>
<xi:include href="xml/hdy-dialer-button.xml"/>
<xi:include href="xml/hdy-dialer-cycle-button.xml"/>
......
......@@ -27,6 +27,7 @@
<glade-widget-class-ref name="HdyActionRow"/>
<glade-widget-class-ref name="HdyArrows"/>
<glade-widget-class-ref name="HdyColumn"/>
<glade-widget-class-ref name="HdyComboRow"/>
<glade-widget-class-ref name="HdyDialer"/>
<glade-widget-class-ref name="HdyExpanderRow"/>
<glade-widget-class-ref name="HdyHeaderGroup"/>
......
......@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/sm/puri/handy/dialer/ui">
<file preprocess="xml-stripblanks">hdy-action-row.ui</file>
<file preprocess="xml-stripblanks">hdy-combo-row.ui</file>
<file preprocess="xml-stripblanks">hdy-dialer.ui</file>
<file preprocess="xml-stripblanks">hdy-dialer-button.ui</file>
<file preprocess="xml-stripblanks">hdy-expander-row.ui</file>
......
......@@ -28,6 +28,7 @@ G_BEGIN_DECLS
#include "hdy-action-row.h"
#include "hdy-arrows.h"
#include "hdy-column.h"
#include "hdy-combo-row.h"
#include "hdy-dialer-button.h"
#include "hdy-dialer-cycle-button.h"
#include "hdy-dialer.h"
......
This diff is collapsed.
/*
* Copyright (C) 2018 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>
#include "hdy-enum-value-object.h"
#include "hdy-action-row.h"
G_BEGIN_DECLS
#define HDY_TYPE_COMBO_ROW (hdy_combo_row_get_type())
G_DECLARE_DERIVABLE_TYPE (HdyComboRow, hdy_combo_row, HDY, COMBO_ROW, HdyActionRow)
/**
* HdyComboRowGetNameFunc:
* @item: (type GObject): the item from the model from which to get a name
* @user_data: (closure): user data
*
* Called for combo rows that are bound to a #GListModel with
* hdy_combo_row_bind_name_model() for each item that gets added to the model.
*
* Returns: (transfer full): a newly allocated displayable name that represents @item
*/
typedef gchar * (*HdyComboRowGetNameFunc) (gpointer item,
gpointer user_data);
/**
* HdyComboRowGetEnumValueNameFunc:
* @value: the value from the enum from which to get a name
* @user_data: (closure): user data
*
* Called for combo rows that are bound to an enumeration with
* hdy_combo_row_set_for_enum() for each value from that enumeration.
*
* Returns: (transfer full): a newly allocated displayable name that represents @value
*/
typedef gchar * (*HdyComboRowGetEnumValueNameFunc) (HdyEnumValueObject *value,
gpointer user_data);
/**
* HdyComboRowClass
* @parent_class: The parent class
*/
struct _HdyComboRowClass
{
HdyActionRowClass parent_class;
};
HdyComboRow *hdy_combo_row_new (void);
GListModel *hdy_combo_row_get_model (HdyComboRow *self);
void hdy_combo_row_bind_model (HdyComboRow *self,
GListModel *model,
GtkListBoxCreateWidgetFunc create_list_widget_func,
GtkListBoxCreateWidgetFunc create_current_widget_func,
gpointer user_data,
GDestroyNotify user_data_free_func);
void hdy_combo_row_bind_name_model (HdyComboRow *self,
GListModel *model,
HdyComboRowGetNameFunc get_name_func,
gpointer user_data,
GDestroyNotify user_data_free_func);
void hdy_combo_row_set_for_enum (HdyComboRow *self,
GType enum_type,
HdyComboRowGetEnumValueNameFunc get_name_func,
gpointer user_data,
GDestroyNotify user_data_free_func);
gchar *hdy_enum_value_row_name (HdyEnumValueObject *value,
gpointer user_data);
G_END_DECLS
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="HdyComboRow" parent="HdyActionRow">
<child type="action">
<object class="GtkImage" id="image">
<property name="icon_name">pan-down-symbolic</property>
<property name="icon_size">1</property>
<property name="visible">True</property>
</object>
</child>
<child type="action">
<object class="GtkBox" id="current">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="visible">True</property>
</object>
</child>
</template>
<object class="GtkPopover" id="popover">
<property name="position">bottom</property>
<property name="relative_to">current</property>
<child>
<object class="GtkScrolledWindow">
<property name="hscrollbar_policy">never</property>
<property name="max_content_height">400</property>
<property name="propagate_natural_height">True</property>
<property name="visible">True</property>
<child>
<object class="GtkListBox" id="list">
<property name="margin_bottom">12</property>
<property name="margin_end">12</property>
<property name="margin_start">12</property>
<property name="margin_top">12</property>
<property name="selection_mode">none</property>
<property name="visible">True</property>
</object>
</child>
</object>
</child>
</object>
</interface>
......@@ -51,6 +51,7 @@ src_headers = [
'hdy-action-row.h',
'hdy-arrows.h',
'hdy-column.h',
'hdy-combo-row.h',
'hdy-dialer-button.h',
'hdy-dialer-cycle-button.h',
'hdy-dialer.h',
......@@ -81,6 +82,7 @@ src_sources = [
'hdy-action-row.c',
'hdy-arrows.c',
'hdy-column.c',
'hdy-combo-row.c',
'hdy-dialer-button.c',
'hdy-dialer-cycle-button.c',
'hdy-dialer.c',
......
......@@ -21,6 +21,7 @@ test_link_args = [
test_names = [
'test-action-row',
'test-arrows',
'test-combo-row',
'test-dialer',
'test-dialer-cycle-button',
'test-expander-row',
......
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
static void
test_hdy_combo_row_set_for_enum (void)
{
g_autoptr (HdyComboRow) row = NULL;
GListModel *model;
HdyEnumValueObject *value;
row = g_object_ref_sink (HDY_COMBO_ROW (hdy_combo_row_new ()));
g_assert_nonnull (row);
g_assert_null (hdy_combo_row_get_model (row));
hdy_combo_row_set_for_enum (row, HDY_TYPE_FOLD, hdy_enum_value_row_name, NULL, NULL);
model = hdy_combo_row_get_model (row);
g_assert_true (G_IS_LIST_MODEL (model));
g_assert_cmpuint (g_list_model_get_n_items (model), ==, 2);
value = g_list_model_get_item (model, 0);
g_assert_true (HDY_IS_ENUM_VALUE_OBJECT (value));
g_assert_cmpstr (hdy_enum_value_object_get_nick (value), ==, "unfolded");
value = g_list_model_get_item (model, 1);
g_assert_true (HDY_IS_ENUM_VALUE_OBJECT (value));
g_assert_cmpstr (hdy_enum_value_object_get_nick (value), ==, "folded");
}
gint
main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
g_test_add_func("/Handy/ComboRow/set_for_enum", test_hdy_combo_row_set_for_enum);
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