GtkFixed only allocates minimum instead of natural size
Steps to reproduce
- Create a label and turn wrapping on, especially noticable with
PANGO_WRAP_CHAR
as wrap mode - Also set the
max-width-chars
property, which should influence the natural size according to https://docs.gtk.org/gtk4/class.Label.html#text-layout - Put it inside a
GtkFixed
.
#include <gtk/gtk.h>
#include <gtk/gtk.h>
static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *fixed;
GtkWidget *label;
label = gtk_label_new("The quick brown fox jumps over the lazy dog");
gtk_label_set_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_wrap_mode(GTK_LABEL(label), PANGO_WRAP_CHAR);
gtk_label_set_max_width_chars(GTK_LABEL(label), 20);
fixed = gtk_fixed_new();
gtk_fixed_put(GTK_FIXED(fixed), label, 20.0, 20.0);
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_window_set_child(GTK_WINDOW(window), GTK_WIDGET(fixed));
gtk_widget_show (window);
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
Current behavior
The label (and any other widgets) are only allocated their minimum instead of their natural size.
Expected outcome
Widgets should be allocated their natural size or it should be possible to choose a behaviour.
Version information
Fedora Silverblue 35
gtk 4.4.1
Additional information
From a quick look at the code, it looks like the GtkFixedLayout
s allocation code does not take the widgets natural preferred size into account at all.
https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gtk/gtkfixedlayout.c#L320
Is this intended?
See also https://gitlab.freedesktop.org/pipewire/helvum/-/merge_requests/27#note_1219716 for an actual example where this is a problem.