2025-03-14 20:29:05 +02:00

6.5 KiB

druid.input API

at /druid/extended/input.lua

Functions

Fields

init


input:init(click_node, text_node, [keyboard_type])
  • Parameters:
    • click_node (node): Node to enabled input component
    • text_node (druid.text|node): Text node what will be changed on user input. You can pass text component instead of text node name Text
    • [keyboard_type] (number|nil): Gui keyboard type for input field

on_style_change


input:on_style_change(style)
  • Parameters:
    • style (druid.input.style):

on_input


input:on_input([action_id], [action])
  • Parameters:

    • [action_id] (any):
    • [action] (any):
  • Returns:

    • `` (boolean):

on_focus_lost


input:on_focus_lost()

on_input_interrupt


input:on_input_interrupt()

get_text_selected


input:get_text_selected()
  • Returns:
    • `` (string|unknown):

get_text_selected_replaced


input:get_text_selected_replaced(text)

Replace selected text with new text

  • Parameters:

    • text (string): The text to replace selected text
  • Returns:

    • New (string): input text

set_text


input:set_text(input_text)

Set text for input field

  • Parameters:
    • input_text (string): The string to apply for input field

select


input:select()

Select input field. It will show the keyboard and trigger on_select events

unselect


input:unselect()

Remove selection from input. It will hide the keyboard and trigger on_unselect events

get_text


input:get_text()

Return current input field text

  • Returns:
    • The (string): current input field text

set_max_length


input:set_max_length(max_length)

Set maximum length for input field. Pass nil to make input field unliminted (by default)

  • Parameters:

    • max_length (number): Maximum length for input text field
  • Returns:

    • Current (druid.input): input instance

set_allowed_characters


input:set_allowed_characters(characters)

Set allowed charaters for input field. See: https://defold.com/ref/stable/string/ ex: [%a%d] for alpha and numeric

  • Parameters:

    • characters (string): Regulax exp. for validate user input
  • Returns:

    • Current (druid.input): input instance

reset_changes


input:reset_changes()

Reset current input selection and return previous value

  • Returns:
    • Current (druid.input): input instance

select_cursor


input:select_cursor([cursor_index], [start_index], [end_index])

Set cursor position in input field

  • Parameters:

    • [cursor_index] (number|nil): Cursor index for cursor position, if nil - will be set to the end of the text
    • [start_index] (number|nil): Start index for cursor position, if nil - will be set to the end of the text
    • [end_index] (number|nil): End index for cursor position, if nil - will be set to the start_index
  • Returns:

    • Current (druid.input): input instance

move_selection


input:move_selection(delta, is_add_to_selection, is_move_to_end)

Change cursor position by delta

  • Parameters:
    • delta (number): side for cursor position, -1 for left, 1 for right
    • is_add_to_selection (boolean): (Shift key)
    • is_move_to_end (boolean): (Ctrl key)

Fields

  • on_input_select (event)

  • on_input_unselect (event)

  • on_input_text (event)

  • on_input_empty (event)

  • on_input_full (event)

  • on_input_wrong (event)

  • on_select_cursor_change (event)

  • style (table)

  • text (druid.text)

  • ALLOWED_ACTIONS (table)

  • druid (druid.instance)

  • is_selected (boolean)

  • value (unknown)

  • previous_value (unknown)

  • current_value (unknown)

  • marked_value (string)

  • is_empty (boolean)

  • text_width (integer)

  • market_text_width (integer)

  • total_width (integer)

  • cursor_index (integer)

  • start_index (number)

  • end_index (number)

  • max_length (nil)

  • allowed_characters (nil)

  • keyboard_type (number)

  • button (druid.button): Druid component to make clickable node with various interaction callbacks

  • marked_text_width (number)