LuaAPI/types/widget
Contents
- 1 Widget Attributes
- 1.1 selected
- 1.2 selected_index
- 1.3 indentation_step_size
- 1.4 text
- 1.5 hint_text
- 1.6 hint_image
- 1.7 history
- 1.8 max_input_length
- 1.9 link_aware
- 1.10 link_color
- 1.11 wrap
- 1.12 value
- 1.13 best_slider_length
- 1.14 minimum_value_label
- 1.15 maximum_value_label
- 1.16 step_size
- 1.17 percentage
- 1.18 selected_item_path
- 1.19 path
- 1.20 unfolded
- 1.21 unit
- 1.22 item_count
- 1.23 use_markup
- 1.24 label
- 1.25 characters_per_line
- 1.26 marked_up_text
- 1.27 enabled
- 1.28 editable
- 1.29 help
- 1.30 tooltip
- 1.31 overflow_to_tooltip
- 1.32 visible
- 1.33 ellipsize_mode
- 1.34 text_alignment
- 1.35 type
- 2 Widget Callbacks
- 3 Widget Length
- 4 Widget Methods
The widget userdata offers access to a widget of a GUI2 dialog. While there is only one type of widget userdata that covers all widgets including the window itself, the properties of a widget userdata are different for each type of widget. Indexing a widget's userdata can either be used to access a child widget or to set or get a property of a widget. Some properties are read-only or write-only; the properties depend on the type of the widget.
An example of accessing a child widget:
function preshow(dialog)
local okay_button = dialog.okay_button
-- okay_button is now a handle to the the widget's child with the id 'okay_button'
end
Widget Attributes
selected
- widget.selected ↔ boolean
- Available on: [toggle_button], [toggle_panel]
Whether the item is selected or not. Note that this should only be used for widgets that have only 2 states. In particular, there exist 3-State toggle_buttons (for example in listbox headers). For those, selected_index must be used instead.
selected_index
- widget.selected_index ↔ index
- Available on: [listbox], [multi_page], [stacked_widget], [menu_button], [toggle_button], [toggle_panel]
The selected index of the item. For [toggle_button] and [toggle_panel], this is the same as selected only encoded as a number (1 for false or 2 for true) instead of a boolean.
For a [listbox]with has_maximum=false and more than one item selected, reading selected_index will return the first selected index.
For a [stacked_widget], only the layer specified by selected_index will be displayed and receive events (callbacks will only be triggered on the selected layer). A selected_index of 0 represents all layers being selected, with events only being received by the layer with the highest index. Note that term selected for the layer of a stacked_widget is not the same as the selected widget attribute.
indentation_step_size
- widget.indentation_step_size ↔ int
- Available on: [tree_view]
How much should child nodes be offset from their parent node.
text
- widget.text ↔ text
- Available on: [text_box]
The text of the textbox.
hint_text
- widget.hint_text ↔ text
- Available on: [text_box], [combobox]
A background text that is shown on the widget when it is not focused and has no other text.
hint_image
- widget.hint_image ↔ text
- Available on: [text_box], [combobox]
A image that is shown on the widget when it is not focused and has no other text.
history
- widget.history ← text
- Available on: [text_box]
Input history of this text box.
max_input_length
- widget.max_input_length ↔ text
- Available on: [text_box], [combobox]
Maximum number of character than can be input into this widget.
link_aware
- widget.link_aware → boolean
- Available on: [label], [rich_label], [scroll_label], [scroll_text]
Whether this widget recognizes inline links and allows clicking on them.
link_color
- widget.link_color → color string
- Available on: [label], [rich_label]
Color of the inline link, as an hex string.
wrap
- widget.wrap → boolean
- Available on: [label]
Whether the text content in this label can wrap.
value
- widget.value ↔ position
- Available on: [slider]
The current position of the slider.
best_slider_length
- widget.best_slider_length ↔ length
- Available on: [slider]
Best length of the slider.
minimum_value_label
- widget.minimum_value_label ↔ text
- Available on: [slider]
The text the slider's label shows when it is at minimum value position.
maximum_value_label
- widget.maximum_value_label ↔ text
- Available on: [slider]
The text the slider's label shows when it is at maximum value position.
step_size
- widget.step_size ↔ int
- Available on: [slider]
percentage
- widget.percentage ↔ position
- Available on: [progress_bar]
The current position of the progress bar, between 0 and 100.
selected_item_path
- widget.selected_item_path → array of indices
- Available on: [tree_view]
A table describing the currently selected node. If for example, in the following treeview, Item 9 is selected, the result will be {2,1,3}.
+Section1 +Subsection11 *Item1 *Item2 *Item3 +Subsection12 *Item4 *Item5 *Item6 +Section2 +Subsection21 *Item7 *Item8 *Item9 +Subsection22 *Item10 *Item11 *Item12
path
- widget.path → array of indices
- Available on: [tree_view_node]
A table describing this node in the overall treeview. See selected_item_path for the meaning of the table..
unfolded
- widget.unfolded ← boolean
- Available on: [tree_view_node], [tree_view]
Control whether a tree node is currently expanded or not.
unit
- widget.unit ← unit or unit type
- Available on: [unit_preview_pane]
Change the displayed unit or unit type in the preview pane.
item_count
- widget.item_count → number of items
- Available on: [multi_page], [listbox], [combobox], [stacked_widget], [tree_view], [tree_view_node], [styled_widget]
The number of items in the container widget.
use_markup
- widget.use_markup → boolean
- Available on: Most widgets, in particular [label], [button]
Sets whether the widget's label will parse Pango formatting.
label
- widget.label ← text
- Available on: Most widgets, in particular [label], [button], [image]
The widget's label. Technically this is a special string used in the widget's wml definition. It usually does what one would expect, but also sets the image for image widgets. For [text_box], use text for initial values.
characters_per_line
- widget.label ↔ int
- Available on: [label]
Maximum characters this label should show per line.
marked_up_text
- widget.marked_up_text ← text
- Available on: Most widgets, in particular [label], [button]
Shortcut for setting label and use_markup=yes.
enabled
- widget.enabled ↔ boolean
- Available on: Most widgets
editable
- widget.enabled ↔ boolean
- Available on: [text_box]
If this text box is editable, i.e., read-only. (Text can be selected/copied but not modified.)
help
- widget.enabled ↔ text
- Available on: Most widgets
Help text for this widget.
tooltip
- widget.tooltip ↔ text
- Available on: Most widgets
overflow_to_tooltip
- widget.overflow_to_tooltip ↔ boolean
- Available on: Most widgets
visible
- widget.visible ↔ visibility string
- Available on: Most widgets
Determines whether the widget is visible onscreen. The following visibility statuses are recognized:
| String value | Boolean shorthand | Meaning |
|---|---|---|
| visible | true | The widget is visible and handles events. |
| hidden | The widget is not visible, doesn't handle events, but still takes up space on the dialog grid. | |
| invisible | false | The widget is not visible, doesn't handle events, and does not take up space on the dialog grid. |
ellipsize_mode
- widget.ellipsize_mode ↔ ellipsization mode string
- Available on: Most widgets
Sets the Pango ellipsization mode for the widget. Accepts only one of the special strings:
| String value |
|---|
| none |
| start |
| end |
| middle |
text_alignment
- widget.text_alignment ↔ text alignment string
- Available on: Most widgets
Sets the Pango text alignment for the widget. Accepts only one of the special strings:
| String value |
|---|
| left |
| right |
| center |
type
- widget.type → string
- Available on: All widgets
Returns a string specifying the type of the widget.
Widget Callbacks
on_modified
- widget.on_modified ← function()
- Available on: Most widgets, in particular [slider], [toggle_button], [listbox], [menu_button], [text_box]
Triggers when the user changes the value of the widget.
on_left_click
- widget.on_left_click ← function()
- Available on: All widgets
Triggers when the user clicks on the widget.
on_double_click
(Version 1.19.14 and later only)
- widget.on_double_click ← function()
- Available on: [toggle_panel]
Triggers when the user double clicks on the widget. Non-toggle panel widgets can be wrapped in a toggle panel to make use of this event handler.
on_button_click
- widget.on_button_click ← function()
- Available on: [button], [repeating_button]
Triggers when the user clicks on the button. This can differ from on_left_click, depending on the type of widget. For example, on a [repeating_button] it will fire multiple times if the user holds the mouse button down.
on_link_click
(Version 1.19.9 and later only)
- widget.on_link_click ← function(dest)
- Available on: [rich_label]
Triggers when the user clicks on a <ref> link inside a [rich_label]. The first argument dest is the target of the link.
Widget Length
(Version 1.19.4 and later only)
- #widget
- Available on: [listbox], [multi_page], [tree_view], [tree_view_node], (Version 1.19.6 and later only) [stacked_widget]
Returns the total number of children in the specified container widget – for example, the number of rows in a list box, or the number of pages in a multi-page.
Widget Methods
Any function defined in the gui.widget module and taking a widget as its first parameter can be called as a method of a widget. This includes any functions that are added to the module by user code. Note that these methods are available even if the widget itself doesn't support that function, so in some cases it may be necessary to check widget.type before calling the method.