Txt field add
Jump to navigation
Jump to search
Description
txt_field_id = txt_field_add(txt,style,x,y,width,height,callback)'
txt_field_add is used to add a text field on the specified location. The text field offers the user a way to input text from a keyboard.
Return value
Argument | Type | Description |
---|---|---|
txt_field_id | String | This value can be used for further reference. It's good practice to store this txt_field_id in your logic code. |
Arguments
# | Argument | Type | Description |
---|---|---|---|
1 | txt | String | This is the text being shown |
2 | style | String | The style to use. More information on styles. |
3 | x | Number | This is the most left point of the canvas where your text field should be shown. |
4 | y | Number | This is the most top point of the canvas where your text field should be shown. |
5 | width | Number | The text field width on the canvas. |
6 | height | Number | The text field height on the canvas. |
7 | callback | Function | This function will be called when the focus of the text field changes, or the user pressed a key when the text field has focus. |
Example
-- Called when focus changed or the user inputs a key
function callback(event, has_focus, txt, key, key_modifier)
-- event can be:
-- "key_pressed" : A key has been pressed
-- "focus_changed" : The focus of the text field changed
-- Enable some extra background image, when text field has focus.
visible(bg_image, has_focus)
-- Apply the pressed key into the text field
-- Optionally you can do additional filtering here, if you only accept numeric signs for example
if event == "key_pressed" then
txt_set(txt_field_id, txt .. key_pressed)
end
end
txt_field_id = txt_field_add("","size:11px; color:black; halign:right;",0,0,200,50,callback)