GtkFlowBox aligns incorrectly with GTK_ALIGN_END and min/max_children_per_line
Steps to reproduce
- run the example
Current behavior
If the number of children in the last line equal to max_children_per_line, it will be displayed in the wrong place.
Expected outcome
It should align with the previous line.
Version information
Fedora 39, gtk4 4.12.5
Additional information
(flowboxbug:34403): Gtk-WARNING **: 03:43:35.681: gtk_widget_size_allocate(): attempt to allocate GtkButton button 0x146e5c0 with width -6 and height 34
(flowboxbug:34403): Gtk-WARNING **: 03:43:35.681: gtk_widget_size_allocate(): attempt to allocate GtkLabel label 0x1494cd0 with width -34 and height -10
(flowboxbug:34403): Gtk-WARNING **: 03:43:35.681: gtk_widget_size_allocate(): attempt to allocate GtkButton button 0x14a7780 with width -6 and height 34
(flowboxbug:34403): Gtk-WARNING **: 03:43:35.681: gtk_widget_size_allocate(): attempt to allocate GtkLabel label 0x14a87e0 with width -34 and height -10
(flowboxbug:34403): Gtk-WARNING **: 03:43:35.681: gtk_widget_size_allocate(): attempt to allocate GtkButton button 0x1493a80 with width -6 and height 34
(flowboxbug:34403): Gtk-WARNING **: 03:43:35.681: gtk_widget_size_allocate(): attempt to allocate GtkLabel label 0x14aa4f0 with width -34 and height -10
#include <gtk/gtk.h>
static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *box;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_halign (box, GTK_ALIGN_START);
for(int i = 0; i < 6; i++) {
char buf[32];
sprintf (buf, "with %d buttons", i + 1);
GtkWidget *label = gtk_label_new (buf);
GtkWidget *flowbox = gtk_flow_box_new ();
gtk_orientable_set_orientation (GTK_ORIENTABLE (flowbox), GTK_ORIENTATION_HORIZONTAL);
gtk_flow_box_set_min_children_per_line (GTK_FLOW_BOX (flowbox), 2);
gtk_flow_box_set_max_children_per_line (GTK_FLOW_BOX (flowbox), 2);
gtk_widget_set_halign (flowbox, GTK_ALIGN_END);
for(int j = 0; j < i + 1; j++) {
sprintf (buf, "%d", j + 1);
gtk_flow_box_append (GTK_FLOW_BOX (flowbox), gtk_button_new_with_label (buf));
}
gtk_box_append (GTK_BOX (box), label);
gtk_box_append (GTK_BOX (box), flowbox);
}
gtk_window_set_child (GTK_WINDOW (window), box);
gtk_window_present (GTK_WINDOW (window));
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
Edited by Gergo Koteles