Skip to main content

LuaGuiElement

Struct LuaGuiElement 

Source
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

Source

pub fn allow_decimal(&self) -> bool

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

Source

pub fn allow_negative(&self) -> bool

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

Source

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

Source

pub fn anchor(&self) -> GuiAnchor

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

Source

pub fn auto_center(&self) -> bool

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

Source

pub fn auto_toggle(&self) -> bool

Whether this button will automatically toggle when clicked.

Source

pub fn badge_text(&self) -> &str

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

Source

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.

Source

pub fn children(&self) -> Vec<LuaGuiElement>

The child-elements of this GUI element.

Source

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.

Source

pub fn clicked_sprite(&self) -> SpritePath

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

Source

pub fn column_count(&self) -> u32

The number of columns in this table.

Source

pub fn direction(&self) -> GuiDirection

Direction of this element’s layout.

Source

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.

Source

pub fn draw_horizontal_line_after_headers(&self) -> bool

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

Source

pub fn draw_horizontal_lines(&self) -> bool

Whether this table should draw horizontal grid lines.

Source

pub fn draw_vertical_lines(&self) -> bool

Whether this table should draw vertical grid lines.

Source

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.

Source

pub fn elem_tooltip(&self) -> ElemID

The element tooltip to display when hovering over this element, or nil.

Source

pub fn elem_type(&self) -> ElemType

The elem type of this choose-elem-button.

Source

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.

Source

pub fn empty_slot_info(&self) -> EmptySlotInfo

Source

pub fn enabled(&self) -> bool

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

Source

pub fn entity(&self) -> LuaEntity

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

Source

pub fn force(&self) -> &str

The force this minimap is using, if any.

Source

pub fn game_controller_interaction(&self) -> &str

How this element should interact with game controllers.

Source

pub fn gui(&self) -> LuaGui

The GUI this element is a child of.

Source

pub fn handle_cursor_split(&self) -> bool

Source

pub fn handle_cursor_transfer(&self) -> bool

Source

pub fn handle_open_item(&self) -> bool

Source

pub fn handle_open_mod_item(&self) -> bool

Source

pub fn handle_send_stack_to_trash(&self) -> bool

Source

pub fn handle_send_stacks_to_trash(&self) -> bool

Source

pub fn horizontal_scroll_policy(&self) -> ScrollPolicy

Policy of the horizontal scroll bar.

Source

pub fn hovered_sprite(&self) -> SpritePath

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

Source

pub fn icon_selector(&self) -> bool

Whether this textfield or text-box was created with an icon selector.

Source

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.

Source

pub fn index(&self) -> u32

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

Source

pub fn inventory(&self) -> LuaInventory

The inventory target for this custom inventory widget.

Source

pub fn is_password(&self) -> bool

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

Source

pub fn items(&self) -> Vec<&str>

The items in this dropdown or listbox.

Source

pub fn left_label_caption(&self) -> &str

The text shown for the left switch label.

Source

pub fn left_label_tooltip(&self) -> &str

The tooltip shown on the left switch label.

Source

pub fn location(&self) -> GuiLocation

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

Source

pub fn locked(&self) -> bool

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

Source

pub fn lose_focus_on_confirm(&self) -> bool

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

Source

pub fn minimap_player_index(&self) -> u32

The player index this minimap is using.

Source

pub fn mouse_button_filter(&self) -> LuaAny

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

Source

pub fn name(&self) -> &str

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

Source

pub fn number(&self) -> f64

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

Source

pub fn numeric(&self) -> bool

Whether this textfield is limited to only numeric characters.

Source

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.

Source

pub fn parent(&self) -> LuaGuiElement

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

Source

pub fn player_index(&self) -> u32

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

Source

pub fn position(&self) -> MapPosition

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

Source

pub fn quality(&self) -> LuaQualityPrototype

The quality to be shown in the bottom left corner of this sprite-button, or nil to show nothing.

Source

pub fn raise_hover_events(&self) -> bool

Whether this element will raise on_gui_hover and on_gui_leave.

Source

pub fn read_only(&self) -> bool

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

Source

pub fn resize_to_sprite(&self) -> bool

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

Source

pub fn right_label_caption(&self) -> &str

The text shown for the right switch label.

Source

pub fn right_label_tooltip(&self) -> &str

The tooltip shown on the right switch label.

Source

pub fn selectable(&self) -> bool

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

Source

pub fn selected_index(&self) -> u32

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

Source

pub fn selected_tab_index(&self) -> u32

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

Source

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.

Source

pub fn slider_value(&self) -> f64

The value of this slider element.

Source

pub fn slots_per_row(&self) -> u8

Source

pub fn sprite(&self) -> SpritePath

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

Source

pub fn state(&self) -> bool

Is this checkbox or radiobutton checked?

Source

pub fn style(&self) -> LuaAny

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.

When writing, this clears all custom values set through LuaStyle.

Source

pub fn surface_index(&self) -> u32

The surface index this camera or minimap is using.

Source

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

Source

pub fn tabs(&self) -> Vec<TabAndContent>

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

Source

pub fn tags(&self) -> LuaAny

The tags associated with this LuaGuiElement.

Source

pub fn text(&self) -> &str

The text contained in this textfield or text-box.

Source

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.

Source

pub fn tooltip(&self) -> &str

The text to display when hovering over this element. Writing "" or nil will disable the tooltip.

Source

pub fn type(&self) -> GuiElementType

The type of this GUI element.

Source

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.

Source

pub fn value(&self) -> f64

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

Source

pub fn vertical_centering(&self) -> bool

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

Source

pub fn vertical_scroll_policy(&self) -> ScrollPolicy

Policy of the vertical scroll bar.

Source

pub fn visible(&self) -> bool

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

Source

pub fn word_wrap(&self) -> bool

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

Source

pub fn zoom(&self) -> f64

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

Source

pub fn add(&self, params: LuaGuiElementAddParams) -> LuaGuiElement

Add a new child element to this GuiElement.

Source

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.

Source

pub fn add_tab(&self, content: LuaGuiElement, tab: LuaGuiElement)

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

Source

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.

Source

pub fn clear(&self)

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

Source

pub fn clear_items(&self)

Removes the items in this dropdown or listbox.

Source

pub fn close_dropdown(&self)

Closes the dropdown list if this is a dropdown and it is open.

Source

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.

Source

pub fn focus(&self)

Focuses this GUI element if possible.

Source

pub fn force_auto_center(&self)

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

Source

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.

Source

pub fn get_item(&self, index: u32) -> &str

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

Source

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.

Source

pub fn get_slider_discrete_values(&self) -> bool

Returns whether this slider only allows discrete values.

Source

pub fn get_slider_maximum(&self) -> f64

Gets this sliders maximum value.

Source

pub fn get_slider_minimum(&self) -> f64

Gets this sliders minimum value.

Source

pub fn get_slider_value_step(&self) -> f64

Gets the minimum distance this slider can move.

Source

pub fn remove_item(&self, index: u32)

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

Source

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.

Source

pub fn scroll_to_bottom(&self)

Scrolls this scroll bar to the bottom.

Source

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.

Source

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.

Source

pub fn scroll_to_left(&self)

Scrolls this scroll bar to the left.

Source

pub fn scroll_to_right(&self)

Scrolls this scroll bar to the right.

Source

pub fn scroll_to_top(&self)

Scrolls this scroll bar to the top.

Source

pub fn select(&self, end_index: i32, start_index: i32)

Selects a range of text in this textbox.

Source

pub fn select_all(&self)

Selects all the text in this textbox.

Source

pub fn set_item(&self, index: u32, string: &str)

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

Source

pub fn set_slider_discrete_values(&self, value: bool)

Sets whether this slider only allows discrete values.

Source

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.

Source

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

Source

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

Source§

fn clone(&self) -> LuaGuiElement

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LuaGuiElement

Source§

impl Debug for LuaGuiElement

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LuaGuiElement

Source§

fn default() -> LuaGuiElement

Returns the “default value” for a type. Read more
Source§

impl Eq for LuaGuiElement

Source§

impl From<LuaGuiElement> for LuaAny

Source§

fn from(_: LuaGuiElement) -> Self

Converts to this type from the input type.
Source§

impl LuaObject for LuaGuiElement

Source§

impl PartialEq for LuaGuiElement

Source§

fn eq(&self, other: &LuaGuiElement) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LuaGuiElement

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.