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¶
@param ui GenericUI_Instance
@param id string
@param parent GenericUI_Element|string
@param style GenericUI_Prefab_Button_Style
GetIconElement¶
Returns the icon element, if any.
GetLabelElement¶
Returns the label element.
GetRootElement¶
@override
IsActivated¶
Returns whether the button is activated.
Will throw if the button is not a state button.
IsEnabled¶
Returns whether the button is enabled.
Disabled buttons do not fire the Pressed event.
SetActivated¶
Sets the activated state of the button.
Will throw if the button is not a state button.
@param activated any
SetActiveStyle¶
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¶
Sets the enabled state of the button.
@param enabled boolean
SetIcon¶
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¶
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¶
Sets the tooltip of the element.
@param type TooltipLib_TooltipType
@param tooltip any
TODO document
__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.