2025-03-18 22:00:51 +02:00

6.2 KiB

druid.button API

at /druid/base/button.lua

Druid component to make clickable node with various interaction callbacks

Functions

Fields

init


button:init(node_or_node_id, [callback], [custom_args], [anim_node])

The constructor for the button component

  • Parameters:
    • node_or_node_id (string|node): Node name or GUI Node itself
    • [callback] (fun()|nil): Callback on button click
    • [custom_args] (any): Custom args for any Button event
    • [anim_node] (string|node|nil): Node to animate instead of trigger node

set_animations_disabled


button:set_animations_disabled()

Remove default button style animations

  • Returns:
    • self (druid.button): The current button instance

set_enabled


button:set_enabled([state])

Set button enabled state. The style.on_set_enabled will be triggered. Disabled button is not clickable.

  • Parameters:

    • [state] (boolean|nil): Enabled state
  • Returns:

    • self (druid.button): The current button instance

is_enabled


button:is_enabled()

Get button enabled state. By default all Buttons is enabled on creating.

  • Returns:
    • is_enabled (boolean): True, if button is enabled now, False overwise

set_click_zone


button:set_click_zone([zone])

Set additional button click area. Useful to restrict click outside out stencil node or scrollable content. If button node placed inside stencil node, it will be automatically set to this stencil node.

  • Parameters:

    • [zone] (string|node|nil): Gui node
  • Returns:

    • self (druid.button): The current button instance

set_key_trigger


button:set_key_trigger(key)

Set key name to trigger this button by keyboard.

  • Parameters:

    • key (string|hash): The action_id of the input key. Example: "key_space"
  • Returns:

    • self (druid.button): The current button instance

get_key_trigger


button:get_key_trigger()

Get current key name to trigger this button.

  • Returns:
    • key_trigger (hash): The action_id of the input key

set_check_function


button:set_check_function([check_function], [failure_callback])

Set function for additional check for button click availability

  • Parameters:

    • [check_function] (function|nil): Should return true or false. If true - button can be pressed.
    • [failure_callback] (function|nil): Function will be called on button click, if check function return false
  • Returns:

    • self (druid.button): The current button instance

set_web_user_interaction


button:set_web_user_interaction([is_web_mode])

Set Button mode to work inside user HTML5 interaction event. It's required to make protected things like copy & paste text, show mobile keyboard, etc The HTML5 button's doesn't call any events except on_click event. If the game is not HTML, html mode will be not enabled

  • Parameters:

    • [is_web_mode] (boolean|nil): If true - button will be called inside html5 callback
  • Returns:

    • self (druid.button): The current button instance

Fields

  • on_click (event): function(self, custom_args, button_instance)

  • on_pressed (event): function(self, custom_args, button_instance)

  • on_repeated_click (event): function(self, custom_args, button_instance, click_count)

  • on_long_click (event): function(self, custom_args, button_instance, hold_time)

  • on_double_click (event): function(self, custom_args, button_instance, click_amount)

  • on_hold_callback (event): function(self, custom_args, button_instance, press_time)

  • on_click_outside (event): function(self, custom_args, button_instance)

  • node (node): Clickable node

  • node_id (hash): Node id

  • anim_node (node): Animation node. In default case equals to clickable node

  • params (any): Custom arguments for any Button event

  • hover (druid.hover): Hover component for this button

  • click_zone (node): Click zone node to restrict click area

  • start_scale (vector3): Start scale of the button

  • start_pos (vector3): Start position of the button

  • disabled (boolean): Is button disabled

  • key_trigger (hash): Key trigger for this button

  • style (table): Style for this button

  • druid (druid.instance): The Druid Factory used to create components

  • is_repeated_started (boolean)

  • last_pressed_time (integer)

  • last_released_time (integer)

  • click_in_row (integer)

  • can_action (boolean): Can't interact, if touch outside of button