Skip to content

Commit

Permalink
More docs + input fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Ritzl committed Sep 8, 2017
1 parent 31b3bb9 commit 2d73bec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ The state table contains the following fields:
end))
end

## gooey.input(node_id, group, action_id, action, fn)
## gooey.input(node_id, keyboard_type, action_id, action)
Perform input and state handling for a text input field

**PARAMETERS**
* ```node_id``` (string|hash) - Id of the node representing the clickable area
* ```node_id``` (string|hash) - Id of the text node
* ```keyboard_type``` (number) - Keyboard type from gui.KEYBOARD_TYPE_*
* ```action_id``` (hash) - Action id as received from on_input()
* ```action``` (table) - Action as received from on_input()
* ```fn``` (function) - Function to call when the radio button is selected. A radio button is considered selected if both a pressed and released action has been detected inside the bounds of the node. The function will get the same state table as described below passed as its first argument

**RETURN**
* ```radio``` (table) - State data for the radio button based on current and previous input actions
* ```input``` (table) - State data for the input field based on current and previous input actions

The state table contains the following fields:

Expand All @@ -228,34 +228,32 @@ The state table contains the following fields:
* ```over``` (boolean) - true if user action is inside the node
* ```over_now``` (boolean) - true if user action moved inside the node this call
* ```out_now``` (boolean) - true if user action moved outside the node this call
* ```selected``` (boolean) - The radio button state
* ```pressed``` (boolean) - true if the radio button is pressed (ie mouse/touch down but not yet released)
* ```pressed_now``` (boolean) - true if the radio button was pressed this call
* ```released_now``` (boolean) - true if the radio button was released this call
* ```selected``` (boolean) - true if the text field is selected
* ```selected_now``` (boolean) - true if the text field was selected this call
* ```deselected_now``` (boolean) - true if the text field was deselected this call
* ```pressed``` (boolean) - true if the text field is pressed (ie mouse/touch down but not yet released)
* ```pressed_now``` (boolean) - true if the text field was pressed this call
* ```released_now``` (boolean) - true if the text field was released this call
* ```text``` (string) - The text in the field
* ```marked_text``` (string) - The marked (non-committed) text
* ```keyboard_type``` (number)
* ```masked_text``` (string) - If the keyboard type is gui.KEYBOARD_TYPE_PASSWORD then this string represents a masked version of the text
* ```masked_marked_text``` (string) - If the keyboard type is gui.KEYBOARD_TYPE_PASSWORD then this string represents a masked version of the marked text
* ```text_width``` (number) - The width of the text
* ```marked_text_width``` (number) - The width of the marked text

**EXAMPLE**

local gooey = require "gooey.gooey"

local function update_radio(radio)
if radio.released_now then
if radio.selected then
gui.play_flipbook(radio.node, hash("radio_selected"))
else
gui.play_flipbook(radio.node, hash("radio_normal"))
end
elseif not radio.pressed and radio.over_now then
gui.play_flipbook(radio.node, hash("radio_over"))
elseif not radio.pressed and radio.out_now then
gui.play_flipbook(radio.node, hash("radio_normal"))
local function update_input(input)
if input.released_now and input.selected then
gui.play_flipbook(input.node, hash("input_selected"))
elseif input.deselected_now then
gui.play_flipbook(input.node, hash("input_normal"))
end
end

function on_input(self, action_id, action)
update_radio(gooey.radio("radio1/bg", "MYGROUP", action_id, action, function(radio)
print("selected 1", radio.selected)
end))
update_radio(gooey.radio("radio2/bg", "MYGROUP", action_id, action, function(radio)
print("selected 2", radio.selected)
end))
update_input(gooey.input("input/text", gui.KEYBOARD_TYPE_DEFAULT, action_id, action))
end
9 changes: 2 additions & 7 deletions example/example.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ local function update_list(list)
end

local function update_input(input, empty_text, cursor_id, bg_id)
if input.released_now and input.selected then
if input.selected_now then
gui.play_flipbook(gui.get_node(bg_id), hash("blue_button05"))
elseif input.deselected_now then
gui.play_flipbook(gui.get_node(bg_id), hash("blue_button03"))
Expand All @@ -85,20 +85,15 @@ local function update_input(input, empty_text, cursor_id, bg_id)

local cursor = gui.get_node(cursor_id)
if input.selected then
local text = input.masked_text or input.text
local marked_text = input.masked_marked_text or input.marked_text
local m_t = gui.get_text_metrics(gui.get_font(input.node), text, 0, false, 0, 0)
local m_m = gui.get_text_metrics(gui.get_font(input.node), marked_text, 0, false, 0, 0)
gui.set_enabled(cursor, true)
gui.set_position(cursor, vmath.vector3(4 + m_t.width, 0, 0))
gui.set_position(cursor, vmath.vector3(4 + input.text_width, 0, 0))
gui.cancel_animation(cursor, gui.PROP_COLOR)
gui.set_color(cursor, vmath.vector4(1))
gui.animate(cursor, gui.PROP_COLOR, vmath.vector4(1,1,1,0), gui.EASING_INSINE, 0.8, 0, nil, gui.PLAYBACK_LOOP_PINGPONG)
else
gui.set_enabled(cursor, false)
gui.cancel_animation(cursor, gui.PROP_COLOR)
end

end


Expand Down
7 changes: 5 additions & 2 deletions gooey/gooey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,10 @@ function M.input(node_id, keyboard_type, action_id, action)
input.deselected_now = false
input.pressed_now = pressed and not input.pressed
input.released_now = released and input.pressed
input.selected_now = released and input.pressed and input.over
input.pressed = pressed or (input.pressed and not released)
if input.released_now then
input.selected = input.over
if input.selected_now then
input.selected = true
input.marked_text = ""
gui.reset_keyboard()
gui.show_keyboard(keyboard_type, true)
Expand Down Expand Up @@ -332,6 +333,8 @@ function M.input(node_id, keyboard_type, action_id, action)
local text = input.masked_text or input.text
local marked_text = input.masked_marked_text or input.marked_text
input.empty = #text == 0 and #marked_text == 0
input.text_width = gui.get_text_metrics(gui.get_font(input.node), text, 0, false, 0, 0).width
input.marked_text_width = gui.get_text_metrics(gui.get_font(input.node), marked_text, 0, false, 0, 0).width
if input.selected then
gui.set_text(input.node, text .. marked_text)
end
Expand Down

0 comments on commit 2d73bec

Please sign in to comment.