commit fc23a23235265e1be44aaef99f0de5fa1c2fd6dc from: xavier date: Fri Jul 31 03:14:55 2026 UTC Implemented grid sticky and fixed a small acalc bug commit - ce5cff68317a7e6bcdb306fb3e3b90522fa4aa17 commit + fc23a23235265e1be44aaef99f0de5fa1c2fd6dc blob - 00cb7edb8b62653cdc08c56db41e34eb1717f758 blob + fbb8bb7084e2803bef965e8d4a7caa3015a23f38 --- aui.h +++ aui.h @@ -50,6 +50,12 @@ struct aui_gridpar { unsigned int row; unsigned int columnspan; unsigned int rowspan; +#define AUI_STICKY_NONE 0 +#define AUI_STICKY_N 1 +#define AUI_STICKY_E 2 +#define AUI_STICKY_S 4 +#define AUI_STICKY_W 8 + unsigned char sticky; }; struct aui_gridconfigure { blob - aa382cf73f012f687df1b1dd50c3bb81e0bf7a90 blob + 8ba115519e8858ea39f30c5e4efc9db0e44e8070 --- examples/acalc/acalc.c +++ examples/acalc/acalc.c @@ -60,27 +60,29 @@ static const struct aui_color theme[] = { { 255, 255, 255, 255 }, }; +static const unsigned char s = AUI_STICKY_N | AUI_STICKY_S | AUI_STICKY_E | AUI_STICKY_W; + static struct binfo binfo[] = { - { CLASS_CLR, { .text = "C", .foreground = theme[0] }, { .row = 0, .columnspan = 3 } }, - { CLASS_DIV, { .text = "/", .foreground = theme[0] }, { .row = 0, .column = 3 } }, + { CLASS_CLR, { .text = "C", .foreground = theme[0] }, { .row = 0, .columnspan = 3, .sticky = s } }, + { CLASS_DIV, { .text = "/", .foreground = theme[0] }, { .row = 0, .column = 3, .sticky = s } }, - { CLASS_DGT, { .text = "7", .foreground = theme[0] }, { .row = 1, .column = 0 } }, - { CLASS_DGT, { .text = "8", .foreground = theme[0] }, { .row = 1, .column = 1 } }, - { CLASS_DGT, { .text = "9", .foreground = theme[0] }, { .row = 1, .column = 2 } }, - { CLASS_MUL, { .text = "*", .foreground = theme[0] }, { .row = 1, .column = 3 } }, + { CLASS_DGT, { .text = "7", .foreground = theme[0] }, { .row = 1, .column = 0, .sticky = s } }, + { CLASS_DGT, { .text = "8", .foreground = theme[0] }, { .row = 1, .column = 1, .sticky = s } }, + { CLASS_DGT, { .text = "9", .foreground = theme[0] }, { .row = 1, .column = 2, .sticky = s } }, + { CLASS_MUL, { .text = "*", .foreground = theme[0] }, { .row = 1, .column = 3, .sticky = s } }, - { CLASS_DGT, { .text = "4", .foreground = theme[0] }, { .row = 2, .column = 0 } }, - { CLASS_DGT, { .text = "5", .foreground = theme[0] }, { .row = 2, .column = 1 } }, - { CLASS_DGT, { .text = "6", .foreground = theme[0] }, { .row = 2, .column = 2 } }, - { CLASS_SUB, { .text = "-", .foreground = theme[0] }, { .row = 2, .column = 3 } }, + { CLASS_DGT, { .text = "4", .foreground = theme[0] }, { .row = 2, .column = 0, .sticky = s } }, + { CLASS_DGT, { .text = "5", .foreground = theme[0] }, { .row = 2, .column = 1, .sticky = s } }, + { CLASS_DGT, { .text = "6", .foreground = theme[0] }, { .row = 2, .column = 2, .sticky = s } }, + { CLASS_SUB, { .text = "-", .foreground = theme[0] }, { .row = 2, .column = 3, .sticky = s } }, - { CLASS_DGT, { .text = "1", .foreground = theme[0] }, { .row = 3, .column = 0 } }, - { CLASS_DGT, { .text = "2", .foreground = theme[0] }, { .row = 3, .column = 1 } }, - { CLASS_DGT, { .text = "3", .foreground = theme[0] }, { .row = 3, .column = 2 } }, - { CLASS_ADD, { .text = "+", .foreground = theme[0] }, { .row = 3, .column = 3 } }, + { CLASS_DGT, { .text = "1", .foreground = theme[0] }, { .row = 3, .column = 0, .sticky = s } }, + { CLASS_DGT, { .text = "2", .foreground = theme[0] }, { .row = 3, .column = 1, .sticky = s } }, + { CLASS_DGT, { .text = "3", .foreground = theme[0] }, { .row = 3, .column = 2, .sticky = s } }, + { CLASS_ADD, { .text = "+", .foreground = theme[0] }, { .row = 3, .column = 3, .sticky = s } }, - { CLASS_DGT, { .text = "0", .foreground = theme[0] }, { .row = 4, .columnspan = 3 } }, - { CLASS_EQU, { .text = "=", .foreground = theme[0] }, { .row = 4, .column = 3 } }, + { CLASS_DGT, { .text = "0", .foreground = theme[0] }, { .row = 4, .columnspan = 3, .sticky = s } }, + { CLASS_EQU, { .text = "=", .foreground = theme[0] }, { .row = 4, .column = 3, .sticky = s } }, }; void @@ -300,7 +302,7 @@ main() aui_grid(AUI_WIDGET(btn), &binfo[i].par); } - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 4; i++) { struct aui_gridconfigure config = { .weight = 1 }; aui_columnconfigure(AUI_WIDGET(buttons_frame), i, &config); } blob - b8f5646351c9899a8c49e7317a9657dce12e57eb blob + 6e27a689d7b8b7658aa07e81d7bc962f14ced7f2 --- layout.c +++ layout.c @@ -236,8 +236,9 @@ grid(struct aui_widget *widget) unsigned int cspan = child->gridpar.columnspan; unsigned int rspan = child->gridpar.rowspan; unsigned int column = child->gridpar.column; + unsigned char sticky = child->gridpar.sticky; unsigned int row = child->gridpar.row; - struct aui_geometry geom; + struct aui_geometry geom, dims; geom.width = csize[column]; geom.height = rsize[row]; @@ -256,7 +257,23 @@ grid(struct aui_widget *widget) geom.x = widget->geom.x + cpos[column + cspan - 1] - geom.width; geom.y = widget->geom.y + rpos[row + rspan - 1] - geom.height; - child->ops->set_geometry(child, &geom); + dims = child->ops->get_min_size(child); + dims.x = geom.x; + dims.y = geom.y; + + if (dims.width > geom.width || ((sticky & AUI_STICKY_E) && (sticky & AUI_STICKY_W))) + dims.width = geom.width; + + if (dims.height > geom.height || ((sticky & AUI_STICKY_N) && (sticky & AUI_STICKY_S))) + dims.height = geom.height; + + if (sticky & AUI_STICKY_S) + dims.y = geom.y + geom.height - dims.height; + + if (sticky & AUI_STICKY_E) + dims.x = geom.x + geom.width - dims.width; + + child->ops->set_geometry(child, &dims); } TAILQ_FOREACH(child, &widget->queue, entries) {