diff --git a/druid/base/button.lua b/druid/base/button.lua index 9d6bc32..362cd1e 100644 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -270,17 +270,21 @@ end -- no click events outside stencil node -- @function button:set_click_zone -- @tparam node zone Gui node +-- @tparam druid.button Self instance to make chain calls function M.set_click_zone(self, zone) self.click_zone = self:get_node(zone) self.hover:set_click_zone(zone) + return self end --- Set key-code to trigger this button -- @function button:set_key_trigger -- @tparam hash key The action_id of the key +-- @tparam druid.button Self instance to make chain calls function M.set_key_trigger(self, key) self.key_trigger = hash(key) + return self end diff --git a/druid/base/input.lua b/druid/base/input.lua index f98639b..7564537 100644 --- a/druid/base/input.lua +++ b/druid/base/input.lua @@ -30,9 +30,11 @@ local function select(self) gui.reset_keyboard() self.marked_value = "" if not self.selected then + self:increase_input_priority() + self.button:increase_input_priority() self.previous_value = self.value self.selected = true - print("type", self.keyboard_type) + gui.show_keyboard(self.keyboard_type, false) self.on_input_select:trigger(self:get_context()) @@ -47,7 +49,10 @@ local function unselect(self) gui.reset_keyboard() self.marked_value = "" if self.selected then + self:reset_input_priority() + self.button:reset_input_priority() self.selected = false + gui.hide_keyboard() self.on_input_unselect:trigger(self:get_context()) @@ -137,7 +142,6 @@ function M.on_input(self, action_id, action) if self.max_length then self.marked_value = utf8.sub(self.marked_value, 1, self.max_length) end - print("marked text", self.marked_value) end if action_id == const.ACTION_BACKSPACE and (action.pressed or action.repeated) then @@ -189,7 +193,6 @@ function M.set_text(self, input_text) end -- Only update the text if it has changed - print("set text", self.value, ":::", self.marked_value) local current_value = self.value .. self.marked_value if current_value ~= self.current_value then @@ -239,17 +242,22 @@ end -- Pass nil to make input field unliminted (by default) -- @function input:set_max_length -- @tparam number max_length Maximum length for input text field +-- @tparam druid.input Self instance to make chain calls function M.set_max_length(self, max_length) self.max_length = max_length + return self end --- Set allowed charaters for input field. +-- See: https://defold.com/ref/stable/string/ -- ex: [%a%d] for alpha and numeric -- @function input:set_allowerd_characters -- @tparam string characters Regulax exp. for validate user input +-- @tparam druid.input Self instance to make chain calls function M.set_allowed_characters(self, characters) self.allowed_characters = characters + return self end diff --git a/druid/component.lua b/druid/component.lua index 47486b4..9b79b88 100644 --- a/druid/component.lua +++ b/druid/component.lua @@ -86,6 +86,19 @@ function Component.get_interests(self) end +--- Increase input priority in current input stack +-- @function component:increase_input_priority +function Component.increase_input_priority(self) + self._meta.increased_input_priority = true +end + +--- Reset input priority in current input stack +-- @function component:reset_input_priority +function Component.reset_input_priority(self) + self._meta.increased_input_priority = false +end + + --- Get node for component by name. -- If component has nodes, node_or_name should be string -- It auto pick node by template name or from nodes by clone_tree @@ -135,6 +148,7 @@ function Component.setup_component(self, context, style) context = nil, nodes = nil, style = nil, + increased_input_priority = false } self:set_context(context) diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 5c774f6..9c04b33 100644 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -90,12 +90,27 @@ local function process_input(action_id, action, components, is_input_consumed) for i = #components, 1, -1 do local component = components[i] + -- Process increased input priority first + if component._meta.increased_input_priority then + if not is_input_consumed then + is_input_consumed = component:on_input(action_id, action) + else + if component.on_input_interrupt then + component:on_input_interrupt() + end + end + end + end - if not is_input_consumed then - is_input_consumed = component:on_input(action_id, action) - else - if component.on_input_interrupt then - component:on_input_interrupt() + for i = #components, 1, -1 do + local component = components[i] + if not component._meta.increased_input_priority then + if not is_input_consumed then + is_input_consumed = component:on_input(action_id, action) + else + if component.on_input_interrupt then + component:on_input_interrupt() + end end end end diff --git a/example/gui/main/main.gui b/example/gui/main/main.gui index e5e02f7..f1883f8 100644 --- a/example/gui/main/main.gui +++ b/example/gui/main/main.gui @@ -3183,7 +3183,7 @@ nodes { } size { x: 250.0 - y: 80.0 + y: 50.0 z: 0.0 w: 1.0 } @@ -3214,7 +3214,7 @@ nodes { w: 1.0 } adjust_mode: ADJUST_MODE_FIT - line_break: true + line_break: false parent: "input_box" layer: "" inherit_alpha: true @@ -8130,7 +8130,7 @@ nodes { w: 1.0 } adjust_mode: ADJUST_MODE_FIT - line_break: true + line_break: false parent: "input_box_usual" layer: "text" inherit_alpha: true @@ -8366,7 +8366,7 @@ nodes { w: 1.0 } adjust_mode: ADJUST_MODE_FIT - line_break: true + line_break: false parent: "input_box_password" layer: "text" inherit_alpha: true @@ -8602,7 +8602,7 @@ nodes { w: 1.0 } adjust_mode: ADJUST_MODE_FIT - line_break: true + line_break: false parent: "input_box_email" layer: "text" inherit_alpha: true @@ -8838,7 +8838,7 @@ nodes { w: 1.0 } adjust_mode: ADJUST_MODE_FIT - line_break: true + line_break: false parent: "input_box_numpad" layer: "text" inherit_alpha: true diff --git a/example/page/input.lua b/example/page/input.lua index 7890d31..be5d6fd 100644 --- a/example/page/input.lua +++ b/example/page/input.lua @@ -6,6 +6,7 @@ function M.setup_page(self) self.druid:new_input("input_box_password", "input_text_password", gui.KEYBOARD_TYPE_PASSWORD) self.druid:new_input("input_box_email", "input_text_email", gui.KEYBOARD_TYPE_EMAIL) self.druid:new_input("input_box_numpad", "input_text_numpad", gui.KEYBOARD_TYPE_NUMBER_PAD) + :set_allowed_characters("[%d,.]") end