diff -r 64ded9f6a6c6 -r 6606616eca9f ui/motif/container.c --- a/ui/motif/container.c Tue Feb 25 21:11:00 2025 +0100 +++ b/ui/motif/container.c Sat Apr 05 16:46:11 2025 +0200 @@ -39,20 +39,7 @@ #include "Grid.h" -UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args) { - Arg xargs[64]; - int n = 0; - - UiContainerPrivate *ctn = ui_obj_container(obj); - UI_APPLY_LAYOUT(ctn->layout, args); - - Widget parent = ctn->prepare(ctn, xargs, &n); - Widget widget = create_widget(obj, args, userdata, parent, xargs, n); - XtManageChild(widget); - ctn->add(ctn, widget); - - return widget; -} + /* ---------------------------- Box Container ---------------------------- */ @@ -156,13 +143,20 @@ Widget grid = XtCreateManagedWidget(args.name ? args.name : "gridcontainer", gridClass, parent, xargs, n); ctn->add(ctn, grid); - UiContainerX *container = ui_grid_container(obj, grid); + UiContainerX *container = ui_grid_container(obj, grid, args.def_hexpand, args.def_vexpand, args.def_hfill, args.def_vfill); uic_object_push_container(obj, container); return grid; } -UiContainerX* ui_grid_container(UiObject *obj, Widget grid) { +UiContainerX* ui_grid_container( + UiObject *obj, + Widget grid, + UiBool def_hexpand, + UiBool def_vexpand, + UiBool def_hfill, + UiBool def_vfill) +{ UiGridContainer *ctn = ui_malloc(obj->ctx, sizeof(UiGridContainer)); memset(ctn, 0, sizeof(UiBoxContainer)); ctn->container.prepare = ui_grid_container_prepare; @@ -170,6 +164,10 @@ ctn->container.widget = grid; ctn->x = 0; ctn->y = 0; + ctn->def_hexpand = def_hexpand; + ctn->def_vexpand = def_vexpand; + ctn->def_hfill = def_hfill; + ctn->def_vfill = def_vfill; return (UiContainerX*)ctn; } @@ -190,23 +188,54 @@ XtSetArg(args[a], gridRowspan, ctn->layout.rowspan); a++; } - if(grid->container.layout.fill == UI_ON) { - grid->container.layout.hfill = TRUE; - grid->container.layout.vfill = TRUE; - grid->container.layout.hexpand = TRUE; - grid->container.layout.vexpand = TRUE; + int hexpand = FALSE; + int vexpand = FALSE; + int hfill = FALSE; + int vfill = FALSE; + if(!ctn->layout.override_defaults) { + if(grid->def_hexpand) { + hexpand = TRUE; + hfill = TRUE; + } else if(grid->def_hfill) { + hfill = TRUE; + } + if(grid->def_vexpand) { + vexpand = TRUE; + vfill = TRUE; + } else if(grid->def_vfill) { + vfill = TRUE; + } } - if(grid->container.layout.hfill) { + if(ctn->layout.hexpand) { + hexpand = TRUE; + hfill = TRUE; + } else if(ctn->layout.hfill) { + hfill = TRUE; + } + if(ctn->layout.vexpand) { + vexpand = TRUE; + vfill = TRUE; + } else if(ctn->layout.vfill) { + vfill = TRUE; + } + if(ctn->layout.fill == UI_ON) { + hexpand = TRUE; + vexpand = TRUE; + hfill = TRUE; + vfill = TRUE; + } + + if(hfill) { XtSetArg(args[a], gridHFill, TRUE); a++; } - if(grid->container.layout.vfill) { + if(vfill) { XtSetArg(args[a], gridVFill, TRUE); a++; } - if(grid->container.layout.hexpand) { + if(hexpand) { XtSetArg(args[a], gridHExpand, TRUE); a++; } - if(grid->container.layout.vexpand) { + if(vexpand) { XtSetArg(args[a], gridVExpand, TRUE); a++; } @@ -557,7 +586,43 @@ ui_reset_layout(ctn->layout); } +/* -------------------- ScrolledWindow -------------------- */ +Widget ui_scrolledwindow_prepare(UiContainerPrivate *ctn, Arg *args, int *n) { + return ctn->widget; +} + +void ui_scrolledwindow_add(UiContainerPrivate *ctn, Widget widget) { + +} + +static UiContainerX* ui_scrolledwindow_container(UiObject *obj, Widget scrolledwindow) { + UiContainerPrivate *ctn = ui_malloc(obj->ctx, sizeof(UiContainerPrivate)); + memset(ctn, 0, sizeof(UiContainerPrivate)); + ctn->prepare = ui_scrolledwindow_prepare; + ctn->add = ui_scrolledwindow_add; + ctn->widget = scrolledwindow; + return (UiContainerX*)ctn; +} + +UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) { + UiContainerPrivate *ctn = ui_obj_container(obj); + UI_APPLY_LAYOUT(ctn->layout, args); + + Arg xargs[16]; + int n = 0; + + XtSetArg(xargs[n], XmNscrollingPolicy, XmAUTOMATIC); n++; + + Widget parent = ctn->prepare(ctn, xargs, &n); + Widget scrolledwindow = XmCreateScrolledWindow(parent, "scrolledwindow", xargs, n); + ctn->add(ctn, scrolledwindow); + + UiContainerX *container = ui_scrolledwindow_container(obj, scrolledwindow); + uic_object_push_container(obj, container); + + return scrolledwindow; +} /* -------------------- Container Helper Functions -------------------- */