diff --git a/.defignore b/.defignore index 9447348..165a74c 100644 --- a/.defignore +++ b/.defignore @@ -1,2 +1,2 @@ /dist -/.deployer_cache \ No newline at end of file +/.deployer_cache diff --git a/druid/extended/input.lua b/druid/extended/input.lua index 3f18ea8..b5108dc 100755 --- a/druid/extended/input.lua +++ b/druid/extended/input.lua @@ -182,7 +182,7 @@ function M:on_input(action_id, action) if self.max_length then self.marked_value = utf8.sub(self.marked_value, 1, self.max_length) end - is_marked_text_changed = true + is_marked_text_changed = self.marked_value ~= "" end if action_id == const.ACTION_BACKSPACE and (action.pressed or action.repeated) then @@ -222,7 +222,7 @@ function M:on_input(action_id, action) end if input_text or is_marked_text_changed then - self:set_text(input_text) + self:set_text(input_text or self.value) if cursor_shift_indexes then self:select_cursor(self.cursor_index + cursor_shift_indexes) @@ -247,12 +247,6 @@ function M:on_focus_lost() end ----@private -function M:on_input_interrupt() - --self:unselect() -end - - function M:get_text_selected() if self.start_index == self.end_index then return self.value diff --git a/example/druid.gui_script b/example/druid.gui_script index db779a9..5c42107 100644 --- a/example/druid.gui_script +++ b/example/druid.gui_script @@ -175,7 +175,7 @@ local function setup_components(self) return end - local url_prefix = "https://github.com/Insality/druid/blob/develop/" + local url_prefix = "https://github.com/Insality/druid/blob/master/" sys.open_url(url_prefix .. code_url, { target = "_blank" }) end) end diff --git a/example/examples/basic/input/basic_input.lua b/example/examples/basic/input/basic_input.lua index c169756..997fd03 100644 --- a/example/examples/basic/input/basic_input.lua +++ b/example/examples/basic/input/basic_input.lua @@ -2,10 +2,33 @@ ---@field input druid.input local M = {} -function M:init() - self.input = self.druid:new_input("input/root", "input/text") - self.input_2 = self.druid:new_input("input_2/root", "input_2/text") --[[@as druid.input]] +local COLOR_SELECTED = vmath.vector3(1, 1, 1) +local COLOR_UNSELECTED = vmath.vector3(184/255, 189/255, 194/255) + +---@param template string +---@param nodes table +function M:init(template, nodes) + self.druid = self:get_druid(template, nodes) + + self.input = self.druid:new_input("input/root", "input/text") + self.input.on_input_select:subscribe(function() + gui.set_color(self.input.text.node, COLOR_SELECTED) + end) + self.input.on_input_unselect:subscribe(function(_, text) + print("User Enters Text: " .. text) + gui.set_color(self.input.text.node, COLOR_UNSELECTED) + end) + + self.input_2 = self.druid:new_input("input_2/root", "input_2/text") + self.input_2:set_text("") + self.input_2.on_input_select:subscribe(function() + gui.set_color(self.input_2.text.node, COLOR_SELECTED) + end) + self.input_2.on_input_unselect:subscribe(function(_, text) + print("User Enters Text: " .. text) + gui.set_color(self.input_2.text.node, COLOR_UNSELECTED) + end) -- you can set custom style for input and their components -- Check in the example, how long tap on bottom input will erase text