Search code examples
c++clinuxdrawing

Horizontally-Drawn RowColumn Class for Motif Library (C)?


I am using the Motif Library for my job. If anybody is not familiar with this library, you can find a list of files here https://packages.ubuntu.com/xenial/amd64/libmotif-dev/filelist, as well as another question here Motif 1.2 X11 on using RowColumn widget inside a ScrolledWindow.

My issue is that the xmRowColumnWidgetClass is drawn vertically, which means it draws it column by column (starts at top left moving to bottom left, then moves right to the next column, etc.)

Doing something like this:

Widget parentWidget, rowColumn;

XtAppContext app;

parentWidget = XtVaAppInitialize(&app, "rowColumn", NULL, 0,
&argc, argv, NULL, NULL);

and then like this:

rowColumn = XtVaCreateManagedWidget("rowcolumn",
            xmRowColumnWidgetClass,
            parentWidget,
            XmNnumColumns, 3,
            XmNpacking, XmPACK_COLUMN,
            XmNspacing, 6,
            NULL);

(void) XtVaCreateManagedWidget("button 1",
xmPushButtonWidgetClass, rowColumn, NULL);

(void) XtVaCreateManagedWidget("button 2",
xmPushButtonWidgetClass, rowColumn, NULL);

(void) XtVaCreateManagedWidget("button 3",
xmPushButtonWidgetClass, rowColumn, NULL);
        
(void) XtVaCreateManagedWidget("button 4",
xmPushButtonWidgetClass, rowColumn, NULL);

(void) XtVaCreateManagedWidget("button 5",
xmPushButtonWidgetClass, rowColumn, NULL);

(void) XtVaCreateManagedWidget("button 6",
xmPushButtonWidgetClass, rowColumn, NULL);

(void) XtVaCreateManagedWidget("button 7",
xmPushButtonWidgetClass, rowColumn, NULL);

(void) XtVaCreateManagedWidget("button 8",
xmPushButtonWidgetClass, rowColumn, NULL);

(void) XtVaCreateManagedWidget("button 9",
xmPushButtonWidgetClass, rowColumn, NULL);

So the above code would create the Widgets like this:

button 1    button 4    button 7

button 2    button 5    button 8

button 3    button 6    button 9

My problem is that I want certain ones to be side-by-side rather than above-below.

And suppose as a way around this I specify an order like this: button 1, button 4, button 7, button 2, button 5, button 8, button 3, button 6, button 9. That would look like this:

button 1    button 2    button 3

button 4    button 5    button 6

button 7    button 8    button 9

However, if I wanted to remove a button or add a new button, this messes everything up. Let's say I remove the "button 4" from the above example, so the order is like this: button 1, button 7, button 2, button 5, button 8, button 3, button 6, button 9. That would look like this:

button 1    button 5    button 6

button 7    button 8    button 9

button 2    button 3

As you can see, practically nothing that should be side-by-side next to each other is next to each other now.

This problem also happens when you add a new button: Let's say we want to add a button 10 to the end: button 1, button 4, button 7, button 2, button 5, button 8, button 3, button 6, button 9, button 10. This would look like this:

button 1    button 5    button 9

button 4    button 8    button 10

button 7    button 3

button 2    button 6

This by far looks the worst, since adding a new button increases the normal of rows to 4 instead of 3, which changes the entire layout.


To anybody familiar with this library:

How do I create a xmRowColumnWidgetClass instance that draws horizontally (row-by-row) instead of vertically? (column-by-column)

Or, how can I extend this library and possibly make a xmHorRowColumnWidgetClass that does what I want?


Another group of examples of this library:
https://github.com/spartrekus/Motif-C-Examples
https://github.com/spartrekus/Motif-C-Examples/blob/master/rowcol.c


Solution

  • To make the xmRowColumnWidgetClass instance draw horizontally, add XmNorientation, XmHORIZONTAL to the code:

    rowColumn = XtVaCreateManagedWidget("rowcolumn",
                xmRowColumnWidgetClass,
                parentWidget,
                XmNnumColumns, 3,
                XmNorientation, XmHORIZONTAL,
                XmNpacking, XmPACK_COLUMN,
                XmNspacing, 6,
                NULL);
    

    This makes it draw row-by-row rather than column-by-column.

    XmNnumColumns now refers to the number of rows rather than columns for some reason, but this is a separate issue and so the above code does indeed answer my original question.