Input priority little rework? Remove on_swipe

This commit is contained in:
Insality 2020-02-23 12:17:25 +03:00
parent 44016bc4f3
commit c2b65eb4e2
9 changed files with 61 additions and 87 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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"
}

View File

@ -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