Skip to content

Commit 9410989

Browse files
committed
Added selected_now and deselected_now to input
Fixes #70
1 parent a82024d commit 9410989

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ The state table contains the following fields:
524524
* ```pressed_now``` (boolean) - true if the text field was pressed this call
525525
* ```long_pressed``` (boolean) - true if the registered press was a long press or not
526526
* ```released_now``` (boolean) - true if the text field was released this call
527+
* ```selected_now``` (boolean) - true if the text field was selected this call
528+
* ```deselected_now``` (boolean) - true if the text field was deselected this call
527529
* ```text``` (string) - The text in the field
528530
* ```marked_text``` (string) - The marked (non-committed) text
529531
* ```keyboard_type``` (number)

gooey/internal/input.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ function M.input(node_id, keyboard_type, action_id, action, config, refresh_fn)
119119
input.node = node
120120
input.node_id = node_id
121121
input.refresh_fn = refresh_fn
122-
122+
input.deselected_now = false
123+
input.selected_now = false
124+
123125
local use_marked_text = (config and config.use_marked_text == nil) and true or (config and config.use_marked_text)
124126
input.text = input.text or "" .. (not use_marked_text and input.marked_text or "")
125127
input.marked_text = input.marked_text or ""
@@ -136,12 +138,16 @@ function M.input(node_id, keyboard_type, action_id, action, config, refresh_fn)
136138
if input.enabled then
137139
input.deselected_now = false
138140
if input.released_now then
141+
if not input.selected then
142+
input.selected_now = true
143+
end
139144
input.selected = true
140145
input.marked_text = ""
141146
gui.reset_keyboard()
142147
gui.show_keyboard(keyboard_type, true)
143148
elseif input.selected and action.pressed and action_id == actions.TOUCH and not input.over then
144149
input.selected = false
150+
input.deselected_now = true
145151
input.text = input.text .. (not use_marked_text and input.marked_text or "")
146152
input.marked_text = ""
147153
gui.hide_keyboard()

test/test_input.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ return function()
5757
assert(input.text == "fooba")
5858
end)
5959

60+
test("it should be possible to know if input was selected or deselected now", function()
61+
local node = gui.new_text_node(vmath.vector3(10, 10, 0), "")
62+
gui.set_id(node, "text")
63+
64+
gooey.input("text", gui.KEYBOARD_TYPE_PASSWORD, action_ids.TOUCH, actions.pressed(10, 10))
65+
local input = gooey.input("text", gui.KEYBOARD_TYPE_PASSWORD, action_ids.TOUCH, actions.released(10, 10))
66+
assert(input.selected_now)
67+
68+
local input = gooey.input("text", gui.KEYBOARD_TYPE_PASSWORD, action_ids.TOUCH, actions.pressed(1000, 1000))
69+
assert(input.deselected_now)
70+
end)
71+
6072
test("it should mask entered text if it is a password", function()
6173
local node = gui.new_text_node(vmath.vector3(10, 10, 0), "")
6274
gui.set_id(node, "text")

0 commit comments

Comments
 (0)