#105 make input.select and input.unselect public methods

This commit is contained in:
Insality 2020-11-06 22:58:29 +03:00
parent 8d0138c770
commit 23c0853d0a

View File

@ -68,45 +68,12 @@ local function mask_text(text, mask)
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)
if self.style.IS_LONGTAP_ERASE then
self:set_text("")
end
select(self)
self:select()
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.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.on_click_outside:subscribe(unselect)
self.button.on_click_outside:subscribe(self.unselect)
self.button.on_long_click:subscribe(clear_and_select)
self.on_input_select = Event()
@ -215,17 +182,17 @@ function Input.on_input(self, action_id, action)
end
if action_id == const.ACTION_ENTER and action.released then
unselect(self)
self:unselect()
return true
end
if action_id == const.ACTION_BACK and action.released then
unselect(self)
self:unselect()
return true
end
if action_id == const.ACTION_ESC and action.released then
unselect(self)
self:unselect()
return true
end
@ -240,12 +207,12 @@ end
function Input.on_focus_lost(self)
unselect(self)
self:unselect()
end
function Input.on_input_interrupt(self)
-- unselect(self)
-- self:unselect()
end
@ -296,6 +263,43 @@ function Input.set_text(self, input_text)
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
-- @tparam Input self
-- @treturn string The current input field text
@ -331,7 +335,7 @@ end
-- @tparam Input self
function Input.reset_changes(self)
self:set_text(self.previous_value)
unselect(self)
self:unselect()
end