pyui Dialog Layout - pytha-3d-cad/pytha-lua-api GitHub Wiki

Dialog layout is based on a regular grid and the widths and heights of controls are inferred automatically.

All functions that create controls take the column position of the control as their first parameter:

...
dialog:create_label_left(1, "Enter Text")
dialog:create_text_box({2,4})

Here, the first call creates a label in the first column, the second call creates a text box that spans all columns from 2 to (and including) 4.

The row position of the controls is inferred automatically: When controls are placed, they are docked from below into the highest accessible row. Imagine this like an upside-down tetris game.

As an example, let XXX, YYY, ZZZ denote controls that have already been created in the dialog when the code above is executed:

Column1 Column 2 Column 3 Column 4

XXX

YYYYYYYYYYYYYYYYYYYYYYYYY

ZZZ

^ New Edit Control ^

^ New Label ^

Note that the label gets to rest on the fourth row because the cells above are occupied and the text box will be placed on the second row, because YYY... prevents it from sliding into the first row.

While this may sound complicated at first, the layouts often come out naturally without much attention to placement.

Modifying the Grid-Placement

In case a control is not placed into its expected position (like the text box in the example above), first check that you create all controls in their natural order. If you already do, then there are two ways to directly influence the grid placement. Before creating the offending control (the text box in our example), we could use

  • dialog:create_empty(2) to create an empty placeholder. In the example, the placeholder would occupy space in column 2, row 3. So the subsequent text box would now be placed in row 4 - next to the label.
  • dialog:create_align({1,4}) to ensure that the subsequent controls from column 1 to and including column 4 now come to rest on the same row.

Adjusting the widths

Dialog layout is automatic, so there is only limited options to adjust the width and height of controls. Sometimes, however, it is desirable that related controls or layout-columns have equal widths (e.g. for the Ok and Cancel buttons). In this case, you can use equalize_column_widths. In some cases, columns are stretched too much. In this case, you can intervene with set_column_stretch.

Updating dialog layout after initialization

In case a control is added after initialization function invoked by run_modal_dialog, it will not appear in the dialog automatically. In this case invoke update_dialog_layout when the new control items are fully configured.

See also:

pyui, Control Gallery

⚠️ **GitHub.com Fallback** ⚠️