pub struct LuaGuiElement;Expand description
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.
For information on all supported GUI elements, see GuiElementType.
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.
Implementations§
Source§impl LuaGuiElement
impl LuaGuiElement
Sourcepub fn allow_decimal(&self) -> bool
pub fn allow_decimal(&self) -> bool
Whether this textfield (when in numeric mode) allows decimal numbers.
Sourcepub fn allow_negative(&self) -> bool
pub fn allow_negative(&self) -> bool
Whether this textfield (when in numeric mode) allows negative numbers.
Sourcepub fn allow_none_state(&self) -> bool
pub fn allow_none_state(&self) -> bool
Whether the "none" state is allowed for this switch.
This can’t be set to false if the current switch_state is ‘none’.
Sourcepub fn anchor(&self) -> GuiAnchor
pub fn anchor(&self) -> GuiAnchor
The anchor for this relative widget, if any. Setting nil clears the anchor.
Sourcepub fn auto_center(&self) -> bool
pub fn auto_center(&self) -> bool
Whether this frame auto-centers on window resize when stored in LuaGui::screen.
Sourcepub fn auto_toggle(&self) -> bool
pub fn auto_toggle(&self) -> bool
Whether this button will automatically toggle when clicked.
Sourcepub fn badge_text(&self) -> &str
pub fn badge_text(&self) -> &str
The text to display after the normal tab text (designed to work with numbers)
Sourcepub fn caption(&self) -> &str
pub fn caption(&self) -> &str
The text displayed on this element. For frames, this is the “heading”. For other elements, like buttons or labels, this is the content.
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.
Sourcepub fn children(&self) -> Vec<LuaGuiElement>
pub fn children(&self) -> Vec<LuaGuiElement>
The child-elements of this GUI element.
Sourcepub fn children_names(&self) -> Vec<&str>
pub fn children_names(&self) -> Vec<&str>
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.
Sourcepub fn clicked_sprite(&self) -> SpritePath
pub fn clicked_sprite(&self) -> SpritePath
The sprite to display on this sprite-button when it is clicked.
Sourcepub fn column_count(&self) -> u32
pub fn column_count(&self) -> u32
The number of columns in this table.
Sourcepub fn direction(&self) -> GuiDirection
pub fn direction(&self) -> GuiDirection
Direction of this element’s layout.
Sourcepub fn drag_target(&self) -> LuaGuiElement
pub fn drag_target(&self) -> LuaGuiElement
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.
Only top-level elements in LuaGui::screen can be drag_targets.
Sourcepub fn draw_horizontal_line_after_headers(&self) -> bool
pub fn draw_horizontal_line_after_headers(&self) -> bool
Whether this table should draw a horizontal grid line below the first table row.
Sourcepub fn draw_horizontal_lines(&self) -> bool
pub fn draw_horizontal_lines(&self) -> bool
Whether this table should draw horizontal grid lines.
Sourcepub fn draw_vertical_lines(&self) -> bool
pub fn draw_vertical_lines(&self) -> bool
Whether this table should draw vertical grid lines.
Sourcepub fn elem_filters(&self) -> LuaAny
pub fn elem_filters(&self) -> LuaAny
The elem filters of this choose-elem-button, if any. The compatible type of filter is determined by elem_type.
Writing to this field does not change or clear the currently selected element.
Sourcepub fn elem_tooltip(&self) -> ElemID
pub fn elem_tooltip(&self) -> ElemID
The element tooltip to display when hovering over this element, or nil.
Sourcepub fn elem_value(&self) -> LuaAny
pub fn elem_value(&self) -> LuaAny
The elem value of this choose-elem-button, if any.
The "signal" type operates with SignalID.
The "with-quality" types operate with PrototypeWithQuality.
The remaining types use strings.
pub fn empty_slot_info(&self) -> EmptySlotInfo
Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Whether this GUI element is enabled. Disabled GUI elements don’t trigger events when clicked.
Sourcepub fn entity(&self) -> LuaEntity
pub fn entity(&self) -> LuaEntity
The entity associated with this entity-preview, camera, minimap, if any.
Sourcepub fn game_controller_interaction(&self) -> &str
pub fn game_controller_interaction(&self) -> &str
How this element should interact with game controllers.
pub fn handle_cursor_split(&self) -> bool
pub fn handle_cursor_transfer(&self) -> bool
pub fn handle_open_item(&self) -> bool
pub fn handle_open_mod_item(&self) -> bool
pub fn handle_send_stack_to_trash(&self) -> bool
pub fn handle_send_stacks_to_trash(&self) -> bool
Sourcepub fn horizontal_scroll_policy(&self) -> ScrollPolicy
pub fn horizontal_scroll_policy(&self) -> ScrollPolicy
Policy of the horizontal scroll bar.
Sourcepub fn hovered_sprite(&self) -> SpritePath
pub fn hovered_sprite(&self) -> SpritePath
The sprite to display on this sprite-button when it is hovered.
Sourcepub fn icon_selector(&self) -> bool
pub fn icon_selector(&self) -> bool
Whether this textfield or text-box was created with an icon selector.
Sourcepub fn ignored_by_interaction(&self) -> bool
pub fn ignored_by_interaction(&self) -> bool
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.
Sourcepub fn index(&self) -> u32
pub fn index(&self) -> u32
The index of this GUI element (unique amongst the GUI elements of a LuaPlayer).
Sourcepub fn inventory(&self) -> LuaInventory
pub fn inventory(&self) -> LuaInventory
The inventory target for this custom inventory widget.
Sourcepub fn is_password(&self) -> bool
pub fn is_password(&self) -> bool
Whether this textfield displays as a password field, which renders all characters as *.
Sourcepub fn left_label_caption(&self) -> &str
pub fn left_label_caption(&self) -> &str
The text shown for the left switch label.
Sourcepub fn left_label_tooltip(&self) -> &str
pub fn left_label_tooltip(&self) -> &str
The tooltip shown on the left switch label.
Sourcepub fn location(&self) -> GuiLocation
pub fn location(&self) -> GuiLocation
The location of this widget when stored in LuaGui::screen. nil if not set or not in LuaGui::screen.
Sourcepub fn lose_focus_on_confirm(&self) -> bool
pub fn lose_focus_on_confirm(&self) -> bool
Whether this textfield loses focus after defines.events.on_gui_confirmed is fired.
Sourcepub fn minimap_player_index(&self) -> u32
pub fn minimap_player_index(&self) -> u32
The player index this minimap is using.
The mouse button filters for this button or sprite-button.
Sourcepub fn number(&self) -> f64
pub fn number(&self) -> f64
The number to be shown in the bottom right corner of this sprite-button, or nil to show nothing.
Sourcepub fn object_name(&self) -> &str
pub fn object_name(&self) -> &str
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.
Sourcepub fn parent(&self) -> LuaGuiElement
pub fn parent(&self) -> LuaGuiElement
The direct parent of this element. nil if this is a top-level element.
Sourcepub fn player_index(&self) -> u32
pub fn player_index(&self) -> u32
Index into LuaGameScript::players specifying the player who owns this element.
Sourcepub fn position(&self) -> MapPosition
pub fn position(&self) -> MapPosition
The position this camera or minimap is focused on, if any.
Sourcepub fn quality(&self) -> LuaQualityPrototype
pub fn quality(&self) -> LuaQualityPrototype
The quality to be shown in the bottom left corner of this sprite-button, or nil to show nothing.
Sourcepub fn raise_hover_events(&self) -> bool
pub fn raise_hover_events(&self) -> bool
Whether this element will raise on_gui_hover and on_gui_leave.
Sourcepub fn resize_to_sprite(&self) -> bool
pub fn resize_to_sprite(&self) -> bool
Whether the sprite widget should resize according to the sprite in it. Defaults to true.
Sourcepub fn right_label_caption(&self) -> &str
pub fn right_label_caption(&self) -> &str
The text shown for the right switch label.
Sourcepub fn right_label_tooltip(&self) -> &str
pub fn right_label_tooltip(&self) -> &str
The tooltip shown on the right switch label.
Sourcepub fn selectable(&self) -> bool
pub fn selectable(&self) -> bool
Whether the contents of this text-box are selectable. Defaults to true.
Sourcepub fn selected_index(&self) -> u32
pub fn selected_index(&self) -> u32
The selected index for this dropdown or listbox. Returns 0 if none is selected.
Sourcepub fn selected_tab_index(&self) -> u32
pub fn selected_tab_index(&self) -> u32
The selected tab index for this tabbed pane, if any.
Sourcepub fn show_percent_for_small_numbers(&self) -> bool
pub fn show_percent_for_small_numbers(&self) -> bool
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.
Sourcepub fn slider_value(&self) -> f64
pub fn slider_value(&self) -> f64
The value of this slider element.
pub fn slots_per_row(&self) -> u8
Sourcepub fn sprite(&self) -> SpritePath
pub fn sprite(&self) -> SpritePath
The sprite to display on this sprite-button or sprite in the default state.
Sourcepub fn surface_index(&self) -> u32
pub fn surface_index(&self) -> u32
The surface index this camera or minimap is using.
Sourcepub fn switch_state(&self) -> SwitchState
pub fn switch_state(&self) -> SwitchState
The switch state for this switch.
If LuaGuiElement::allow_none_state is false this can’t be set to "none".
Sourcepub fn tabs(&self) -> Vec<TabAndContent>
pub fn tabs(&self) -> Vec<TabAndContent>
The tabs and contents being shown in this tabbed-pane.
The tags associated with this LuaGuiElement.
Sourcepub fn toggled(&self) -> bool
pub fn toggled(&self) -> bool
Whether this button is currently toggled. When a button is toggled, it will use the selected_graphical_set and selected_font_color defined in its style.
Sourcepub fn tooltip(&self) -> &str
pub fn tooltip(&self) -> &str
The text to display when hovering over this element. Writing "" or nil will disable the tooltip.
Sourcepub fn type(&self) -> GuiElementType
pub fn type(&self) -> GuiElementType
The type of this GUI element.
Sourcepub fn valid(&self) -> bool
pub fn valid(&self) -> bool
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.
Sourcepub fn value(&self) -> f64
pub fn value(&self) -> f64
How much this progress bar is filled. It is a value in the range [0, 1].
Sourcepub fn vertical_centering(&self) -> bool
pub fn vertical_centering(&self) -> bool
Whether the content of this table should be vertically centered. Overrides LuaStyle::column_alignments. Defaults to true.
Sourcepub fn vertical_scroll_policy(&self) -> ScrollPolicy
pub fn vertical_scroll_policy(&self) -> ScrollPolicy
Policy of the vertical scroll bar.
Sourcepub fn visible(&self) -> bool
pub fn visible(&self) -> bool
Sets whether this GUI element is visible or completely hidden, taking no space in the layout.
Sourcepub fn word_wrap(&self) -> bool
pub fn word_wrap(&self) -> bool
Whether this text-box will word-wrap automatically. Defaults to false.
Sourcepub fn zoom(&self) -> f64
pub fn zoom(&self) -> f64
The zoom this camera or minimap is using. This value must be positive.
Sourcepub fn add(&self, params: LuaGuiElementAddParams) -> LuaGuiElement
pub fn add(&self, params: LuaGuiElementAddParams) -> LuaGuiElement
Add a new child element to this GuiElement.
Sourcepub fn add_item(&self, index: Option<u32>, string: &str)
pub fn add_item(&self, index: Option<u32>, string: &str)
Inserts a string at the end or at the given index of this dropdown or listbox.
Sourcepub fn add_tab(&self, content: LuaGuiElement, tab: LuaGuiElement)
pub fn add_tab(&self, content: LuaGuiElement, tab: LuaGuiElement)
Adds the given tab and content widgets to this tabbed pane as a new tab.
Sourcepub fn bring_to_front(&self)
pub fn bring_to_front(&self)
Moves this GUI element to the “front” so it will draw over other elements.
Only works for elements in LuaGui::screen.
Sourcepub fn clear(&self)
pub fn clear(&self)
Remove children of this element. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.
Sourcepub fn clear_items(&self)
pub fn clear_items(&self)
Removes the items in this dropdown or listbox.
Sourcepub fn close_dropdown(&self)
pub fn close_dropdown(&self)
Closes the dropdown list if this is a dropdown and it is open.
Sourcepub fn destroy(&self)
pub fn destroy(&self)
Remove this element, along with its children. Any LuaGuiElement objects referring to the destroyed elements become invalid after this operation.
The top-level GUI elements - LuaGui::top, LuaGui::left, LuaGui::center and LuaGui::screen - can’t be destroyed.
Sourcepub fn force_auto_center(&self)
pub fn force_auto_center(&self)
Forces this frame to re-auto-center. Only works on frames stored directly in LuaGui::screen.
Sourcepub fn get_index_in_parent(&self) -> u32
pub fn get_index_in_parent(&self) -> u32
Gets the index that this element has in its parent element.
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.
Sourcepub fn get_item(&self, index: u32) -> &str
pub fn get_item(&self, index: u32) -> &str
Gets the item at the given index from this dropdown or listbox.
Sourcepub fn get_mod(&self) -> Option<&str>
pub fn get_mod(&self) -> Option<&str>
The mod that owns this Gui element or nil if it’s owned by the scenario script.
This has a not-super-expensive, but non-free cost to get.
Sourcepub fn get_slider_discrete_values(&self) -> bool
pub fn get_slider_discrete_values(&self) -> bool
Returns whether this slider only allows discrete values.
Sourcepub fn get_slider_maximum(&self) -> f64
pub fn get_slider_maximum(&self) -> f64
Gets this sliders maximum value.
Sourcepub fn get_slider_minimum(&self) -> f64
pub fn get_slider_minimum(&self) -> f64
Gets this sliders minimum value.
Sourcepub fn get_slider_value_step(&self) -> f64
pub fn get_slider_value_step(&self) -> f64
Gets the minimum distance this slider can move.
Sourcepub fn remove_item(&self, index: u32)
pub fn remove_item(&self, index: u32)
Removes the item at the given index from this dropdown or listbox.
Sourcepub fn remove_tab(&self, tab: Option<LuaGuiElement>)
pub fn remove_tab(&self, tab: Option<LuaGuiElement>)
Removes the given tab and its associated content from this tabbed pane.
Removing a tab does not destroy the tab or the tab contents. It just removes them from the view.
Sourcepub fn scroll_to_bottom(&self)
pub fn scroll_to_bottom(&self)
Scrolls this scroll bar to the bottom.
Sourcepub fn scroll_to_element(
&self,
element: LuaGuiElement,
scroll_mode: Option<LuaGuiElementScrollMode>,
)
pub fn scroll_to_element( &self, element: LuaGuiElement, scroll_mode: Option<LuaGuiElementScrollMode>, )
Scrolls this scroll bar such that the specified GUI element is visible to the player.
Sourcepub fn scroll_to_item(
&self,
index: i32,
scroll_mode: Option<LuaGuiElementScrollMode>,
)
pub fn scroll_to_item( &self, index: i32, scroll_mode: Option<LuaGuiElementScrollMode>, )
Scrolls the scroll bar such that the specified listbox item is visible to the player.
Sourcepub fn scroll_to_left(&self)
pub fn scroll_to_left(&self)
Scrolls this scroll bar to the left.
Sourcepub fn scroll_to_right(&self)
pub fn scroll_to_right(&self)
Scrolls this scroll bar to the right.
Sourcepub fn scroll_to_top(&self)
pub fn scroll_to_top(&self)
Scrolls this scroll bar to the top.
Sourcepub fn select(&self, end_index: i32, start_index: i32)
pub fn select(&self, end_index: i32, start_index: i32)
Selects a range of text in this textbox.
Sourcepub fn select_all(&self)
pub fn select_all(&self)
Selects all the text in this textbox.
Sourcepub fn set_item(&self, index: u32, string: &str)
pub fn set_item(&self, index: u32, string: &str)
Sets the given string at the given index in this dropdown or listbox.
Sourcepub fn set_slider_discrete_values(&self, value: bool)
pub fn set_slider_discrete_values(&self, value: bool)
Sets whether this slider only allows discrete values.
Sourcepub fn set_slider_minimum_maximum(&self, maximum: f64, minimum: f64)
pub fn set_slider_minimum_maximum(&self, maximum: f64, minimum: f64)
Sets this sliders minimum and maximum values. The minimum can’t be >= the maximum.
Sourcepub fn set_slider_value_step(&self, value: f64)
pub fn set_slider_value_step(&self, value: f64)
Sets the minimum distance this slider can move. The minimum distance can’t be > (max - min).
Sourcepub fn swap_children(&self, index_1: u32, index_2: u32)
pub fn swap_children(&self, index_1: u32, index_2: u32)
Swaps the children at the given indices in this element.
Trait Implementations§
Source§impl Clone for LuaGuiElement
impl Clone for LuaGuiElement
Source§fn clone(&self) -> LuaGuiElement
fn clone(&self) -> LuaGuiElement
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more