[libhandy] action-row: Add the title-lines and subtitle-lines properties
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] action-row: Add the title-lines and subtitle-lines properties
- Date: Thu, 12 Nov 2020 15:03:54 +0000 (UTC)
commit 150331c58e849448eb734784bab06fc421062a50
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Nov 11 09:12:38 2020 +0100
action-row: Add the title-lines and subtitle-lines properties
This allows to set the line number at th end of which the title and
subtitle labels should ellipsized.
Fixes https://gitlab.gnome.org/GNOME/libhandy/-/issues/116
debian/libhandy-1-0.symbols | 4 ++
doc/handy-docs.xml | 5 ++
src/hdy-action-row.c | 168 ++++++++++++++++++++++++++++++++++++++++++++
src/hdy-action-row.h | 12 ++++
src/hdy-action-row.ui | 4 ++
tests/test-action-row.c | 44 ++++++++++++
6 files changed, 237 insertions(+)
---
diff --git a/debian/libhandy-1-0.symbols b/debian/libhandy-1-0.symbols
index 77c9884c..75901fae 100644
--- a/debian/libhandy-1-0.symbols
+++ b/debian/libhandy-1-0.symbols
@@ -5,12 +5,16 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
hdy_action_row_get_activatable_widget@LIBHANDY_1_0 0.0.7
hdy_action_row_get_icon_name@LIBHANDY_1_0 0.0.6
hdy_action_row_get_subtitle@LIBHANDY_1_0 0.0.6
+ hdy_action_row_get_subtitle_lines@LIBHANDY_1_0 1.1.0
+ hdy_action_row_get_title_lines@LIBHANDY_1_0 1.1.0
hdy_action_row_get_type@LIBHANDY_1_0 0.0.6
hdy_action_row_get_use_underline@LIBHANDY_1_0 0.0.6
hdy_action_row_new@LIBHANDY_1_0 0.0.6
hdy_action_row_set_activatable_widget@LIBHANDY_1_0 0.0.7
hdy_action_row_set_icon_name@LIBHANDY_1_0 0.0.6
hdy_action_row_set_subtitle@LIBHANDY_1_0 0.0.6
+ hdy_action_row_set_subtitle_lines@LIBHANDY_1_0 1.1.0
+ hdy_action_row_set_title_lines@LIBHANDY_1_0 1.1.0
hdy_action_row_set_use_underline@LIBHANDY_1_0 0.0.6
hdy_application_window_get_type@LIBHANDY_1_0 0.80.0
hdy_application_window_new@LIBHANDY_1_0 0.80.0
diff --git a/doc/handy-docs.xml b/doc/handy-docs.xml
index 18c15263..e60dc514 100644
--- a/doc/handy-docs.xml
+++ b/doc/handy-docs.xml
@@ -132,6 +132,11 @@
<xi:include href="xml/api-index-1.0.xml"><xi:fallback /></xi:include>
</index>
+ <index id="api-index-1-1" role="1.1">
+ <title>Index of new symbols in 1.1</title>
+ <xi:include href="xml/api-index-1.1.xml"><xi:fallback /></xi:include>
+ </index>
+
<index id="annotations-glossary">
<title>Annotations glossary</title>
<xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
diff --git a/src/hdy-action-row.c b/src/hdy-action-row.c
index dfcaf318..6ae6ab77 100644
--- a/src/hdy-action-row.c
+++ b/src/hdy-action-row.c
@@ -57,6 +57,8 @@ typedef struct
GtkWidget *previous_parent;
gboolean use_underline;
+ gint title_lines;
+ gint subtitle_lines;
GtkWidget *activatable_widget;
} HdyActionRowPrivate;
@@ -75,6 +77,8 @@ enum {
PROP_ACTIVATABLE_WIDGET,
PROP_SUBTITLE,
PROP_USE_UNDERLINE,
+ PROP_TITLE_LINES,
+ PROP_SUBTITLE_LINES,
LAST_PROP,
};
@@ -142,6 +146,12 @@ hdy_action_row_get_property (GObject *object,
case PROP_SUBTITLE:
g_value_set_string (value, hdy_action_row_get_subtitle (self));
break;
+ case PROP_SUBTITLE_LINES:
+ g_value_set_int (value, hdy_action_row_get_subtitle_lines (self));
+ break;
+ case PROP_TITLE_LINES:
+ g_value_set_int (value, hdy_action_row_get_title_lines (self));
+ break;
case PROP_USE_UNDERLINE:
g_value_set_boolean (value, hdy_action_row_get_use_underline (self));
break;
@@ -168,6 +178,12 @@ hdy_action_row_set_property (GObject *object,
case PROP_SUBTITLE:
hdy_action_row_set_subtitle (self, g_value_get_string (value));
break;
+ case PROP_SUBTITLE_LINES:
+ hdy_action_row_set_subtitle_lines (self, g_value_get_int (value));
+ break;
+ case PROP_TITLE_LINES:
+ hdy_action_row_set_title_lines (self, g_value_get_int (value));
+ break;
case PROP_USE_UNDERLINE:
hdy_action_row_set_use_underline (self, g_value_get_boolean (value));
break;
@@ -399,6 +415,39 @@ hdy_action_row_class_init (HdyActionRowClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * HdyActionRow:title-lines:
+ *
+ * The number of lines at the end of which the title label will be ellipsized.
+ * Set this property to 0 if you don't want to limit the number of lines.
+ *
+ * Since: 1.1
+ */
+ props[PROP_TITLE_LINES] =
+ g_param_spec_int ("title-lines",
+ _("Number of title lines"),
+ _("The desired number of title lines"),
+ 0, G_MAXINT,
+ 1,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
+ /**
+ * HdyActionRow:subtitle-lines:
+ *
+ * The number of lines at the end of which the subtitle label will be
+ * ellipsized.
+ * Set this property to 0 if you don't want to limit the number of lines.
+ *
+ * Since: 1.1
+ */
+ props[PROP_SUBTITLE_LINES] =
+ g_param_spec_int ("subtitle-lines",
+ _("Number of subtitle lines"),
+ _("The desired number of subtitle lines"),
+ 0, G_MAXINT,
+ 1,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
g_object_class_install_properties (object_class, LAST_PROP, props);
/**
@@ -447,6 +496,9 @@ hdy_action_row_init (HdyActionRow *self)
{
HdyActionRowPrivate *priv = hdy_action_row_get_instance_private (self);
+ priv->title_lines = 1;
+ priv->subtitle_lines = 1;
+
gtk_widget_init_template (GTK_WIDGET (self));
g_object_bind_property_full (self, "title", priv->title, "visible", G_BINDING_SYNC_CREATE,
@@ -743,6 +795,122 @@ hdy_action_row_set_use_underline (HdyActionRow *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_USE_UNDERLINE]);
}
+/**
+ * hdy_action_row_get_title_lines:
+ * @self: a #HdyActionRow
+ *
+ * Gets the number of lines at the end of which the title label will be
+ * ellipsized.
+ * If the value is 0, the number of lines won't be limited.
+ *
+ * Returns: the number of lines at the end of which the title label will be
+ * ellipsized.
+ *
+ * Since: 1.1
+ */
+gint
+hdy_action_row_get_title_lines (HdyActionRow *self)
+{
+ HdyActionRowPrivate *priv;
+
+ g_return_val_if_fail (HDY_IS_ACTION_ROW (self), 0);
+
+ priv = hdy_action_row_get_instance_private (self);
+
+ return priv->title_lines;
+}
+
+/**
+ * hdy_action_row_set_title_lines:
+ * @self: a #HdyActionRow
+ * @title_lines: the number of lines at the end of which the title label will be ellipsized
+ *
+ * Sets the number of lines at the end of which the title label will be
+ * ellipsized.
+ * If the value is 0, the number of lines won't be limited.
+ *
+ * Since: 1.1
+ */
+void
+hdy_action_row_set_title_lines (HdyActionRow *self,
+ gint title_lines)
+{
+ HdyActionRowPrivate *priv;
+
+ g_return_if_fail (HDY_IS_ACTION_ROW (self));
+ g_return_if_fail (title_lines >= 0);
+
+ priv = hdy_action_row_get_instance_private (self);
+
+ if (priv->title_lines == title_lines)
+ return;
+
+ priv->title_lines = title_lines;
+
+ gtk_label_set_lines (priv->title, title_lines);
+ gtk_label_set_ellipsize (priv->title, title_lines == 0 ? PANGO_ELLIPSIZE_NONE : PANGO_ELLIPSIZE_END);
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TITLE_LINES]);
+}
+
+/**
+ * hdy_action_row_get_subtitle_lines:
+ * @self: a #HdyActionRow
+ *
+ * Gets the number of lines at the end of which the subtitle label will be
+ * ellipsized.
+ * If the value is 0, the number of lines won't be limited.
+ *
+ * Returns: the number of lines at the end of which the subtitle label will be
+ * ellipsized.
+ *
+ * Since: 1.1
+ */
+gint
+hdy_action_row_get_subtitle_lines (HdyActionRow *self)
+{
+ HdyActionRowPrivate *priv;
+
+ g_return_val_if_fail (HDY_IS_ACTION_ROW (self), 0);
+
+ priv = hdy_action_row_get_instance_private (self);
+
+ return priv->subtitle_lines;
+}
+
+/**
+ * hdy_action_row_set_subtitle_lines:
+ * @self: a #HdyActionRow
+ * @subtitle_lines: the number of lines at the end of which the subtitle label will be ellipsized
+ *
+ * Sets the number of lines at the end of which the subtitle label will be
+ * ellipsized.
+ * If the value is 0, the number of lines won't be limited.
+ *
+ * Since: 1.1
+ */
+void
+hdy_action_row_set_subtitle_lines (HdyActionRow *self,
+ gint subtitle_lines)
+{
+ HdyActionRowPrivate *priv;
+
+ g_return_if_fail (HDY_IS_ACTION_ROW (self));
+ g_return_if_fail (subtitle_lines >= 0);
+
+ priv = hdy_action_row_get_instance_private (self);
+
+ if (priv->subtitle_lines == subtitle_lines)
+ return;
+
+ priv->subtitle_lines = subtitle_lines;
+
+ gtk_label_set_lines (priv->subtitle, subtitle_lines);
+ gtk_label_set_ellipsize (priv->subtitle, subtitle_lines == 0 ? PANGO_ELLIPSIZE_NONE : PANGO_ELLIPSIZE_END);
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SUBTITLE_LINES]);
+}
+
/**
* hdy_action_row_add_prefix:
* @self: a #HdyActionRow
diff --git a/src/hdy-action-row.h b/src/hdy-action-row.h
index 7b5dd53e..a795bae2 100644
--- a/src/hdy-action-row.h
+++ b/src/hdy-action-row.h
@@ -63,6 +63,18 @@ HDY_AVAILABLE_IN_ALL
void hdy_action_row_set_use_underline (HdyActionRow *self,
gboolean use_underline);
+HDY_AVAILABLE_IN_1_1
+gint hdy_action_row_get_title_lines (HdyActionRow *self);
+HDY_AVAILABLE_IN_1_1
+void hdy_action_row_set_title_lines (HdyActionRow *self,
+ gint title_lines);
+
+HDY_AVAILABLE_IN_1_1
+gint hdy_action_row_get_subtitle_lines (HdyActionRow *self);
+HDY_AVAILABLE_IN_1_1
+void hdy_action_row_set_subtitle_lines (HdyActionRow *self,
+ gint subtitle_lines);
+
HDY_AVAILABLE_IN_ALL
void hdy_action_row_add_prefix (HdyActionRow *self,
GtkWidget *widget);
diff --git a/src/hdy-action-row.ui b/src/hdy-action-row.ui
index ff54c152..9374d683 100644
--- a/src/hdy-action-row.ui
+++ b/src/hdy-action-row.ui
@@ -44,7 +44,9 @@
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="label" bind-source="HdyActionRow" bind-property="title"
bind-flags="sync-create"/>
+ <property name="lines">1</property>
<property name="visible">True</property>
+ <property name="wrap">True</property>
<property name="xalign">0</property>
<style>
<class name="title"/>
@@ -57,6 +59,8 @@
<property name="ellipsize">end</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
+ <property name="lines">1</property>
+ <property name="wrap">True</property>
<property name="xalign">0</property>
<style>
<class name="subtitle"/>
diff --git a/tests/test-action-row.c b/tests/test-action-row.c
index 10b3f9a5..822eada4 100644
--- a/tests/test-action-row.c
+++ b/tests/test-action-row.c
@@ -95,6 +95,48 @@ test_hdy_action_row_use_underline (void)
}
+static void
+test_hdy_action_row_title_lines (void)
+{
+ g_autoptr (HdyActionRow) row = NULL;
+
+ row = g_object_ref_sink (HDY_ACTION_ROW (hdy_action_row_new ()));
+ g_assert_nonnull (row);
+
+ g_assert_cmpint (hdy_action_row_get_title_lines (row), ==, 1);
+
+ g_test_expect_message (HDY_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "hdy_action_row_set_title_lines: assertion
'title_lines >= 0' failed");
+ hdy_action_row_set_title_lines (row, -1);
+ g_test_assert_expected_messages ();
+
+ g_assert_cmpint (hdy_action_row_get_title_lines (row), ==, 1);
+
+ hdy_action_row_set_title_lines (row, 0);
+ g_assert_cmpint (hdy_action_row_get_title_lines (row), ==, 0);
+}
+
+
+static void
+test_hdy_action_row_subtitle_lines (void)
+{
+ g_autoptr (HdyActionRow) row = NULL;
+
+ row = g_object_ref_sink (HDY_ACTION_ROW (hdy_action_row_new ()));
+ g_assert_nonnull (row);
+
+ g_assert_cmpint (hdy_action_row_get_subtitle_lines (row), ==, 1);
+
+ g_test_expect_message (HDY_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "hdy_action_row_set_subtitle_lines: assertion
'subtitle_lines >= 0' failed");
+ hdy_action_row_set_subtitle_lines (row, -1);
+ g_test_assert_expected_messages ();
+
+ g_assert_cmpint (hdy_action_row_get_subtitle_lines (row), ==, 1);
+
+ hdy_action_row_set_subtitle_lines (row, 0);
+ g_assert_cmpint (hdy_action_row_get_subtitle_lines (row), ==, 0);
+}
+
+
static void
test_hdy_action_row_activate (void)
{
@@ -123,6 +165,8 @@ main (gint argc,
g_test_add_func("/Handy/ActionRow/subtitle", test_hdy_action_row_subtitle);
g_test_add_func("/Handy/ActionRow/icon_name", test_hdy_action_row_icon_name);
g_test_add_func("/Handy/ActionRow/use_underline", test_hdy_action_row_use_underline);
+ g_test_add_func("/Handy/ActionRow/title_lines", test_hdy_action_row_title_lines);
+ g_test_add_func("/Handy/ActionRow/subtitle_lines", test_hdy_action_row_subtitle_lines);
g_test_add_func("/Handy/ActionRow/activate", test_hdy_action_row_activate);
return g_test_run();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]