GtkFlowBox has alignment issues with HEIGHT_FOR_WIDTH widgets
Given a flow box containing height for width widgets that is limited by minChildren == maxChildren, if the widget size is not decidable by the number of children a lot of "Allocation height too small." criticals will be printed.
This seems similar to #6455, but the attached fix (!6925) doesn't solve it.
A reproducer looks like this. Here the allocated height deviates quite a bit more than in my actual app (where it's only off by one).
#include <gtk/gtk.h>
#define T_TYPE_HFW (t_hfw_get_type())
G_DECLARE_FINAL_TYPE (THFW, t_hfw, T, HFW, GtkWidget)
struct _THFW {
GtkWidget parent_instance;
};
G_DEFINE_FINAL_TYPE (THFW, t_hfw, GTK_TYPE_WIDGET)
static GtkSizeRequestMode t_hfw_get_request_mode(GtkWidget*) {
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
static void t_hfw_measure(GtkWidget*, GtkOrientation orientation, gint for_size, gint* min, gint* nat, G_GNUC_UNUSED gint* min_baseline, G_GNUC_UNUSED gint* nat_baseline) {
if (orientation == GTK_ORIENTATION_VERTICAL) {
gint size = (for_size * 3) / 4;
*min = size;
*nat = size;
} else if (orientation == GTK_ORIENTATION_HORIZONTAL) {
*min = *nat = 40;
}
}
static void t_hfw_class_init(THFWClass* class) {
GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(class);
widget_class->get_request_mode = t_hfw_get_request_mode;
widget_class->measure = t_hfw_measure;
}
static void t_hfw_init(THFW*) {}
GtkWidget* create_item(void) {
return g_object_new(T_TYPE_HFW, NULL);
}
void activate(GtkApplication* app, gpointer) {
GtkWidget* window = gtk_application_window_new(app);
GtkWidget* box = gtk_flow_box_new();
gtk_flow_box_set_homogeneous(GTK_FLOW_BOX(box), TRUE);
gtk_flow_box_set_min_children_per_line(GTK_FLOW_BOX(box), 2);
gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(box), 2);
for (guint i = 0; i < 8; i++)
gtk_flow_box_append(GTK_FLOW_BOX(box), create_item());
gtk_window_set_child(GTK_WINDOW(window), box);
gtk_window_present(GTK_WINDOW(window));
}
int main(int argc, char** argv) {
g_autoptr(GtkApplication) app = gtk_application_new("arpa.sp1rit.gtk.floxboxbug", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
return g_application_run(G_APPLICATION(app), argc, argv);
}
(note that the criticals are only printed in debug builds)