An element of a custom GUI. This type is used to represent any kind of a GUI element - labels, buttons
and frames are all instances of this type. Just like LuaEntity, different kinds
of elements support different attributes; attempting to access an attribute on an element that doesn't support
it (for instance, trying to access the column_count
of a textfield
) will result in a runtime error.
The following types of GUI element are supported:
"button"
: A clickable element. Relevant event: on_gui_click"sprite-button"
: A button
that displays a sprite rather than text. Relevant event: on_gui_click"checkbox"
: A clickable element with a check mark that can be turned off or on. Relevant event: on_gui_checked_state_changed"flow"
: An invisible container that lays out its children either horizontally or vertically."frame"
: A non-transparent box that contains other elements. It can have a title (set via the caption
attribute). Just like a flow
, it lays out its children either horizontally or vertically. Relevant event: on_gui_location_changed"label"
: A piece of text."line"
: A horizontal or vertical separation line."progressbar"
: A partially filled bar that can be used to indicate progress."table"
: An invisible container that lays out its children in a specific number of columns.
The width of each column is determined by the widest element it contains."textfield"
: A single-line box the user can type into. Relevant events: on_gui_text_changed, on_gui_confirmed"radiobutton"
: A clickable element that is functionally identical to a checkbox
, but has a circular appearance. Relevant event: on_gui_checked_state_changed"sprite"
: An element that shows an image."scroll-pane"
: An invisible element that is similar to a flow
, but has the ability to show and use scroll bars."drop-down"
: A drop-down containing strings of text. Relevant event: on_gui_selection_state_changed"list-box"
: A list of strings, only one of which can be selected at a time. Shows a scroll bar if necessary. Relevant event: on_gui_selection_state_changed"camera"
: A camera that shows the game at the given position on the given surface. It can visually track an entity that is set after the element has been created."choose-elem-button"
: A button that lets the player pick from a certain kind of prototype, with optional filtering. Relevant event: on_gui_elem_changed"text-box"
: A multi-line textfield
. Relevant event: on_gui_text_changed"slider"
: A horizontal number line which can be used to choose a number. Relevant event: on_gui_value_changed"minimap"
: A minimap preview, similar to the normal player minimap. It can visually track an entity that is set after the element has been created."entity-preview"
: A preview of an entity. The entity has to be set after the element has been created."empty-widget"
: An empty element that just exists. The root GUI elements screen
and relative
are empty-widget
s."tabbed-pane"
: A collection of tab
s and their contents. Relevant event: on_gui_selected_tab_changed"tab"
: A tab for use in a tabbed-pane
."switch"
: A switch with three possible states. Can have labels attached to either side. Relevant event: on_gui_switch_state_changed Each GUI element allows access to its children by having them as attributes. Thus, one can use the
parent.child
syntax to refer to children. Lua also supports the parent["child"]
syntax to refer to the
same element. This can be used in cases where the child has a name that isn't a valid Lua identifier.
greeting
to the top flow. Immediately after, it will change its text
to illustrate accessing child elements.
game.player.gui.top.add{type="label", name="greeting", caption="Hi"}
game.player.gui.top.greeting.caption = "Hello there!"
game.player.gui.top["greeting"].caption = "Actually, never mind, I don't like your face"
local tabbed_pane = game.player.gui.top.add{type="tabbed-pane"}
local tab1 = tabbed_pane.add{type="tab", caption="Tab 1"}
local tab2 = tabbed_pane.add{type="tab", caption="Tab 2"}
local label1 = tabbed_pane.add{type="label", caption="Label 1"}
local label2 = tabbed_pane.add{type="label", caption="Label 2"}
tabbed_pane.add_tab(tab1, label1)
tabbed_pane.add_tab(tab2, label2)
add{type = …, name = …, caption = …, tooltip = …, enabled = …, visible = …, ignored_by_interaction = …, style = …, tags = …, index = …, anchor = …} → LuaGuiElement | Add a new child element to this GuiElement. |
clear() | Remove children of this element. |
destroy() | Remove this element, along with its children. |
get_mod() → string | The mod that owns this Gui element or nil if it's owned by the scenario script. |
get_index_in_parent() → uint | Gets the index that this element has in its parent element. |
clear_items() | Removes the items in this dropdown or listbox. |
get_item(index) → LocalisedString | Gets the item at the given index from this dropdown or listbox. |
set_item(index, string) | Sets the given string at the given index in this dropdown or listbox. |
add_item(string, index) | Inserts a string at the end or at the given index of this dropdown or listbox. |
remove_item(index) | Removes the item at the given index from this dropdown or listbox. |
get_slider_minimum() → double | Gets this sliders minimum value. |
get_slider_maximum() → double | Gets this sliders maximum value. |
set_slider_minimum_maximum(minimum, maximum) | Sets this sliders minimum and maximum values. |
get_slider_value_step() → double | Gets the minimum distance this slider can move. |
get_slider_discrete_slider() → boolean | Returns whether this slider only allows being moved to discrete positions. |
get_slider_discrete_values() → boolean | Returns whether this slider only allows discrete values. |
set_slider_value_step(value) | Sets the minimum distance this slider can move. |
set_slider_discrete_slider(value) | Sets whether this slider only allows being moved to discrete positions. |
set_slider_discrete_values(value) | Sets whether this slider only allows discrete values. |
focus() | Focuses this GUI element if possible. |
scroll_to_top() | Scrolls this scroll bar to the top. |
scroll_to_bottom() | Scrolls this scroll bar to the bottom. |
scroll_to_left() | Scrolls this scroll bar to the left. |
scroll_to_right() | Scrolls this scroll bar to the right. |
scroll_to_element(element, scroll_mode) | Scrolls this scroll bar such that the specified GUI element is visible to the player. |
select_all() | Selects all the text in this textbox. |
select(start, end) | Selects a range of text in this textbox. |
add_tab(tab, content) | Adds the given tab and content widgets to this tabbed pane as a new tab. |
remove_tab(tab) | Removes the given tab and its associated content from this tabbed pane. |
force_auto_center() | Forces this frame to re-auto-center. |
scroll_to_item(index, scroll_mode) | Scrolls the scroll bar such that the specified listbox item is visible to the player. |
bring_to_front() | Moves this GUI element to the "front" so it will draw over other elements. |
index :: uint [R] | The index of this GUI element (unique amongst the GUI elements of a LuaPlayer). |
gui :: LuaGui [R] | The GUI this element is a child of. |
parent :: LuaGuiElement [R] | The direct parent of this element; nil if this is a top-level element. |
name :: string [RW] | The name of this element. |
caption :: LocalisedString [RW] | The text displayed on this element. |
value :: double [RW] | How much this progress bar is filled. |
direction :: string [R] | Direction of this element's layout. |
style :: LuaStyle or string [RW] | The style of this element. |
visible :: boolean [RW] | Sets whether this GUI element is visible or completely hidden, taking no space in the layout. |
text :: string [RW] | The text contained in this textfield or text-box. |
children_names :: array[string] [R] | Names of all the children of this element. |
state :: boolean [RW] | Is this checkbox or radiobutton checked? |
player_index :: uint [R] | Index into LuaGameScript::players specifying the player who owns this element. |
sprite :: SpritePath [RW] | The image to display on this sprite-button or sprite in the default state. |
resize_to_sprite :: boolean [RW] | Whether the image widget should resize according to the sprite in it. |
hovered_sprite :: SpritePath [RW] | The image to display on this sprite-button when it is hovered. |
clicked_sprite :: SpritePath [RW] | The image to display on this sprite-button when it is clicked. |
tooltip :: LocalisedString [RW] | |
horizontal_scroll_policy :: string [RW] | Policy of the horizontal scroll bar. |
vertical_scroll_policy :: string [RW] | Policy of the vertical scroll bar. |
type :: string [R] | The type of this GUI element. |
children :: array[LuaGuiElement] [R] | The child-elements of this GUI element. |
items :: array[LocalisedString] [RW] | The items in this dropdown or listbox. |
selected_index :: uint [RW] | The selected index for this dropdown or listbox. |
number :: double [RW] | The number to be shown in the bottom right corner of this sprite-button. |
show_percent_for_small_numbers :: boolean [RW] | Related to the number to be shown in the bottom right corner of this sprite-button. |
location :: GuiLocation [RW] | The location of this widget when stored in LuaGui::screen or nil if not not set or not in LuaGui::screen. |
auto_center :: boolean [RW] | Whether this frame auto-centers on window resize when stored in LuaGui::screen. |
badge_text :: LocalisedString [RW] | The text to display after the normal tab text (designed to work with numbers) |
position :: Position [RW] | The position this camera or minimap is focused on, if any. |
surface_index :: uint [RW] | The surface index this camera or minimap is using. |
zoom :: double [RW] | The zoom this camera or minimap is using. |
minimap_player_index :: uint [RW] | The player index this minimap is using. |
force :: string [RW] | The force this minimap is using or nil if no force is set. |
elem_type :: string [R] | The elem type of this choose-elem-button. |
elem_value :: string or SignalID [RW] | The elem value of this choose-elem-button or nil if there is no value. |
elem_filters :: array[PrototypeFilter] [RW] | The elem filters of this choose-elem-button or nil if there are no filters. |
selectable :: boolean [RW] | Whether the contents of this text-box are selectable. |
word_wrap :: boolean [RW] | Whether this text-box will word-wrap automatically. |
read_only :: boolean [RW] | Whether this text-box is read-only. |
enabled :: boolean [RW] | Whether this GUI element is enabled. |
ignored_by_interaction :: boolean [RW] | Whether this GUI element is ignored by interaction. |
locked :: boolean [RW] | Whether this choose-elem-button can be changed by the player. |
draw_vertical_lines :: boolean [RW] | Whether this table should draw vertical grid lines. |
draw_horizontal_lines :: boolean [RW] | Whether this table should draw horizontal grid lines. |
draw_horizontal_line_after_headers :: boolean [RW] | Whether this table should draw a horizontal grid line below the first table row. |
column_count :: uint [R] | The number of columns in this table. |
vertical_centering :: boolean [RW] | Whether the content of this table should be vertically centered. |
slider_value :: double [RW] | The value of this slider element. |
mouse_button_filter :: MouseButtonFlags [RW] | The mouse button filters for this button or sprite-button. |
numeric :: boolean [RW] | Whether this textfield is limited to only numberic characters. |
allow_decimal :: boolean [RW] | Whether this textfield (when in numeric mode) allows decimal numbers. |
allow_negative :: boolean [RW] | Whether this textfield (when in numeric mode) allows negative numbers. |
is_password :: boolean [RW] | Whether this textfield displays as a password field, which renders all characters as * . |
lose_focus_on_confirm :: boolean [RW] | Whether this textfield loses focus after defines.events.on_gui_confirmed is fired. |
clear_and_focus_on_right_click :: boolean [RW] | Makes it so right-clicking on this textfield clears and focuses it. |
drag_target :: LuaGuiElement [RW] | The frame drag target for this flow, frame, label, table, or empty-widget. |
selected_tab_index :: uint [RW] | The selected tab index for this tabbed pane or nil if no tab is selected. |
tabs :: array[TabAndContent] [R] | The tabs and contents being shown in this tabbed-pane. |
entity :: LuaEntity [RW] | The entity associated with this entity-preview, camera, minimap or nil if no entity is associated. |
anchor :: GuiAnchor [RW] | Sets the anchor for this relative widget. |
tags :: Tags [RW] | The tags associated with this LuaGuiElement. |
switch_state :: string [RW] | The switch state (left, none, right) for this switch. |
allow_none_state :: boolean [RW] | Whether the "none" state is allowed for this switch. |
left_label_caption :: LocalisedString [RW] | The text shown for the left switch label. |
left_label_tooltip :: LocalisedString [RW] | The tooltip shown on the left switch label. |
right_label_caption :: LocalisedString [RW] | The text shown for the right switch label. |
right_label_tooltip :: LocalisedString [RW] | The tooltip shown on the right switch label. |
operator [] :: LuaGuiElement [R] | The indexing operator. |
valid :: boolean [R] | Is this object valid? |
object_name :: string [R] | The class name of this object. |
help() → string | All methods and properties that this object supports. |
Add a new child element to this GuiElement.
true
.true
.false
.relative
element.type
:button
"left-and-right"
.flow
"horizontal"
.frame
"horizontal"
.table
false
.false
.false
.true
.textfield
false
.false
.false
.false
.false
.false
.progressbar
0
.checkbox
radiobutton
sprite-button
false
."left-and-right"
.sprite
true
.scroll-pane
"auto"
, "never"
, "always"
, "auto-and-reserve-space"
, "dont-show-but-allow-scrolling"
.
Defaults to "auto"
."auto"
, "never"
, "always"
, "auto-and-reserve-space"
, "dont-show-but-allow-scrolling"
.
Defaults to "auto"
.drop-down
line
"horizontal"
.list-box
camera
choose-elem-button
"item"
- the default value for the button."tile"
- the default value for the button."entity"
- the default value for the button."signal"
- the default value for the button."fluid"
- the default value for the button."recipe"
- the default value for the button."decorative"
- the default value for the button."item-group"
- the default value for the button."achievement"
- the default value for the button."equipment"
- the default value for the button."technology"
- the default value for the button.text-box
slider
0
.30
.minimum_value
.1
.false
.true
.minimap
0.75
.tab
switch
"left"
, "right"
, or "none"
. If set
to "none", allow_none_state
must be true
. Defaults to "left"
.false
.Remove children of this element. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.
game.player.gui.top.clear()
Remove this element, along with its children. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.
game.player.gui.top.greeting.destroy()
The mod that owns this Gui element or nil
if it's owned by the scenario script.
Gets the index that this element has in its parent element.
Removes the items in this dropdown or listbox.
Gets the item at the given index from this dropdown or listbox.
Sets the given string at the given index in this dropdown or listbox.
Inserts a string at the end or at the given index of this dropdown or listbox.
Removes the item at the given index from this dropdown or listbox.
Gets this sliders minimum value.
Gets this sliders maximum value.
Gets the minimum distance this slider can move.
Returns whether this slider only allows being moved to discrete positions.
Returns whether this slider only allows discrete values.
Sets the minimum distance this slider can move.
Sets whether this slider only allows being moved to discrete positions.
Sets whether this slider only allows discrete values.
Focuses this GUI element if possible.
Scrolls this scroll bar to the top.
Scrolls this scroll bar to the bottom.
Scrolls this scroll bar to the left.
Scrolls this scroll bar to the right.
Scrolls this scroll bar such that the specified GUI element is visible to the player.
"in-view"
or "top-third"
. Defaults to "in-view"
.Selects all the text in this textbox.
Selects a range of text in this textbox.
amp
from example
:
textbox.select(3, 5)
textbox.select(1, 0)
Adds the given tab and content widgets to this tabbed pane as a new tab.
Removes the given tab and its associated content from this tabbed pane.
Forces this frame to re-auto-center. Only works on frames stored directly in LuaGui::screen.
Scrolls the scroll bar such that the specified listbox item is visible to the player.
Moves this GUI element to the "front" so it will draw over other elements.
The index of this GUI element (unique amongst the GUI elements of a LuaPlayer).
The GUI this element is a child of.
The direct parent of this element; nil
if this is a top-level element.
The name of this element.
game.player.gui.top.greeting.name == "greeting"
How much this progress bar is filled. It is a value in the range [0, 1].
Direction of this element's layout. May be either "horizontal"
or "vertical"
.
The style of this element. When read, this evaluates to a LuaStyle. For writing, it only accepts a string that specifies the textual identifier (prototype name) of the desired style.
Sets whether this GUI element is visible or completely hidden, taking no space in the layout.
The text contained in this textfield or text-box.
Names of all the children of this element. These are the identifiers that can be used to access the child as an attribute of this element.
Is this checkbox or radiobutton checked?
Index into LuaGameScript::players specifying the player who owns this element.
The image to display on this sprite-button or sprite in the default state.
Whether the image widget should resize according to the sprite in it. Defaults to true
.
The image to display on this sprite-button when it is hovered.
The image to display on this sprite-button when it is clicked.
Policy of the horizontal scroll bar. Possible values are "auto"
, "never"
, "always"
, "auto-and-reserve-space"
, "dont-show-but-allow-scrolling"
.
Policy of the vertical scroll bar. Possible values are "auto"
, "never"
, "always"
, "auto-and-reserve-space"
, "dont-show-but-allow-scrolling"
.
The type of this GUI element.
The child-elements of this GUI element.
The items in this dropdown or listbox.
The selected index for this dropdown or listbox. Returns 0
if none is selected.
The number to be shown in the bottom right corner of this sprite-button. Set this to nil
to show nothing.
Related to the number to be shown in the bottom right corner of this sprite-button.
When set to true
, numbers that are non-zero and smaller than one are shown as a percentage rather than the value.
For example, 0.5
will be shown as 50%
instead.
The location of this widget when stored in LuaGui::screen or nil
if not not set or not in LuaGui::screen.
Whether this frame auto-centers on window resize when stored in LuaGui::screen.
The text to display after the normal tab text (designed to work with numbers)
The position this camera or minimap is focused on, if any.
The surface index this camera or minimap is using.
The zoom this camera or minimap is using.
The player index this minimap is using.
The force this minimap is using or nil
if no force is set.
The elem type of this choose-elem-button.
The elem value of this choose-elem-button or nil
if there is no value.
"signal"
type operates with SignalID, while all other types use strings. The elem filters of this choose-elem-button or nil
if there are no filters.
"item"
- ItemPrototypeFilter"tile"
- TilePrototypeFilter"entity"
- EntityPrototypeFilter"signal"
- Does not support filters"fluid"
- FluidPrototypeFilter"recipe"
- RecipePrototypeFilter"decorative"
- DecorativePrototypeFilter"item-group"
- Does not support filters"achievement"
- AchievementPrototypeFilter"equipment"
- EquipmentPrototypeFilter"technology"
- TechnologyPrototypeFilter
"entity"
to only show items of type "furnace"
.
button.elem_filters = {{filter = "type", type = "furnace"}}
"entity"
to only show entities that have their "hidden"
flags set.
button.elem_filters = {{filter = "hidden"}}
"and"
or "or"
.
The following will filter for any "entities"
that are "furnaces"
and that are not "hidden"
.
button.elem_filters = {{filter = "type", type = "furnace"}, {filter = "hidden", invert = true, mode = "and"}}
Whether the contents of this text-box are selectable. Defaults to true
.
Whether this text-box will word-wrap automatically. Defaults to false
.
Whether this text-box is read-only. Defaults to false
.
Whether this GUI element is enabled. Disabled GUI elements don't trigger events when clicked.
Whether this GUI element is ignored by interaction. This makes clicks on this element 'go through' to the GUI element or even the game surface below it.
Whether this choose-elem-button can be changed by the player.
Whether this table should draw vertical grid lines.
Whether this table should draw horizontal grid lines.
Whether this table should draw a horizontal grid line below the first table row.
The number of columns in this table.
Whether the content of this table should be vertically centered. Overrides LuaStyle::column_alignments. Defaults to true
.
The value of this slider element.
The mouse button filters for this button or sprite-button.
Whether this textfield is limited to only numberic characters.
Whether this textfield (when in numeric mode) allows decimal numbers.
Whether this textfield (when in numeric mode) allows negative numbers.
Whether this textfield displays as a password field, which renders all characters as *
.
Whether this textfield loses focus after defines.events.on_gui_confirmed is fired.
Makes it so right-clicking on this textfield clears and focuses it.
The frame drag target for this flow, frame, label, table, or empty-widget.
nil
. The selected tab index for this tabbed pane or nil
if no tab is selected.
The tabs and contents being shown in this tabbed-pane.
The entity associated with this entity-preview, camera, minimap or nil
if no entity is associated.
Sets the anchor for this relative widget. Setting nil
clears the anchor.
The tags associated with this LuaGuiElement.
The switch state (left, none, right) for this switch.
"none"
. Whether the "none"
state is allowed for this switch.
The tooltip shown on the left switch label.
The tooltip shown on the right switch label.
The indexing operator. Gets children by name.