# HG changeset patch # User Olaf Wintermann # Date 1708027974 -3600 # Node ID eebb0626d02051559375f8acaab06bffb5d7433a # Parent 8cce275d2847b18b682a644eb22c70b752a3d395 implement grid colspan/rowspan (GTK) diff -r 8cce275d2847 -r eebb0626d020 application/main.c --- a/application/main.c Thu Feb 15 21:04:21 2024 +0100 +++ b/application/main.c Thu Feb 15 21:12:54 2024 +0100 @@ -71,6 +71,14 @@ ui_togglebutton(obj, .label = "Toggle"); ui_checkbox(obj, .label = "Checkbox"); + ui_grid(obj, .fill = 1) { + ui_button(obj, .label = "cell1", .hexpand = TRUE); + ui_button(obj, .label = "cell2"); + ui_newline(obj); + ui_button(obj, .label = "cell_colspan2", .colspan = 2); + + } + ui_show(obj); } diff -r 8cce275d2847 -r eebb0626d020 ui/gtk/container.c --- a/ui/gtk/container.c Thu Feb 15 21:04:21 2024 +0100 +++ b/ui/gtk/container.c Thu Feb 15 21:12:54 2024 +0100 @@ -141,10 +141,11 @@ gtk_widget_set_vexpand(widget, TRUE); } - int gwidth = ct->layout.gridwidth > 0 ? ct->layout.gridwidth : 1; + int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1; + int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1; - gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, gwidth, 1); - grid->x += gwidth; + gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, colspan, rowspan); + grid->x += colspan; ui_reset_layout(ct->layout); ct->current = widget; @@ -171,6 +172,10 @@ GtkAttachOptions xoptions = hexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL; GtkAttachOptions yoptions = vexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL; + int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1; + int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1; + // TODO: use colspan/rowspan + gtk_table_attach(GTK_TABLE(ct->widget), widget, grid->x, grid->x+1, grid->y, grid->y+1, xoptions, yoptions, 0, 0); grid->x++; int nw = grid->x > grid->width ? grid->x : grid->width; @@ -367,11 +372,6 @@ ct->layout.vexpand = expand; } -void ui_layout_gridwidth(UiObject *obj, int width) { - UiContainer *ct = uic_get_current_container(obj); - ct->layout.gridwidth = width; -} - void ui_layout_colspan(UiObject* obj, int cols) { UiContainer* ct = uic_get_current_container(obj); ct->layout.colspan = cols; diff -r 8cce275d2847 -r eebb0626d020 ui/gtk/container.h --- a/ui/gtk/container.h Thu Feb 15 21:04:21 2024 +0100 +++ b/ui/gtk/container.h Thu Feb 15 21:12:54 2024 +0100 @@ -61,7 +61,6 @@ UiBool hexpand; UiBool vexpand; int width; - int gridwidth; int colspan; int rowspan; };