mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
#105 make input.select and input.unselect public methods
This commit is contained in:
parent
8d0138c770
commit
23c0853d0a
@ -68,45 +68,12 @@ local function mask_text(text, mask)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function select(self)
|
|
||||||
gui.reset_keyboard()
|
|
||||||
self.marked_value = ""
|
|
||||||
if not self.is_selected then
|
|
||||||
self:increase_input_priority()
|
|
||||||
self.button:increase_input_priority()
|
|
||||||
self.previous_value = self.value
|
|
||||||
self.is_selected = true
|
|
||||||
|
|
||||||
gui.show_keyboard(self.keyboard_type, false)
|
|
||||||
self.on_input_select:trigger(self:get_context())
|
|
||||||
|
|
||||||
self.style.on_select(self, self.button.node)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function unselect(self)
|
|
||||||
gui.reset_keyboard()
|
|
||||||
self.marked_value = ""
|
|
||||||
if self.is_selected then
|
|
||||||
self:reset_input_priority()
|
|
||||||
self.button:reset_input_priority()
|
|
||||||
self.is_selected = false
|
|
||||||
|
|
||||||
gui.hide_keyboard()
|
|
||||||
self.on_input_unselect:trigger(self:get_context())
|
|
||||||
|
|
||||||
self.style.on_unselect(self, self.button.node)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function clear_and_select(self)
|
local function clear_and_select(self)
|
||||||
if self.style.IS_LONGTAP_ERASE then
|
if self.style.IS_LONGTAP_ERASE then
|
||||||
self:set_text("")
|
self:set_text("")
|
||||||
end
|
end
|
||||||
|
|
||||||
select(self)
|
self:select()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -161,9 +128,9 @@ function Input.init(self, click_node, text_node, keyboard_type)
|
|||||||
|
|
||||||
self.keyboard_type = keyboard_type or gui.KEYBOARD_TYPE_DEFAULT
|
self.keyboard_type = keyboard_type or gui.KEYBOARD_TYPE_DEFAULT
|
||||||
|
|
||||||
self.button = self.druid:new_button(click_node, select)
|
self.button = self.druid:new_button(click_node, self.select)
|
||||||
self.button:set_style(self.button_style)
|
self.button:set_style(self.button_style)
|
||||||
self.button.on_click_outside:subscribe(unselect)
|
self.button.on_click_outside:subscribe(self.unselect)
|
||||||
self.button.on_long_click:subscribe(clear_and_select)
|
self.button.on_long_click:subscribe(clear_and_select)
|
||||||
|
|
||||||
self.on_input_select = Event()
|
self.on_input_select = Event()
|
||||||
@ -215,17 +182,17 @@ function Input.on_input(self, action_id, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if action_id == const.ACTION_ENTER and action.released then
|
if action_id == const.ACTION_ENTER and action.released then
|
||||||
unselect(self)
|
self:unselect()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if action_id == const.ACTION_BACK and action.released then
|
if action_id == const.ACTION_BACK and action.released then
|
||||||
unselect(self)
|
self:unselect()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if action_id == const.ACTION_ESC and action.released then
|
if action_id == const.ACTION_ESC and action.released then
|
||||||
unselect(self)
|
self:unselect()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -240,12 +207,12 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function Input.on_focus_lost(self)
|
function Input.on_focus_lost(self)
|
||||||
unselect(self)
|
self:unselect()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Input.on_input_interrupt(self)
|
function Input.on_input_interrupt(self)
|
||||||
-- unselect(self)
|
-- self:unselect()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -296,6 +263,43 @@ function Input.set_text(self, input_text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Select input field. It will show the keyboard and trigger on_select events
|
||||||
|
-- @tparam Input self
|
||||||
|
function Input.select(self)
|
||||||
|
gui.reset_keyboard()
|
||||||
|
self.marked_value = ""
|
||||||
|
if not self.is_selected then
|
||||||
|
self:increase_input_priority()
|
||||||
|
self.button:increase_input_priority()
|
||||||
|
self.previous_value = self.value
|
||||||
|
self.is_selected = true
|
||||||
|
|
||||||
|
gui.show_keyboard(self.keyboard_type, false)
|
||||||
|
self.on_input_select:trigger(self:get_context())
|
||||||
|
|
||||||
|
self.style.on_select(self, self.button.node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Remove selection from input. It will hide the keyboard and trigger on_unselect events
|
||||||
|
-- @tparam Input self
|
||||||
|
function Input.unselect(self)
|
||||||
|
gui.reset_keyboard()
|
||||||
|
self.marked_value = ""
|
||||||
|
if self.is_selected then
|
||||||
|
self:reset_input_priority()
|
||||||
|
self.button:reset_input_priority()
|
||||||
|
self.is_selected = false
|
||||||
|
|
||||||
|
gui.hide_keyboard()
|
||||||
|
self.on_input_unselect:trigger(self:get_context())
|
||||||
|
|
||||||
|
self.style.on_unselect(self, self.button.node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current input field text
|
--- Return current input field text
|
||||||
-- @tparam Input self
|
-- @tparam Input self
|
||||||
-- @treturn string The current input field text
|
-- @treturn string The current input field text
|
||||||
@ -331,7 +335,7 @@ end
|
|||||||
-- @tparam Input self
|
-- @tparam Input self
|
||||||
function Input.reset_changes(self)
|
function Input.reset_changes(self)
|
||||||
self:set_text(self.previous_value)
|
self:set_text(self.previous_value)
|
||||||
unselect(self)
|
self:unselect()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user