mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 05:50:10 +00:00
label: Never measure more than max-width-chars
Even when we have tons of width available, still do the wrapping at max-width-chars. This is what happened in GTK3, too, but it happened automatically because GTK3 did for_size = MIN (for_size, nat_size) and GTK4 does not. So we do this manually in the label now. Fixes the label-sizing.ui reftest.
This commit is contained in:
parent
cad979b734
commit
ba44e7a228
@ -1017,31 +1017,6 @@ gtk_label_get_measuring_layout (GtkLabel *self,
|
||||
return copy;
|
||||
}
|
||||
|
||||
static void
|
||||
get_height_for_width (GtkLabel *self,
|
||||
int width,
|
||||
int *minimum_height,
|
||||
int *natural_height,
|
||||
int *minimum_baseline,
|
||||
int *natural_baseline)
|
||||
{
|
||||
PangoLayout *layout;
|
||||
int text_height, baseline;
|
||||
|
||||
layout = gtk_label_get_measuring_layout (self, NULL, width * PANGO_SCALE);
|
||||
|
||||
pango_layout_get_pixel_size (layout, NULL, &text_height);
|
||||
|
||||
*minimum_height = text_height;
|
||||
*natural_height = text_height;
|
||||
|
||||
baseline = pango_layout_get_baseline (layout) / PANGO_SCALE;
|
||||
*minimum_baseline = baseline;
|
||||
*natural_baseline = baseline;
|
||||
|
||||
g_object_unref (layout);
|
||||
}
|
||||
|
||||
static int
|
||||
get_char_pixels (GtkWidget *self,
|
||||
PangoLayout *layout)
|
||||
@ -1059,6 +1034,44 @@ get_char_pixels (GtkWidget *self,
|
||||
return MAX (char_width, digit_width);
|
||||
}
|
||||
|
||||
static void
|
||||
get_height_for_width (GtkLabel *self,
|
||||
int width,
|
||||
int *minimum_height,
|
||||
int *natural_height,
|
||||
int *minimum_baseline,
|
||||
int *natural_baseline)
|
||||
{
|
||||
PangoLayout *layout;
|
||||
int text_height, baseline;
|
||||
|
||||
width *= PANGO_SCALE;
|
||||
if (self->max_width_chars > -1)
|
||||
{
|
||||
int char_pixels, width_chars;
|
||||
|
||||
layout = gtk_label_get_measuring_layout (self, NULL, -1);
|
||||
char_pixels = get_char_pixels (GTK_WIDGET (self), layout);
|
||||
if (self->width_chars > self->max_width_chars)
|
||||
width_chars = self->width_chars;
|
||||
else
|
||||
width_chars = self->max_width_chars;
|
||||
width = MIN (char_pixels * width_chars, width);
|
||||
}
|
||||
layout = gtk_label_get_measuring_layout (self, NULL, width);
|
||||
|
||||
pango_layout_get_pixel_size (layout, NULL, &text_height);
|
||||
|
||||
*minimum_height = text_height;
|
||||
*natural_height = text_height;
|
||||
|
||||
baseline = pango_layout_get_baseline (layout) / PANGO_SCALE;
|
||||
*minimum_baseline = baseline;
|
||||
*natural_baseline = baseline;
|
||||
|
||||
g_object_unref (layout);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_label_get_preferred_layout_size (GtkLabel *self,
|
||||
PangoRectangle *smallest,
|
||||
|
Loading…
Reference in New Issue
Block a user