Adjustable tables

Adjustable tables.

Tables' default width gets computed based on the width of the tables' items. An optional table setting enables adjustable tables. Adjustable tables allow their width to expand, and their individual columns' relative width to be manually adjusted using the mouse pointer.

table2.C is a modified version of the example from this chapter that enables adjustable table features:


x::w::new_tablelayoutmanager's adjustable() enables adjustable table columns and assigns the table's label for saving the adjustable table column widths and restoring them the next time the table window gets opened. Moving the mouse pointer on top of a dividing border in the header row changes the pointer to a bi-directional horizontal arrow. Pressing pointer button #1 drags the border under the pointer horizontally and adjusts the relative widths of the columns on both sides of the border. Pressing pointer button #1 while holding down the Alt key restores all columns to their initial unadjusted width.

Setting table_width and maximum_table_width specifies the initial and the maximum width of the table, in millimeters. table2.C's window's width is expandable, this adjusts the size of its table until its table reaches its maximum width. Calling unlimited_table_width() removes the maximum limit for the table's width, completely.


Other widgets in the same window affect the table's actual and maximum widths. The main window's grid layout manager (or the table's container's layout manager) has to calculate the other window elements' metrics. Unless the other widgets in the window can be sized accordingly, the table may not end up being sizable to its maximum width.

Adjusting table column widths using the keyboard

Each border between the columns in an adjustable table is draggable directly, by the pointer. This adjusts the relative sizes of the two columns on either sides of the border. The column sizes are also adjustable using the keyboard.

When the keyboard focus is on the table's list the Tab key highlights each border in the header row in turn the Tab key moves the keyboard focus out of the talbe list, as with other focusable widgets (Shift-Tab highlights the previous border in this mode). Cursor-Left and Cursor-Right move the highlighted border by a moderate amount, and by one precise pixel together with the Ctrl key.

Column width adjusting mode gets terminated immediately by the Esc key, or by repeatedly tabbing until the keyboard focus leaves the table list, or the header row. Pressing Esc while holding down the Alt key goes one step further and restores all columns to their initial unadjusted width.

Preserving table columns' widths

It's natural to expect that reopening an application opens the table and its columns using their original size. This behavior is enabled by assigning a unique label to each table in the window, and passing this label to adjustable(). table2.C gives an example of enabling adjustable table columns:

x::w::new_tablelayoutmanager ntlm{
                    // ...


     (const x::w::focusable_container &)
         // ...
     }, ntlm);

A unique identifier must get assigned to each table in a window that has adjustable columns. table2.C calls its sole table, unimaginatively, main_table.


Calling adjustable() without any parameters enables adjustable table column widths, but they do not get preserved and each time the window gets opened the column widths get reset to their default values.

ntlm.adjustable("main_table", false);

Passing a false as the optional 2nd parameter enables adjustable column widths, but resets all column widths to their default values. They'll still get preserved and the next time the window gets opened the column widths will get restored to what they were, once more.