Skip to content

Button

The GenericUI_Prefab_Button prefab implements a button; an element that can be clicked and visually reacts to user interaction.

This prefab is intended to replace the built-in Button and StateButton elements. It's major advantage is easier styling and maintainability, as there is no flash code directly involved.

Buttons implement I_Stylable, which allows customizing their group of textures and other visual assets to use. Styles can be registered via :RegisterStyle() and fetched using :GetStyle().

StateButtons (buttons that toggle between active/inactive states) are created by supplying and additional style to use for the active state, via :SetActiveStyle().

Epip has many premade button styles. You may browse them via GenericUITextures UI.

The button prefab additionally supports adding an IggyIcon to it with :SetIcon().

GenericUI_Prefab_Button Class

Inherits from GenericUI_Prefab, GenericUI_I_Stylable, GenericUI_I_Elementable.

Prefab for a button.

Events and Hooks

Pressed (event)

Fires only if the button is enabled.

RightClicked (event)

Fires even if the button is disabled.

Methods

Create
function GenericUI_Prefab_Button.Create(ui, id, parent, style)
   -> GenericUI_Prefab_Button

@param ui GenericUI_Instance

@param id string

@param parent GenericUI_Element|string

@param style GenericUI_Prefab_Button_Style

GetIconElement
function GenericUI_Prefab_Button:GetIconElement()
   -> GenericUI_Element_IggyIcon?

Returns the icon element, if any.

GetLabelElement
function GenericUI_Prefab_Button:GetLabelElement()
   -> GenericUI_Prefab_Text

Returns the label element.

GetRootElement
function GenericUI_Prefab_Button:GetRootElement()

@override

IsActivated
function GenericUI_Prefab_Button:IsActivated()
   -> boolean

Returns whether the button is activated.

Will throw if the button is not a state button.

IsEnabled
function GenericUI_Prefab_Button:IsEnabled()
   -> boolean

Returns whether the button is enabled.

Disabled buttons do not fire the Pressed event.

SetActivated
function GenericUI_Prefab_Button:SetActivated(activated)

Sets the activated state of the button.

Will throw if the button is not a state button.

@param activated any

SetActiveStyle
function GenericUI_Prefab_Button:SetActiveStyle(style)

Sets a style to be used while the button is active.

This cannot be used to revert the button to a normal one if it was already a state button.

@param style GenericUI_Prefab_Button_Style If background fields are not assigned, the normal style will be used as fallback.

SetEnabled
function GenericUI_Prefab_Button:SetEnabled(enabled)

Sets the enabled state of the button.

@param enabled boolean

SetIcon
function GenericUI_Prefab_Button:SetIcon(icon, size, relativePosition, offset)

Sets an icon for the button.

@param icon icon

@param size Vector2

@param relativePosition GenericUI_Element_RelativePosition? Defaults to `"Center"`.

@param offset Vector2? Defaults to `(0, 0)`.

SetLabel
function GenericUI_Prefab_Button:SetLabel(label, align)

Sets the label of the button.

@param label TextLib_String Set to an empty string to hide the label.

@param align GenericUI_Element_Text_Align? Defaults to `"Center"`.

SetTooltip
function GenericUI_Prefab_Button:SetTooltip(type, tooltip)

Sets the tooltip of the element.

@param type TooltipLib_TooltipType

@param tooltip any TODO document

__OnStyleChanged
---@protected
function GenericUI_Prefab_Button:__OnStyleChanged()

@override

GenericUI_Prefab_Button_Style Class

Inherits from GenericUI_I_Stylable_Style.

@field IdleTexture TextureLib_Texture

@field HighlightedTexture TextureLib_Texture If not present, `IdleTexture` will be used instead.

@field PressedTexture TextureLib_Texture? If not present, `IdleTexture` will be used instead.

@field DisabledTexture TextureLib_Texture? If not present, `IdleTexture` will be used instead.

@field Size Vector2? Defaults to texture size.

@field Sound string? Sound effect to play when the button is pressed. Defaults to `DEFAULT_SOUND`.

@field IdleOverlay TextureLib_Texture?

@field HighlightedOverlay TextureLib_Texture? If not present, `IdleOverlay` will be used instead.

@field PressedOverlay TextureLib_Texture? If not present, `IdleOverlay` will be used instead.

@field PressedLabelYOffset number? Position offset to apply to the label while in the pressed state.

Methods