Skip to content

Commit

Permalink
Added selected_now and deselected_now to input
Browse files Browse the repository at this point in the history
Fixes #70
  • Loading branch information
britzl committed Mar 14, 2022
1 parent a82024d commit 9410989
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ The state table contains the following fields:
* ```pressed_now``` (boolean) - true if the text field was pressed this call
* ```long_pressed``` (boolean) - true if the registered press was a long press or not
* ```released_now``` (boolean) - true if the text field was released this call
* ```selected_now``` (boolean) - true if the text field was selected this call
* ```deselected_now``` (boolean) - true if the text field was deselected this call
* ```text``` (string) - The text in the field
* ```marked_text``` (string) - The marked (non-committed) text
* ```keyboard_type``` (number)
Expand Down
8 changes: 7 additions & 1 deletion gooey/internal/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ function M.input(node_id, keyboard_type, action_id, action, config, refresh_fn)
input.node = node
input.node_id = node_id
input.refresh_fn = refresh_fn

input.deselected_now = false
input.selected_now = false

local use_marked_text = (config and config.use_marked_text == nil) and true or (config and config.use_marked_text)
input.text = input.text or "" .. (not use_marked_text and input.marked_text or "")
input.marked_text = input.marked_text or ""
Expand All @@ -136,12 +138,16 @@ function M.input(node_id, keyboard_type, action_id, action, config, refresh_fn)
if input.enabled then
input.deselected_now = false
if input.released_now then
if not input.selected then
input.selected_now = true
end
input.selected = true
input.marked_text = ""
gui.reset_keyboard()
gui.show_keyboard(keyboard_type, true)
elseif input.selected and action.pressed and action_id == actions.TOUCH and not input.over then
input.selected = false
input.deselected_now = true
input.text = input.text .. (not use_marked_text and input.marked_text or "")
input.marked_text = ""
gui.hide_keyboard()
Expand Down
12 changes: 12 additions & 0 deletions test/test_input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ return function()
assert(input.text == "fooba")
end)

test("it should be possible to know if input was selected or deselected now", function()
local node = gui.new_text_node(vmath.vector3(10, 10, 0), "")
gui.set_id(node, "text")

gooey.input("text", gui.KEYBOARD_TYPE_PASSWORD, action_ids.TOUCH, actions.pressed(10, 10))
local input = gooey.input("text", gui.KEYBOARD_TYPE_PASSWORD, action_ids.TOUCH, actions.released(10, 10))
assert(input.selected_now)

local input = gooey.input("text", gui.KEYBOARD_TYPE_PASSWORD, action_ids.TOUCH, actions.pressed(1000, 1000))
assert(input.deselected_now)
end)

test("it should mask entered text if it is a password", function()
local node = gui.new_text_node(vmath.vector3(10, 10, 0), "")
gui.set_id(node, "text")
Expand Down

0 comments on commit 9410989

Please sign in to comment.