Skip to content

Commit

Permalink
Improved text field input
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Apr 23, 2018
1 parent 6552bfa commit 82690d6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions gooey/internal/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,44 @@ function M.mask_text(text, mask)
return masked_text
end

local INPUT = {
refresh = function(input)
if input.refresh_fn then input.refresh_fn(input) end
end,
set_visible = function(input, visible)
gui.set_enabled(input.node, visible)
end,
}

function M.input(node_id, keyboard_type, action_id, action, config, refresh_fn)
node_id = core.to_hash(node_id)
local node = gui.get_node(node_id)
assert(node)

local input = core.instance(node_id, inputfields)
local input = core.instance(node_id, inputfields, INPUT)
input.enabled = core.is_enabled(node)
input.node = node
input.refresh_fn = refresh_fn

if not action then
input.refresh()
return input
end

input.text = input.text or ""
input.marked_text = input.marked_text or ""
input.keyboard_type = keyboard_type

core.clickable(input, action_id, action)

if input.enabled then
input.deselected_now = false
if input.released_now then
input.selected = true
input.marked_text = ""
gui.reset_keyboard()
gui.show_keyboard(keyboard_type, true)
elseif input.selected and action.pressed and not input.over then
elseif input.selected and action.pressed and action_id == M.TOUCH and not input.over then
input.selected = false
gui.hide_keyboard()
end
Expand Down

0 comments on commit 82690d6

Please sign in to comment.