Thu, 15 Feb 2024 21:12:54 +0100
implement grid colspan/rowspan (GTK)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/gtk/container.c | file | annotate | diff | comparison | revisions | |
ui/gtk/container.h | file | annotate | diff | comparison | revisions |
--- 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); }
--- 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;