GeanyWrapLabel: fix rendering issues
GtkLabel may re-create its PangoLayout between calls leading to the final layout used for rendering not to be set up with the appropriate values for our sizing. Then, re-set up the layout each time we have to deal with it and straight before GtkLabel renders it.
This commit is contained in:
parent
6c15dd4724
commit
c84d486472
@ -51,6 +51,7 @@ struct _GeanyWrapLabel
|
||||
|
||||
static void geany_wrap_label_size_request (GtkWidget *widget, GtkRequisition *req);
|
||||
static void geany_wrap_label_size_allocate (GtkWidget *widget, GtkAllocation *alloc);
|
||||
static gboolean geany_wrap_label_expose (GtkWidget *widget, GdkEventExpose *event);
|
||||
static void geany_wrap_label_set_wrap_width (GtkWidget *widget, gint width);
|
||||
static void geany_wrap_label_label_notify (GObject *object, GParamSpec *pspec, gpointer data);
|
||||
|
||||
@ -63,6 +64,7 @@ static void geany_wrap_label_class_init(GeanyWrapLabelClass *klass)
|
||||
|
||||
widget_class->size_request = geany_wrap_label_size_request;
|
||||
widget_class->size_allocate = geany_wrap_label_size_allocate;
|
||||
widget_class->expose_event = geany_wrap_label_expose;
|
||||
|
||||
g_type_class_add_private(klass, sizeof (GeanyWrapLabelPrivate));
|
||||
}
|
||||
@ -77,7 +79,6 @@ static void geany_wrap_label_init(GeanyWrapLabel *self)
|
||||
self->priv->wrap_height = 0;
|
||||
|
||||
g_signal_connect(self, "notify::label", G_CALLBACK(geany_wrap_label_label_notify), NULL);
|
||||
pango_layout_set_wrap(gtk_label_get_layout(GTK_LABEL(self)), PANGO_WRAP_WORD_CHAR);
|
||||
gtk_misc_set_alignment(GTK_MISC(self), 0.0, 0.0);
|
||||
}
|
||||
|
||||
@ -98,6 +99,7 @@ static void geany_wrap_label_set_wrap_width(GtkWidget *widget, gint width)
|
||||
* or not we've changed the width.
|
||||
*/
|
||||
pango_layout_set_width(layout, width * PANGO_SCALE);
|
||||
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
|
||||
pango_layout_get_pixel_size(layout, NULL, &self->priv->wrap_height);
|
||||
|
||||
if (self->priv->wrap_width != width)
|
||||
@ -117,6 +119,19 @@ static void geany_wrap_label_label_notify(GObject *object, GParamSpec *pspec, gp
|
||||
}
|
||||
|
||||
|
||||
/* makes sure the layout is setup for rendering and chains to parent renderer */
|
||||
static gboolean geany_wrap_label_expose(GtkWidget *widget, GdkEventExpose *event)
|
||||
{
|
||||
GeanyWrapLabel *self = GEANY_WRAP_LABEL(widget);
|
||||
PangoLayout *layout = gtk_label_get_layout(GTK_LABEL(widget));
|
||||
|
||||
pango_layout_set_width(layout, self->priv->wrap_width * PANGO_SCALE);
|
||||
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
|
||||
|
||||
return (* GTK_WIDGET_CLASS(geany_wrap_label_parent_class)->expose_event)(widget, event);
|
||||
}
|
||||
|
||||
|
||||
/* Forces the height to be the size necessary for the Pango layout, while allowing the
|
||||
* width to be flexible. */
|
||||
static void geany_wrap_label_size_request(GtkWidget *widget, GtkRequisition *req)
|
||||
|
Loading…
x
Reference in New Issue
Block a user