Tue, 31 Dec 2024 17:57:43 +0100
implement Grid col/row spacing (Motif)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/motif/Grid.c | file | annotate | diff | comparison | revisions | |
ui/motif/Grid.h | file | annotate | diff | comparison | revisions | |
ui/motif/container.c | file | annotate | diff | comparison | revisions |
--- a/application/main.c Tue Dec 31 17:29:58 2024 +0100 +++ b/application/main.c Tue Dec 31 17:57:43 2024 +0100 @@ -595,7 +595,7 @@ ui_button(obj, .label = "Line 4 B4", .hexpand = TRUE, .hfill = TRUE); ui_button(obj, .label = "Line EOL"); ui_newline(obj); - ui_button(obj, .colspan = 5, .hfill = TRUE); + ui_button(obj, .colspan = 5, .hfill = TRUE, .label = "EOL"); } ui_show(obj);
--- a/ui/motif/Grid.c Tue Dec 31 17:29:58 2024 +0100 +++ b/ui/motif/Grid.c Tue Dec 31 17:57:43 2024 +0100 @@ -52,6 +52,39 @@ <EnterWindow>: getfocus()\n\ <LeaveWindow>: loosefocus()\n"; +static XtResource resources[] = +{ + { + gridColumnSpacing, + gridColumnSpacing, + XmRDimension, + sizeof (Dimension), + XtOffsetOf( GridRec, + mywidget.columnspacing), + XmRImmediate, + (XtPointer) 0 + }, + { + gridRowSpacing, + gridRowSpacing, + XmRDimension, + sizeof (Dimension), + XtOffsetOf( GridRec, + mywidget.rowspacing), + XmRImmediate, + (XtPointer) 0 + }, + { + gridMargin, + gridMargin, + XmRDimension, + sizeof (Dimension), + XtOffsetOf( GridRec, + mywidget.margin), + XmRImmediate, + (XtPointer) 0 + } +}; ///* static XtResource constraints[] = @@ -179,7 +212,6 @@ }; //*/ -//static XtResource constraints[] = {}; GridClassRec gridClassRec = { // Core Class @@ -187,17 +219,17 @@ //(WidgetClass)&constraintClassRec, // superclass (WidgetClass)&xmManagerClassRec, "Grid", // class_name - sizeof(GridRec), // widget_size - grid_class_initialize, // class_initialize + sizeof(GridRec), // widget_size + grid_class_initialize, // class_initialize NULL, // class_part_initialize FALSE, // class_inited - (XtInitProc)grid_initialize, // initialize + (XtInitProc)grid_initialize, // initialize NULL, // initialize_hook - grid_realize, // realize - actionslist, // actions - XtNumber(actionslist), // num_actions - NULL, // resources - 0, // num_resources + grid_realize, // realize + actionslist, // actions + XtNumber(actionslist), // num_actions + resources, // resources + XtNumber(resources), // num_resources NULLQUARK, // xrm_class True, // compress_motion True, // compress_exposure @@ -465,7 +497,7 @@ span_max = 50000; // not sure if this is unreasonable low or high } - + // calc required size for(int i=0;i<ncols;i++) { if(cols[i].expand) { num_cols_expanding++; @@ -480,6 +512,10 @@ } if(req_width > 0 && req_height > 0) { + // add col/row spacing + req_width += (ncols-1)*w->mywidget.columnspacing; + req_height += (nrows-1)*w->mywidget.rowspacing; + Widget parent = w->core.parent; Dimension rwidth = req_width; Dimension rheight = req_height; @@ -509,6 +545,7 @@ } + // how much space can we add to each expanding col/row int hexpand = 0; int width_diff = (int)w->core.width - req_width; int hexpand2 = 0; @@ -522,7 +559,7 @@ if(cols[i].expand) { cols[i].size += hexpand + hexpand2; } - x += cols[i].size; + x += cols[i].size + w->mywidget.columnspacing; hexpand2 = 0; } @@ -540,7 +577,7 @@ if(rows[i].expand) { rows[i].size += vexpand + vexpand2; } - y += rows[i].size; + y += rows[i].size += w->mywidget.rowspacing; vexpand2 = 0; } @@ -559,12 +596,12 @@ Dimension cwidth = 0; for(int j=0;j<constraints->grid.colspan;j++) { if(constraints->grid.x+j < ncols) { - cwidth += cols[constraints->grid.x+j].size; + cwidth += cols[constraints->grid.x+j].size + (j > 0 ? w->mywidget.columnspacing : 0); } } width = cwidth; } else { - width = c.size; + width = c.size - w->mywidget.columnspacing; } } if(constraints->grid.vfill) { @@ -572,12 +609,12 @@ Dimension cheight = 0; for(int j=0;j<constraints->grid.rowspan;j++) { if(constraints->grid.y+j < nrows) { - cheight += rows[constraints->grid.y+j].size; + cheight += rows[constraints->grid.y+j].size + (j > 0 ? w->mywidget.rowspacing : 0); } } height = cheight; } else { - height = r.size; + height = r.size - w->mywidget.rowspacing; } }
--- a/ui/motif/Grid.h Tue Dec 31 17:29:58 2024 +0100 +++ b/ui/motif/Grid.h Tue Dec 31 17:57:43 2024 +0100 @@ -40,6 +40,12 @@ extern "C" { #endif +// resources +#define gridColumnSpacing "gridColumnSpacing" +#define gridRowSpacing "gridRowSpacing" +#define gridMargin "gridMargin" + +// constraints #define gridColumn "gridColumn" #define gridRow "gridRow" #define gridColspan "gridColspan" @@ -80,6 +86,9 @@ int margin_bottom; int max_col; int max_row; + Dimension columnspacing; + Dimension rowspacing; + Dimension margin; Boolean sizerequest; } GridPart;
--- a/ui/motif/container.c Tue Dec 31 17:29:58 2024 +0100 +++ b/ui/motif/container.c Tue Dec 31 17:57:43 2024 +0100 @@ -132,6 +132,9 @@ UI_APPLY_LAYOUT(ctn->layout, args); Widget parent = ctn->prepare(ctn, xargs, &n); + XtSetArg(xargs[n], gridMargin, args.margin); n++; + XtSetArg(xargs[n], gridColumnSpacing, args.columnspacing); n++; + XtSetArg(xargs[n], gridRowSpacing, args.rowspacing); n++; Widget grid = XtCreateManagedWidget(args.name ? args.name : "gridcontainer", gridClass, parent, xargs, n); ctn->add(ctn, grid);