From 6d15549f5156c583421275298094a4cbbaa0f2d3 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 12 Jun 2022 02:58:22 +0200 Subject: [PATCH] inscription: Add ::wrap-mode We use a different wrap-mode than GtkLabel, because we cannot just resize the widget to make long words fit, we have to fit the size we are given. --- gtk/gtkinscription.c | 69 ++++++++++++++++++++++++++++++++++++++++++++ gtk/gtkinscription.h | 5 ++++ 2 files changed, 74 insertions(+) diff --git a/gtk/gtkinscription.c b/gtk/gtkinscription.c index 6a2260027a..c8937df9e9 100644 --- a/gtk/gtkinscription.c +++ b/gtk/gtkinscription.c @@ -86,6 +86,7 @@ enum PROP_NAT_LINES, PROP_TEXT, PROP_TEXT_OVERFLOW, + PROP_WRAP_MODE, PROP_XALIGN, PROP_YALIGN, @@ -154,6 +155,10 @@ gtk_inscription_get_property (GObject *object, g_value_set_enum (value, self->overflow); break; + case PROP_WRAP_MODE: + g_value_set_enum (value, pango_layout_get_wrap (self->layout)); + break; + case PROP_XALIGN: g_value_set_float (value, self->xalign); break; @@ -210,6 +215,10 @@ gtk_inscription_set_property (GObject *object, gtk_inscription_set_text_overflow (self, g_value_get_enum (value)); break; + case PROP_WRAP_MODE: + gtk_inscription_set_wrap_mode (self, g_value_get_enum (value)); + break; + case PROP_XALIGN: gtk_inscription_set_xalign (self, g_value_get_float (value)); break; @@ -626,6 +635,21 @@ gtk_inscription_class_init (GtkInscriptionClass *klass) GTK_INSCRIPTION_OVERFLOW_CLIP, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + /** + * GtkInscription:wrap-mode: (attributes org.gtk.Property.get=gtk_inscription_get_wrap_mode org.gtk.Property.set=gtk_inscription_set_wrap_mode) + * + * Controls how the line wrapping is done. + * + * Note that unlike `GtkLabel`, the default here is %PANGO_WRAP_WORD_CHAR. + * + * Since: 4.8 + */ + properties[PROP_WRAP_MODE] = + g_param_spec_enum ("wrap-mode", NULL, NULL, + PANGO_TYPE_WRAP_MODE, + PANGO_WRAP_WORD_CHAR, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + /** * GtkInscription:xalign: (attributes org.gtk.Property.get=gtk_inscription_get_xalign org.gtk.Property.set=gtk_inscription_set_xalign) * @@ -1152,6 +1176,51 @@ gtk_inscription_get_text_overflow (GtkInscription *self) return self->overflow; } +/** + * gtk_inscription_set_wrap_mode: (attributes org.gtk.Method.set_property=wrap-mode) + * @self: a `GtkInscription` + * @wrap_mode: the line wrapping mode + * + * Controls how line wrapping is done. + * + * Since:4.8 + */ +void +gtk_inscription_set_wrap_mode (GtkInscription *self, + PangoWrapMode wrap_mode) +{ + g_return_if_fail (GTK_IS_INSCRIPTION (self)); + + if (pango_layout_get_wrap (self->layout) == wrap_mode) + return; + + pango_layout_set_wrap (self->layout, wrap_mode); + + gtk_widget_queue_draw (GTK_WIDGET (self)); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WRAP_MODE]); +} + +/** + * gtk_inscription_get_wrap_mode: (attributes org.gtk.Method.get_property=wrap-mode) + * @self: a `GtkInscription` + * + * Returns line wrap mode used by the inscription. + * + * See [method@Gtk.Inscription.set_wrap_mode]. + * + * Returns: the line wrap mode + * + * Since:4.8 + */ +PangoWrapMode +gtk_inscription_get_wrap_mode (GtkInscription *self) +{ + g_return_val_if_fail (GTK_IS_INSCRIPTION (self), PANGO_WRAP_WORD_CHAR); + + return pango_layout_get_wrap (self->layout); +} + /** * gtk_inscription_set_markup: (attributes org.gtk.Method.set_property=markup) * @self: a `GtkInscription` diff --git a/gtk/gtkinscription.h b/gtk/gtkinscription.h index af53a7917d..41b2738fd8 100644 --- a/gtk/gtkinscription.h +++ b/gtk/gtkinscription.h @@ -71,6 +71,11 @@ GtkInscriptionOverflow gtk_inscription_get_text_overflow (GtkInscription GDK_AVAILABLE_IN_4_8 void gtk_inscription_set_text_overflow (GtkInscription *self, GtkInscriptionOverflow overflow); +GDK_AVAILABLE_IN_4_8 +PangoWrapMode gtk_inscription_get_wrap_mode (GtkInscription *self); +GDK_AVAILABLE_IN_4_8 +void gtk_inscription_set_wrap_mode (GtkInscription *self, + PangoWrapMode wrap_mode); GDK_AVAILABLE_IN_4_8 guint gtk_inscription_get_min_chars (GtkInscription *self);