Factorio API Docs

1.1.66 <>

Class LuaGuiElement

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-widgets.
  • "tabbed-pane": A collection of tabs 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.

Examples

This will add a label called 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"

This will add a tabbed-pane and 2 tabs with contents.

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?=…}

Add a new child element to this GuiElement.


clear()

Remove children of this element.


Remove this element, along with its children.


string?

The mod that owns this Gui element or nil if it's owned by the scenario script.


uint

Gets the index that this element has in its parent element.


swap_children(index_1, index_2)

Swaps the children at the given indices in this element.


Removes the items in this dropdown or listbox.


get_item(index)

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.


double

Gets this sliders minimum value.


double

Gets this sliders maximum value.


set_slider_minimum_maximum(minimum, maximum)

Sets this sliders minimum and maximum values.


double

Gets the minimum distance this slider can move.


boolean

Returns whether this slider only allows being moved to discrete positions.


boolean

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.


focus()

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.


scroll_to_element(element, scroll_mode?)

Scrolls this scroll bar such that the specified GUI element is visible to the player.


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.


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.


Moves this GUI element to the "front" so it will draw over other elements.


help()
string

All methods and properties that this object supports.


:: 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.


[R]

The direct parent of this element.


:: string
[RW]

The name of this element.


[RW]

The text displayed on this element.


:: double
[RW]

How much this progress bar is filled.


:: string
[R]

Direction of this element's layout.


[RW]

The style of this element.


:: boolean
[RW]

Sets whether this GUI element is visible or completely hidden, taking no space in the layout.


:: string
[RW]

The text contained in this textfield or text-box.


:: array[string]
[R]

Names of all the children of this element.


:: boolean
[RW]

Is this checkbox or radiobutton checked?


:: uint
[R]

Index into LuaGameScript::players specifying the player who owns this element.


[RW]

The image to display on this sprite-button or sprite in the default state.


:: boolean
[RW]

Whether the image widget should resize according to the sprite in it.


[RW]

The image to display on this sprite-button when it is hovered.


[RW]

The image to display on this sprite-button when it is clicked.



:: string
[RW]

Policy of the horizontal scroll bar.


:: string
[RW]

Policy of the vertical scroll bar.


:: string
[R]

The type of this GUI element.


:: array[LuaGuiElement]
[R]

The child-elements of this GUI element.


:: array[LocalisedString]
[RW]

The items in this dropdown or listbox.


:: uint
[RW]

The selected index for this dropdown or listbox.


:: double
[RW]

The number to be shown in the bottom right corner of this sprite-button.


:: boolean
[RW]

Related to the number to be shown in the bottom right corner of this sprite-button.


[RW]

The location of this widget when stored in LuaGui::screen.


:: boolean
[RW]

Whether this frame auto-centers on window resize when stored in LuaGui::screen.


[RW]

The text to display after the normal tab text (designed to work with numbers)


[RW]

The position this camera or minimap is focused on, if any.


:: uint
[RW]

The surface index this camera or minimap is using.


:: double
[RW]

The zoom this camera or minimap is using.


:: uint
[RW]

The player index this minimap is using.


:: string?
[RW]

The force this minimap is using, if any.


:: string
[R]

The elem type of this choose-elem-button.


:: string or SignalID?
[RW]

The elem value of this choose-elem-button, if any.


[RW]

The elem filters of this choose-elem-button, if any.


:: boolean
[RW]

Whether the contents of this text-box are selectable.


:: boolean
[RW]

Whether this text-box will word-wrap automatically.


:: boolean
[RW]

Whether this text-box is read-only.


:: boolean
[RW]

Whether this GUI element is enabled.


:: boolean
[RW]

Whether this GUI element is ignored by interaction.


:: boolean
[RW]

Whether this choose-elem-button can be changed by the player.


:: boolean
[RW]

Whether this table should draw vertical grid lines.


:: boolean
[RW]

Whether this table should draw horizontal grid lines.


:: boolean
[RW]

Whether this table should draw a horizontal grid line below the first table row.


:: uint
[R]

The number of columns in this table.


:: boolean
[RW]

Whether the content of this table should be vertically centered.


:: double
[RW]

The value of this slider element.


[RW]

The mouse button filters for this button or sprite-button.


:: boolean
[RW]

Whether this textfield is limited to only numberic characters.


:: boolean
[RW]

Whether this textfield (when in numeric mode) allows decimal numbers.


:: boolean
[RW]

Whether this textfield (when in numeric mode) allows negative numbers.


:: boolean
[RW]

Whether this textfield displays as a password field, which renders all characters as *.


:: boolean
[RW]

Whether this textfield loses focus after defines.events.on_gui_confirmed is fired.


:: boolean
[RW]

Makes it so right-clicking on this textfield clears and focuses it.


[RW]

The frame that is being moved when dragging this GUI element, if any.


:: uint?
[RW]

The selected tab index for this tabbed pane, if any.


:: array[TabAndContent]
[R]

The tabs and contents being shown in this tabbed-pane.


:: LuaEntity?
[RW]

The entity associated with this entity-preview, camera, minimap, if any.


:: GuiAnchor?
[RW]

The anchor for this relative widget, if any.


:: Tags
[RW]

The tags associated with this LuaGuiElement.


:: string
[RW]

The switch state (left, none, right) for this switch.


:: boolean
[RW]

Whether the "none" state is allowed for this switch.


[RW]

The text shown for the left switch label.


[RW]

The tooltip shown on the left switch label.


[RW]

The text shown for the right switch label.


[RW]

The tooltip shown on the right switch label.


:: boolean
[R]

Is this object valid?


:: string
[R]

The class name of this object.


[R]

The indexing operator.

Methods

add{type=…, name?=…, caption?=…, tooltip?=…, enabled?=…, visible?=…, ignored_by_interaction?=…, style?=…, tags?=…, index?=…, anchor?=…} → LuaGuiElement

Add a new child element to this GuiElement.

Parameters

Table with the following fields:
type
:: string

The kind of element to add. Has to be one of the GUI element types listed at the top of this page.


name
:: string?

Name of the child element. It must be unique within the parent element.


caption

Text displayed on the child element. For frames, this is their title. For other elements, like buttons or labels, this is the content. Whilst this attribute may be used on all elements, it doesn't make sense for tables and flows as they won't display it.


tooltip

Tooltip of the child element.


enabled
:: boolean?

Whether the child element is enabled. Defaults to true.


visible
:: boolean?

Whether the child element is visible. Defaults to true.


ignored_by_interaction
:: boolean?

Whether the child element is ignored by interaction. Defaults to false.


style
:: string?

Style of the child element.


tags
:: Tags?

Tags associated with the child element.


index
:: uint?

Location in its parent that the child element should slot into. By default, the child will be appended onto the end.


anchor
:: GuiAnchor?

Where to position the child element when in the relative element.

Other attributes may be specified depending on type:

button

mouse_button_filter

Which mouse buttons the button responds to. Defaults to "left-and-right".

flow

direction
:: string?

The initial direction of the flow's layout. See LuaGuiElement::direction. Defaults to "horizontal".

frame

direction
:: string?

The initial direction of the frame's layout. See LuaGuiElement::direction. Defaults to "horizontal".

table

column_count
:: uint

Number of columns. This can't be changed after the table is created.


draw_vertical_lines
:: boolean?

Whether the table should draw vertical grid lines. Defaults to false.


draw_horizontal_lines
:: boolean?

Whether the table should draw horizontal grid lines. Defaults to false.


draw_horizontal_line_after_headers
:: boolean?

Whether the table should draw a single horizontal grid line after the headers. Defaults to false.


vertical_centering
:: boolean?

Whether the content of the table should be vertically centered. Defaults to true.

textfield

text
:: string?

The initial text contained in the textfield.


numeric
:: boolean?

Defaults to false.


allow_decimal
:: boolean?

Defaults to false.


allow_negative
:: boolean?

Defaults to false.


is_password
:: boolean?

Defaults to false.


lose_focus_on_confirm
:: boolean?

Defaults to false.


clear_and_focus_on_right_click
:: boolean?

Defaults to false.

progressbar

value
:: double?

The initial value of the progressbar, in the range [0, 1]. Defaults to 0.

checkbox

state
:: boolean

The initial checked-state of the checkbox.

radiobutton

state
:: boolean

The initial checked-state of the radiobutton.

sprite-button

sprite

Path to the image to display on the button.


hovered_sprite

Path to the image to display on the button when it is hovered.


clicked_sprite

Path to the image to display on the button when it is clicked.


number
:: double?

The number shown on the button.


show_percent_for_small_numbers
:: boolean?

Formats small numbers as percentages. Defaults to false.


mouse_button_filter

The mouse buttons that the button responds to. Defaults to "left-and-right".

sprite

sprite

Path to the image to display.


resize_to_sprite
:: boolean?

Whether the widget should resize according to the sprite in it. Defaults to true.

scroll-pane

horizontal_scroll_policy
:: string?

Policy of the horizontal scroll bar. Possible values are "auto", "never", "always", "auto-and-reserve-space", "dont-show-but-allow-scrolling". Defaults to "auto".


vertical_scroll_policy
:: string?

Policy of the vertical scroll bar. Possible values are "auto", "never", "always", "auto-and-reserve-space", "dont-show-but-allow-scrolling". Defaults to "auto".

drop-down

items
:: array[LocalisedString]?

The initial items in the dropdown.


selected_index
:: uint?

The index of the initially selected item. Defaults to 0.

line

direction
:: string?

The initial direction of the line. Defaults to "horizontal".

list-box

items
:: array[LocalisedString]?

The initial items in the listbox.


selected_index
:: uint?

The index of the initially selected item. Defaults to 0.

camera

position

The position the camera centers on.


surface_index
:: uint?

The surface that the camera will render. Defaults to the player's current surface.


zoom
:: double?

The initial camera zoom. Defaults to 0.75.

choose-elem-button

elem_type
:: string

The type of the button - one of the following values.


item
:: string?

If type is "item" - the default value for the button.


tile
:: string?

If type is "tile" - the default value for the button.


entity
:: string?

If type is "entity" - the default value for the button.


signal
:: SignalID?

If type is "signal" - the default value for the button.


fluid
:: string?

If type is "fluid" - the default value for the button.


recipe
:: string?

If type is "recipe" - the default value for the button.


decorative
:: string?

If type is "decorative" - the default value for the button.


item-group
:: string?

If type is "item-group" - the default value for the button.


achievement
:: string?

If type is "achievement" - the default value for the button.


equipment
:: string?

If type is "equipment" - the default value for the button.


technology
:: string?

If type is "technology" - the default value for the button.


elem_filters

Filters describing what to show in the selection window. The applicable filter depends on the elem_type.

text-box

text
:: string?

The initial text contained in the text-box.


clear_and_focus_on_right_click
:: boolean?

Defaults to false.

slider

minimum_value
:: double?

The minimum value for the slider. Defaults to 0.


maximum_value
:: double?

The maximum value for the slider. Defaults to 30.


value
:: double?

The initial value for the slider. Defaults to minimum_value.


value_step
:: double?

The minimum value the slider can move. Defaults to 1.


discrete_slider
:: boolean?

Defaults to false.


discrete_values
:: boolean?

Defaults to true.

minimap

position

The position the minimap centers on. Defaults to the player's current position.


surface_index
:: uint?

The surface the camera will render. Defaults to the player's current surface.


chart_player_index
:: uint?

The player index the map should use. Defaults to the current player.


force
:: string?

The force this minimap should use. Defaults to the player's current force.


zoom
:: double?

The initial camera zoom. Defaults to 0.75.

tab

badge_text

The text to display after the normal tab text (designed to work with numbers).

switch

switch_state
:: string?

Possible values are "left", "right", or "none". If set to "none", allow_none_state must be true. Defaults to "left".


allow_none_state
:: boolean?

Whether the switch can be set to a middle state. Defaults to false.


left_label_caption

left_label_tooltip

right_label_caption

right_label_tooltip

Return values

The GUI element that was added.


clear()

Remove children of this element. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.

Example

game.player.gui.top.clear()

destroy()

Remove this element, along with its children. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.

Example

game.player.gui.top.greeting.destroy()

Note

The top-level GUI elements - LuaGui::top, LuaGui::left, LuaGui::center and LuaGui::screen - can't be destroyed.


get_mod() → string?

The mod that owns this Gui element or nil if it's owned by the scenario script.

Note

This has a not-super-expensive, but non-free cost to get.


get_index_in_parent() → uint

Gets the index that this element has in its parent element.

Note

This iterates through the children of the parent of this element, meaning this has a non-free cost to get, but is faster than doing the equivalent in Lua.


swap_children(index_1, index_2)

Swaps the children at the given indices in this element.

Parameters

index_1
:: uint

The index of the first child.


index_2
:: uint

The index of the second child.


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.

Parameters

index
:: uint

The index to get


set_item(index, string)

Sets the given string at the given index in this dropdown or listbox.

Parameters

index
:: uint

The index whose text to replace.


string

The text to set at the given index.


add_item(string, index?)

Inserts a string at the end or at the given index of this dropdown or listbox.

Parameters

string

The text to insert.


index
:: uint?

The index at which to insert the item.


remove_item(index)

Removes the item at the given index from this dropdown or listbox.

Parameters

index
:: uint

The index


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.

Parameters

minimum
:: double

maximum
:: double

Note

The minimum can't be >= the maximum.


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.

Parameters

value
:: double

Note

The minimum distance can't be > (max - min).


set_slider_discrete_slider(value)

Sets whether this slider only allows being moved to discrete positions.

Parameters

value
:: boolean

set_slider_discrete_values(value)

Sets whether this slider only allows discrete values.

Parameters

value
:: boolean

focus()

Focuses this GUI element if possible.


scroll_to_top()

Scrolls this scroll bar to the top.

Can only be used if this is scroll-pane or text-box

scroll_to_bottom()

Scrolls this scroll bar to the bottom.

Can only be used if this is scroll-pane or text-box

scroll_to_left()

Scrolls this scroll bar to the left.

Can only be used if this is scroll-pane or text-box

scroll_to_right()

Scrolls this scroll bar to the right.

Can only be used if this is scroll-pane or text-box

scroll_to_element(element, scroll_mode?)

Scrolls this scroll bar such that the specified GUI element is visible to the player.

Parameters

element

The element to scroll to.


scroll_mode
:: string?

Where the element should be positioned in the scroll-pane. Must be either "in-view" or "top-third". Defaults to "in-view".

Can only be used if this is scroll-pane

select_all()

Selects all the text in this textbox.

Can only be used if this is textfield or text-box

select(start, end)

Selects a range of text in this textbox.

Parameters

start
:: int

The index of the first character to select


end
:: int

The index of the last character to select

Examples

Select the characters amp from example:

textbox.select(3, 5)

Move the cursor to the start of the text box:

textbox.select(1, 0)
Can only be used if this is textfield or text-box

add_tab(tab, content)

Adds the given tab and content widgets to this tabbed pane as a new tab.

Parameters

tab

The tab to add, must be a GUI element of type "tab".


content

The content to show when this tab is selected. Can be any type of GUI element.

Can only be used if this is tabbed-pane

remove_tab(tab)

Removes the given tab and its associated content from this tabbed pane.

Parameters

tab

The tab to remove. If not given, it removes all tabs.

Notes

Removing a tab does not destroy the tab or the tab contents. It just removes them from the view.

When removing tabs, LuaGuiElement::selected_tab_index needs to be manually updated.

Can only be used if this is tabbed-pane

force_auto_center()

Forces this frame to re-auto-center. Only works on frames stored directly in LuaGui::screen.

Raised events

Can only be used if this is frame

scroll_to_item(index, scroll_mode?)

Scrolls the scroll bar such that the specified listbox item is visible to the player.

Parameters

index
:: int

The item index to scroll to.


scroll_mode
:: string?

Where the item should be positioned in the list-box. Must be either "in-view" or "top-third". Defaults to "in-view".

Can only be used if this is list-box

bring_to_front()

Moves this GUI element to the "front" so it will draw over other elements.

Note

Only works for elements in LuaGui::screen


help() → string

All methods and properties that this object supports.

Attributes

index :: uint [Read]

The index of this GUI element (unique amongst the GUI elements of a LuaPlayer).


gui :: LuaGui [Read]

The GUI this element is a child of.


parent :: LuaGuiElement? [Read]

The direct parent of this element. nil if this is a top-level element.


name :: string [Read/Write]

The name of this element. "" if no name was set.

Example

game.player.gui.top.greeting.name == "greeting"

caption :: LocalisedString [Read/Write]

The text displayed on this element. For frames, this is the "heading". For other elements, like buttons or labels, this is the content.

Note

Whilst this attribute may be used on all elements without producing an error, it doesn't make sense for tables and flows as they won't display it.


value :: double [Read/Write]

How much this progress bar is filled. It is a value in the range [0, 1].

Can only be used if this is progressbar

direction :: string [Read]

Direction of this element's layout. May be either "horizontal" or "vertical".

Can only be used if this is frame or flow or line

style :: LuaStyle or string [Read/Write]

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.


visible :: boolean [Read/Write]

Sets whether this GUI element is visible or completely hidden, taking no space in the layout.


text :: string [Read/Write]

The text contained in this textfield or text-box.

Can only be used if this is textfield or text-box

children_names :: array[string] [Read]

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.


state :: boolean [Read/Write]

Is this checkbox or radiobutton checked?

Can only be used if this is CheckBox or RadioButton

player_index :: uint [Read]

Index into LuaGameScript::players specifying the player who owns this element.


sprite :: SpritePath [Read/Write]

The image to display on this sprite-button or sprite in the default state.


resize_to_sprite :: boolean [Read/Write]

Whether the image widget should resize according to the sprite in it. Defaults to true.


hovered_sprite :: SpritePath [Read/Write]

The image to display on this sprite-button when it is hovered.

Can only be used if this is sprite-button

clicked_sprite :: SpritePath [Read/Write]

The image to display on this sprite-button when it is clicked.


tooltip :: LocalisedString [Read/Write]


horizontal_scroll_policy :: string [Read/Write]

Policy of the horizontal scroll bar. Possible values are "auto", "never", "always", "auto-and-reserve-space", "dont-show-but-allow-scrolling".

Can only be used if this is scroll-pane

vertical_scroll_policy :: string [Read/Write]

Policy of the vertical scroll bar. Possible values are "auto", "never", "always", "auto-and-reserve-space", "dont-show-but-allow-scrolling".

Can only be used if this is scroll-pane

type :: string [Read]

The type of this GUI element.


children :: array[LuaGuiElement] [Read]

The child-elements of this GUI element.


items :: array[LocalisedString] [Read/Write]

The items in this dropdown or listbox.


selected_index :: uint [Read/Write]

The selected index for this dropdown or listbox. Returns 0 if none is selected.


number :: double [Read/Write]

The number to be shown in the bottom right corner of this sprite-button. Set this to nil to show nothing.


show_percent_for_small_numbers :: boolean [Read/Write]

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.


location :: GuiLocation? [Read/Write]

The location of this widget when stored in LuaGui::screen. nil if not set or not in LuaGui::screen.


auto_center :: boolean [Read/Write]

Whether this frame auto-centers on window resize when stored in LuaGui::screen.

Can only be used if this is frame

badge_text :: LocalisedString [Read/Write]

The text to display after the normal tab text (designed to work with numbers)

Can only be used if this is tab

position :: MapPosition [Read/Write]

The position this camera or minimap is focused on, if any.


surface_index :: uint [Read/Write]

The surface index this camera or minimap is using.


zoom :: double [Read/Write]

The zoom this camera or minimap is using. This value must be positive.


minimap_player_index :: uint [Read/Write]

The player index this minimap is using.

Can only be used if this is minimap

force :: string? [Read/Write]

The force this minimap is using, if any.


elem_type :: string [Read]

The elem type of this choose-elem-button.

Can only be used if this is choose-elem-button

elem_value :: string or SignalID? [Read/Write]

The elem value of this choose-elem-button, if any.

Note

The "signal" type operates with SignalID, while all other types use strings.

Can only be used if this is choose-elem-button

elem_filters :: PrototypeFilter? [Read/Write]

The elem filters of this choose-elem-button, if any. The compatible type of filter is determined by elem_type.

Examples

This will configure a choose-elem-button of type "entity" to only show items of type "furnace".

button.elem_filters = {{filter = "type", type = "furnace"}}

Then, there are some types of filters that work on a specific kind of attribute. The following will configure a choose-elem-button of type "entity" to only show entities that have their "hidden" flags set.

button.elem_filters = {{filter = "hidden"}}

Lastly, these filters can be combined at will, taking care to specify how they should be combined (either "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"}}

Note

Writing to this field does not change or clear the currently selected element.

Can only be used if this is choose-elem-button

selectable :: boolean [Read/Write]

Whether the contents of this text-box are selectable. Defaults to true.

Can only be used if this is text-box

word_wrap :: boolean [Read/Write]

Whether this text-box will word-wrap automatically. Defaults to false.

Can only be used if this is text-box

read_only :: boolean [Read/Write]

Whether this text-box is read-only. Defaults to false.

Can only be used if this is text-box

enabled :: boolean [Read/Write]

Whether this GUI element is enabled. Disabled GUI elements don't trigger events when clicked.


ignored_by_interaction :: boolean [Read/Write]

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.


locked :: boolean [Read/Write]

Whether this choose-elem-button can be changed by the player.

Can only be used if this is choose-elem-button

draw_vertical_lines :: boolean [Read/Write]

Whether this table should draw vertical grid lines.

Can only be used if this is table

draw_horizontal_lines :: boolean [Read/Write]

Whether this table should draw horizontal grid lines.

Can only be used if this is table

draw_horizontal_line_after_headers :: boolean [Read/Write]

Whether this table should draw a horizontal grid line below the first table row.

Can only be used if this is table

column_count :: uint [Read]

The number of columns in this table.

Can only be used if this is table

vertical_centering :: boolean [Read/Write]

Whether the content of this table should be vertically centered. Overrides LuaStyle::column_alignments. Defaults to true.

Can only be used if this is table

slider_value :: double [Read/Write]

The value of this slider element.

Can only be used if this is slider

mouse_button_filter :: MouseButtonFlags [Read/Write]

The mouse button filters for this button or sprite-button.


numeric :: boolean [Read/Write]

Whether this textfield is limited to only numberic characters.

Can only be used if this is textfield

allow_decimal :: boolean [Read/Write]

Whether this textfield (when in numeric mode) allows decimal numbers.

Can only be used if this is textfield

allow_negative :: boolean [Read/Write]

Whether this textfield (when in numeric mode) allows negative numbers.

Can only be used if this is textfield

is_password :: boolean [Read/Write]

Whether this textfield displays as a password field, which renders all characters as *.

Can only be used if this is textfield

lose_focus_on_confirm :: boolean [Read/Write]

Whether this textfield loses focus after defines.events.on_gui_confirmed is fired.

Can only be used if this is textfield

clear_and_focus_on_right_click :: boolean [Read/Write]

Makes it so right-clicking on this textfield clears and focuses it.

Can only be used if this is textfield or text-box

drag_target :: LuaGuiElement? [Read/Write]

The frame that is being moved when dragging this GUI element, if any. This element needs to be a child of the drag_target at some level.

Example

This creates a frame that contains a dragging handle which can move the frame.

local frame = player.gui.screen.add{type="frame", direction="vertical"}
local dragger = frame.add{type="empty-widget", style="draggable_space"}
dragger.style.size = {128, 24}
dragger.drag_target = frame

Note

Only top-level elements in LuaGui::screen can be drag_targets.

Can only be used if this is flow or frame or label or table or empty-widget

selected_tab_index :: uint? [Read/Write]

The selected tab index for this tabbed pane, if any.

Can only be used if this is tabbed-pane

tabs :: array[TabAndContent] [Read]

The tabs and contents being shown in this tabbed-pane.


entity :: LuaEntity? [Read/Write]

The entity associated with this entity-preview, camera, minimap, if any.


anchor :: GuiAnchor? [Read/Write]

The anchor for this relative widget, if any. Setting nil clears the anchor.


tags :: Tags [Read/Write]

The tags associated with this LuaGuiElement.


switch_state :: string [Read/Write]

The switch state (left, none, right) for this switch.

Note

If LuaGuiElement::allow_none_state is false this can't be set to "none".

Can only be used if this is switch

allow_none_state :: boolean [Read/Write]

Whether the "none" state is allowed for this switch.

Note

This can't be set to false if the current switch_state is 'none'.

Can only be used if this is switch

left_label_caption :: LocalisedString [Read/Write]

The text shown for the left switch label.

Can only be used if this is switch

left_label_tooltip :: LocalisedString [Read/Write]

The tooltip shown on the left switch label.

Can only be used if this is switch

right_label_caption :: LocalisedString [Read/Write]

The text shown for the right switch label.

Can only be used if this is switch

right_label_tooltip :: LocalisedString [Read/Write]

The tooltip shown on the right switch label.

Can only be used if this is switch

valid :: boolean [Read]

Is this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be false. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.


object_name :: string [Read]

The class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.

Operators

[] (index)

The indexing operator. Gets children by name.

|<

Classes

Events

Concepts

Defines

Builtin types

>|