diff --git a/README.md b/README.md index 298b34e..60931e1 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ function M.update(self, dt) end --- Call only if exist interest: const.ON_INPUT or const.ON_SWIPE +-- Call only if exist interest: const.ON_INPUT or const.ON_INPUT_HIGH function M.on_input(self, action_id, action) end @@ -123,8 +123,8 @@ function M.on_message(self, message_id, message, sender) end --- Call only if swipe was started on another component (ex. scroll) -function M.on_swipe(self) +-- Call if input was interrupt by previous components (ex. scroll) +function M.on_input_interrupt(self) end @@ -178,7 +178,7 @@ _TODO_ - update - on_input - on_message -- on_swipe +- on_input_interrupt - setup_component - get_style - set_style diff --git a/alpha_todo.txt b/alpha_todo.txt index ac659ed..aae9b80 100644 --- a/alpha_todo.txt +++ b/alpha_todo.txt @@ -7,29 +7,29 @@ Simple to-do for Druid Alpha 0.2.0 + add druid events/triggers? better callback system + better name for locale component? lang? lang_text? + better name for slider component? Slider is ok ++ Druid store assets - separate repository with rich components (progress_rich migrate) - refactor on_swipe. To on_scroll? Add input priority - separate custom data and predefined fields in components? - add init/remove stuff for every style in component. How to set custom sprites for button states? +- unify component api (get/set/to and other general stuff) +- add druid settings (add auto_focus input and other stuff) - button add key trigger - button polish, actions -- add druid settings (add auto_focus input and other stuff) -- better callbacks for every components -- better default style, add template for custom style -- add docs for all components -- add docs folder for every component with gifs? Solutions -- unify component api (get/set/to and other general stuff) -- add text component for alpha release -- compare with gooey - button and hover click restriction zone? +- better callbacks for every components - better scroll size management, check different cases. So implicit now - better grid + scroll management +- better default style, add template for custom style +- add text component for alpha release +- compare with gooey +- add docs for all components +- add docs folder for every component with gifs? Solutions -- Low - add code template and example for user components - custom input settings (name of touch, text, etc) -- ability to relocalize all locale text nodes - add good examples with template and/or nodes (basic component no use any of them) - try use final druid in real project (FI uses custom druid) (use in 4321?) -- Druid store assest - separate repository with rich components +- ability to relocalize all locale text nodes - ability to control buttons via controller. Select it by cursor (d-pad) diff --git a/druid/base/blocker.lua b/druid/base/blocker.lua index 54d41b3..d03fc3f 100644 --- a/druid/base/blocker.lua +++ b/druid/base/blocker.lua @@ -5,7 +5,7 @@ local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") -local M = component.create("blocker", { const.ON_SWIPE }) +local M = component.create("blocker", { const.ON_INPUT_HIGH }) function M.init(self, node) diff --git a/druid/base/button.lua b/druid/base/button.lua index d0de518..618663f 100644 --- a/druid/base/button.lua +++ b/druid/base/button.lua @@ -1,6 +1,7 @@ --- Component to handle basic GUI button -- @module druid.button +local Event = require("druid.event") local const = require("druid.const") local helper = require("druid.helper") local component = require("druid.component") @@ -60,6 +61,12 @@ function M.init(self, node, callback, params, anim_node, event) self.hover_anim = self.style.IS_HOVER self.hover = self.druid:new_hover(node, self, on_button_hover) + -- Event stubs + self.on_click = Event() + self.on_hold_click = Event() + self.on_long_click = Event() + self.on_double_click = Event() + self.click_zone = nil end @@ -99,7 +106,7 @@ function M.on_input(self, action_id, action) end -function M.on_swipe(self) +function M.on_input_interrupt(self) self.can_action = false end diff --git a/druid/base/hover.lua b/druid/base/hover.lua index dbf5016..71a15bc 100644 --- a/druid/base/hover.lua +++ b/druid/base/hover.lua @@ -59,7 +59,7 @@ function M.on_input(self, action_id, action) end -function M.on_swipe(self) +function M.on_input_interrupt(self) set_hover(self, false) end diff --git a/druid/base/scroll.lua b/druid/base/scroll.lua index a00459a..b5382ca 100644 --- a/druid/base/scroll.lua +++ b/druid/base/scroll.lua @@ -5,7 +5,7 @@ local helper = require("druid.helper") local const = require("druid.const") local component = require("druid.component") -local M = component.create("scroll", { const.ON_UPDATE, const.ON_SWIPE }) +local M = component.create("scroll", { const.ON_UPDATE, const.ON_INPUT_HIGH }) -- Global on all scrolls diff --git a/druid/base/slider.lua b/druid/base/slider.lua index 5b8d691..80a8534 100644 --- a/druid/base/slider.lua +++ b/druid/base/slider.lua @@ -5,7 +5,7 @@ local helper = require("druid.helper") local const = require("druid.const") local component = require("druid.component") -local M = component.create("slider", { const.ON_SWIPE }) +local M = component.create("slider", { const.ON_INPUT_HIGH }) local function on_change_value(self) diff --git a/druid/const.lua b/druid/const.lua index ace87b6..fd2c121 100644 --- a/druid/const.lua +++ b/druid/const.lua @@ -19,14 +19,13 @@ M.ZERO = "0" M.ALL = "all" ---- Interests +--- Component Interests M.ON_MESSAGE = hash("on_message") M.ON_UPDATE = hash("on_update") - - --- Input -M.ON_SWIPE = hash("on_swipe") +M.ON_INPUT_HIGH = hash("on_input_high") M.ON_INPUT = hash("on_input") +M.ON_CHANGE_LANGUAGE = hash("on_change_language") +M.ON_LAYOUT_CHANGED = hash("on_layout_changed") M.PIVOTS = { @@ -42,43 +41,21 @@ M.PIVOTS = { } -M.SIDE = { - X = "x", - Y = "y" -} - - -M.UI_INPUT = { - [M.ON_SWIPE] = true, - [M.ON_INPUT] = true -} - --- UI messages -M.ON_CHANGE_LANGUAGE = hash("on_change_language") -M.ON_LAYOUT_CHANGED = hash("on_layout_changed") - - M.SPECIFIC_UI_MESSAGES = { [M.ON_CHANGE_LANGUAGE] = "on_change_language", [M.ON_LAYOUT_CHANGED] = "on_layout_changed" } --- Basic druid components -M.COMPONENTS = { - BUTTON = "button", - BLOCKER = "blocker", - BACK_HANDLER = "back_handler", - TEXT = "text", - LOCALE = "locale", - TIMER = "timer", - PROGRESS = "progress", - GRID = "grid", - SCROLL = "scroll", - SLIDER = "slider", - CHECKBOX = "checkbox", - CHECKBOX_GROUP = "checkbox_group", - RADIO_GROUP = "radio_group", +M.UI_INPUT = { + [M.ON_INPUT_HIGH] = true, + [M.ON_INPUT] = true +} + + +M.SIDE = { + X = "x", + Y = "y" } diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 684c515..1a217ca 100644 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -82,16 +82,24 @@ local function create(self, instance_class) end -local function notify_input_on_swipe(self) - if self.components[const.ON_INPUT] then - local len = #self.components[const.ON_INPUT] - for i = len, 1, -1 do - local comp = self.components[const.ON_INPUT][i] - if comp.on_swipe then - comp:on_swipe() +local function process_input(action_id, action, components, is_input_consumed) + if not components then + return is_input_consumed + end + + for i = #components, 1, -1 do + local component = components[i] + + 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 + + return is_input_consumed end @@ -169,33 +177,15 @@ end -- @tparam hash action_id Action_id from on_input -- @tparam table action Action from on_input function Druid.on_input(self, action_id, action) - -- TODO: расписать отличия ON_SWIPE и ON_INPUT - -- Почему-то некоторые используют ON_SWIPE, а логичнее ON_INPUT? (blocker, slider) - local components = self.components[const.ON_SWIPE] - if components then - local result - for i = #components, 1, -1 do - local v = components[i] - result = result or v:on_input(action_id, action) - end - if result then - notify_input_on_swipe(self) - return true - end - end + local is_input_consumed = false - components = self.components[const.ON_INPUT] - if components then - for i = #components, 1, -1 do - local v = components[i] - if v:on_input(action_id, action) then - return true - end - end - return false - end + is_input_consumed = process_input(action_id, action, + self.components[const.ON_INPUT_HIGH], is_input_consumed) - return false + is_input_consumed = process_input(action_id, action, + self.components[const.ON_INPUT], is_input_consumed) + + return is_input_consumed end