Difference between revisions of "LuaAPI/types/widget"

From The Battle for Wesnoth Wiki
< LuaAPI‎ | types
(Created page with "the 'widget' userdata offers access to a widget of a gui2 dialog, whiel there is only one type of widget userdata tha covers all widgets including the window itself, The prope...")
 
Line 1: Line 1:
the 'widget' userdata offers access to a widget of a gui2 dialog, whiel there is only one type of widget userdata tha covers all widgets including the window itself, The properties of a widget userdataq are different for each widgets. Indexing a widgets userdata cen either be sued to
+
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 userdataq are different for each widgets. Indexing a widgets userdata can either be used to
 +
 
 
* Access a child widget
 
* Access a child widget
 
Example code
 
Example code
Line 7: Line 8:
 
   -- okay_button is now a handle to the the widgets child with the id 'okay_button'  
 
   -- okay_button is now a handle to the the widgets child with the id 'okay_button'  
 
end
 
end
```
+
``` or to
* Set/Get a property of a widget
+
* Set/Get a property of a widget Some Properties are read-only, the propertied depends on the type of  the widget, the following properties exist:
Some Properties are read-only, the propertied depends on the type of  the widget, the follwing properties exist:
+
 
** selected get/set '''boolean''', [toggle_button], [toggle_panel]:whether the item is selected or not
+
 
** selected_index, get/set '''integer''', [listbox], [multi_page], [stacked_widget], selectable_item ([menu_button], [toggle_button], [toggle_panel]) :the selected index of the item.
+
=== widget attributes ===
** text, get/set '''string''', [text_box]: the text of the textbox .
+
 
** value, get/set, '''integer''' [slider]: the value of the slider
+
 
** percentage, get/set, '''integer''' [progress_bar]
+
==== selected ====
** selected_item_path, get '''array of integers''' [tree_view]: a table descibing the currently selected node. If for example in this treeview
+
 
 +
* '''w.selected = value'''
 +
* '''boolean'''
 +
* '''get/set'''
 +
* [toggle_button], [toggle_panel]
 +
 
 +
whether the item is selected or not
 +
 
 +
 
 +
==== selected_index ====
 +
 
 +
* '''w.selected_index = value'''
 +
* '''number'''
 +
* '''get/set'''
 +
* [listbox], [multi_page], [stacked_widget], selectable_item ([menu_button], [toggle_button], [toggle_panel])
 +
 
 +
the selected index of the item
 +
 
 +
 
 +
==== text ====
 +
 
 +
* '''w.text = value'''
 +
* '''string'''
 +
* '''get/set'''
 +
* [text_box]
 +
 
 +
the text of the textbox
 +
 
 +
==== value ====
 +
 
 +
* '''w.value = value'''
 +
* '''number'''
 +
* '''get/set'''
 +
* [slider]
 +
 
 +
 
 +
==== percentage ====
 +
 
 +
* '''w.percentage = value'''
 +
* '''number'''
 +
* '''get/set'''
 +
* [progress_bar]
 +
 
 +
 
 +
==== selected_item_path ====
 +
 
 +
* '''value = w.selected_item_path'''
 +
* '''array of integers'''
 +
* '''get'''
 +
* [slider]
 +
 
 +
a table descibing the currently selected node. If for example in this treeview
 
  +Section1
 
  +Section1
 
   +Subsection11
 
   +Subsection11
Line 35: Line 87:
 
   *Item12
 
   *Item12
 
Item 9 is selected the value will be {2,1,3}
 
Item 9 is selected the value will be {2,1,3}
** path, get '''array of integers''' [tree_view_node] table of integers, see selected_item_path
 
** unfolded, set '''boolean''' [tree_view_node]: whether a node of a treeview is unfolded or not
 
** unit, set '''unit''' or '''unit type''' userdata [unit_preview_pane]
 
** item_count, get  '''integer''' [multi_page], [listbox]
 
** use_markup, set, '''boolean''' most widgets, in particular [label], [button]
 
** marked_up_text, set, '''string''' most widgets, in particular [label], [button]: a shortcut for settigns label with use_markup=true
 
** enabled, set '''boolean''', all widgets
 
** tooltip, set '''string''', all widgets
 
** visible, set '''string''', all widgets
 
** label, set '''string''', all widgets: the label, technically the is a special string used in the widgets wml definition, it usualyl does what one would expect but also sets the image for [image] widgets
 
** type, get '''string''', all widgtes
 
  the type of the widget
 
  
 +
==== path ====
 +
 +
* '''value = w.path'''
 +
* '''array of integers'''
 +
* '''get'''
 +
* [tree_view_node]
 +
 +
See selected_item_path for the syntax.
 +
 +
 +
==== unfolded ====
 +
 +
* '''w.unfolded = value'''
 +
* '''boolean'''
 +
* '''set'''
 +
* [tree_view_node]
 +
 +
 +
==== unit ====
 +
 +
* '''w.unit = value'''
 +
* '''unit''' or '''unit type'''
 +
* '''set'''
 +
* [unit_preview_pane]
 +
 +
 +
==== item_count ====
 +
 +
* '''value = w.item_count'''
 +
* '''number'''
 +
* '''get'''
 +
* [multi_page], [listbox]
 +
 +
==== use_markup ====
 +
 +
* '''w.use_markup = value'''
 +
* '''boolean'''
 +
* '''set'''
 +
* most widgets, in particular [label], [button]
 +
 +
==== label ====
 +
 +
* '''w.label = value'''
 +
* '''string'''
 +
* '''set'''
 +
* most widgets, in particular [label], [button], [image]
 +
 +
the label, technically the is a special string used in the widgets wml definition, it usualyl does what one would expect but also sets the image for [image] widgets
 +
 +
==== marked_up_text ====
 +
 +
* '''w.marked_up_text = value'''
 +
* '''string'''
 +
* '''set'''
 +
* most widgets, in particular [label], [button]
 +
 +
shortcut for setting label and use_markup=yes
 +
 +
 +
==== enabled ====
 +
 +
* '''w.enabled = value'''
 +
* '''boolean'''
 +
* '''set'''
 +
* all widgets
 +
 +
==== tooltip ====
 +
 +
* '''w.tooltip = value'''
 +
* '''string'''
 +
* '''set'''
 +
* all widgets
 +
 +
 +
==== visible ====
 +
 +
* '''w.visible = value'''
 +
* '''string'''
 +
* '''set'''
 +
* all widgets
 +
 +
The following visibility statuses are recognized:
 +
 +
{| clasS="wikitable"
 +
! 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.
 +
|}
 +
 +
 +
==== type ====
 +
 +
* '''value = w.type'''
 +
* '''string'''
 +
* '''get'''
 +
* all widgets
 +
 +
 +
 +
=== widget callbacks ===
 +
 +
==== on_modified ====
 +
* '''function w.on_modified() .... end
 +
* all widgets the allow the user to select a value of any type.
 +
 +
==== on_left_click ====
 +
* '''function w.on_left_click() .... end
 +
* all widgets
  
on_modified
+
==== on_button_click ====
"on_left_click
+
* '''function w.on_button_click() .... end
"on_button_click
+
* button type widgets

Revision as of 21:29, 27 September 2020

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 userdataq are different for each widgets. Indexing a widgets userdata can either be used to

  • Access a child widget

Example code ``` function preshow(dialog)

 local okay_button = dialog.okay_button
 -- okay_button is now a handle to the the widgets child with the id 'okay_button' 

end ``` or to

  • Set/Get a property of a widget Some Properties are read-only, the propertied depends on the type of the widget, the following properties exist:


widget attributes

selected

  • w.selected = value
  • boolean
  • get/set
  • [toggle_button], [toggle_panel]

whether the item is selected or not


selected_index

  • w.selected_index = value
  • number
  • get/set
  • [listbox], [multi_page], [stacked_widget], selectable_item ([menu_button], [toggle_button], [toggle_panel])

the selected index of the item


text

  • w.text = value
  • string
  • get/set
  • [text_box]

the text of the textbox

value

  • w.value = value
  • number
  • get/set
  • [slider]


percentage

  • w.percentage = value
  • number
  • get/set
  • [progress_bar]


selected_item_path

  • value = w.selected_item_path
  • array of integers
  • get
  • [slider]

a table descibing the currently selected node. If for example in this treeview

+Section1
 +Subsection11
  *Item1
  *Item2
  *Item3
 +Subsection12
  *Item4
  *Item5
  *Item6
+Section2
 +Subsection21
  *Item7
  *Item8
  *Item9
 +Subsection22
  *Item10
  *Item11
  *Item12

Item 9 is selected the value will be {2,1,3}

path

  • value = w.path
  • array of integers
  • get
  • [tree_view_node]

See selected_item_path for the syntax.


unfolded

  • w.unfolded = value
  • boolean
  • set
  • [tree_view_node]


unit

  • w.unit = value
  • unit or unit type
  • set
  • [unit_preview_pane]


item_count

  • value = w.item_count
  • number
  • get
  • [multi_page], [listbox]

use_markup

  • w.use_markup = value
  • boolean
  • set
  • most widgets, in particular [label], [button]

label

  • w.label = value
  • string
  • set
  • most widgets, in particular [label], [button], [image]

the label, technically the is a special string used in the widgets wml definition, it usualyl does what one would expect but also sets the image for [image] widgets

marked_up_text

  • w.marked_up_text = value
  • string
  • set
  • most widgets, in particular [label], [button]

shortcut for setting label and use_markup=yes


enabled

  • w.enabled = value
  • boolean
  • set
  • all widgets

tooltip

  • w.tooltip = value
  • string
  • set
  • all widgets


visible

  • w.visible = value
  • string
  • set
  • all widgets

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.


type

  • value = w.type
  • string
  • get
  • all widgets


widget callbacks

on_modified

  • function w.on_modified() .... end
  • all widgets the allow the user to select a value of any type.

on_left_click

  • function w.on_left_click() .... end
  • all widgets

on_button_click

  • function w.on_button_click() .... end
  • button type widgets