Update set/reset input priority functions. Remove increase_input_priority function

This commit is contained in:
Insality 2021-04-01 20:59:47 +03:00
parent 44842f78dc
commit 14dccea799
6 changed files with 59 additions and 35 deletions

View File

@ -91,7 +91,7 @@ local function process_touch(self, touch)
if not self.is_drag and distance >= self.style.DRAG_DEADZONE then
self.is_drag = true
self.on_drag_start:trigger(self:get_context())
self:increase_input_priority()
self:set_input_priority(const.PRIORITY_INPUT_MAX)
end
end

View File

@ -5,6 +5,7 @@
local const = require("druid.const")
local class = require("druid.system.middleclass")
local helper = require("druid.helper")
local BaseComponent = class("druid.component")
@ -95,17 +96,12 @@ end
--- Increase input priority in current input stack
-- @tparam BaseComponent self
-- @local
function BaseComponent.increase_input_priority(self)
self._meta.increased_input_priority = true
helper.deprecated("The component:increase_input_priority is deprecated. Please use component:set_input_priority(druid_const.PRIORITY_INPUT_MAX) instead")
end
--- Reset input priority in current input stack
-- @tparam BaseComponent self
function BaseComponent.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
@ -169,7 +165,12 @@ end
-- @treturn number The component input priority
function BaseComponent.set_input_priority(self, value)
assert(value)
if self._component.input_priority ~= value then
self._component.input_priority = value
self._component._is_input_priority_changed = true
end
return self
end
@ -187,7 +188,7 @@ end
-- @tparam BaseComponent self
-- @treturn number The component uid
function BaseComponent.get_uid(self)
return self._component.uid
return self._component._uid
end
@ -234,7 +235,6 @@ function BaseComponent.setup_component(self, druid_instance, context, style)
nodes = nil,
style = nil,
druid = druid_instance,
increased_input_priority = false,
input_enabled = true,
children = {}
}
@ -266,11 +266,28 @@ function BaseComponent.initialize(self, name, interest, input_priority)
interest = interest,
input_priority = input_priority or const.PRIORITY_INPUT,
default_input_priority = input_priority or const.PRIORITY_INPUT,
uid = BaseComponent.get_uid()
_is_input_priority_changed = true, -- Default true for sort once time after GUI init
_uid = BaseComponent.get_uid()
}
end
--- Return true, if input priority was changed
-- @tparam BaseComponent self
-- @local
function BaseComponent._is_input_priority_changed(self)
return self._component._is_input_priority_changed
end
--- Reset is_input_priority_changed field
-- @tparam BaseComponent self
-- @local
function BaseComponent._reset_input_priority_changed(self)
self._component._is_input_priority_changed = false
end
function BaseComponent.__tostring(self)
return self._component.name
end

View File

@ -39,6 +39,7 @@ M.ON_LANGUAGE_CHANGE = hash("on_language_change")
M.PRIORITY_INPUT = 10
M.PRIORITY_INPUT_HIGH = 20
M.PRIORITY_INPUT_MAX = 100
M.PIVOTS = {

View File

@ -271,8 +271,8 @@ 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:set_input_priority(const.PRIORITY_INPUT_MAX)
self.button:set_input_priority(const.PRIORITY_INPUT_MAX)
self.previous_value = self.value
self.is_selected = true

View File

@ -92,6 +92,7 @@ local function sort_input_stack(self)
if a:get_input_priority() ~= b:get_input_priority() then
return a:get_input_priority() < b:get_input_priority()
end
return a:get_uid() < b:get_uid()
end)
end
@ -111,7 +112,6 @@ local function create(self, instance_class)
if base_component.UI_INPUT[interest] then
input_init(self)
sort_input_stack(self)
end
end
@ -119,6 +119,27 @@ local function create(self, instance_class)
end
local function check_sort_input_stack(self, components)
if not components or #components == 0 then
return
end
local is_need_sort_input_stack = false
for i = #components, 1, -1 do
local component = components[i]
if component:_is_input_priority_changed() then
is_need_sort_input_stack = true
end
component:_reset_input_priority_changed()
end
if is_need_sort_input_stack then
sort_input_stack(self)
end
end
local function process_input(action_id, action, components, is_input_consumed)
if #components == 0 then
return is_input_consumed
@ -126,24 +147,8 @@ 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
local meta = component._meta
if meta.input_enabled and 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
for i = #components, 1, -1 do
local component = components[i]
-- Process usual input priority next
local meta = component._meta
if meta.input_enabled and not meta.increased_input_priority then
if meta.input_enabled then
if not is_input_consumed then
is_input_consumed = component:on_input(action_id, action)
else
@ -273,9 +278,9 @@ function DruidInstance.on_input(self, action_id, action)
self._is_input_processing = true
local is_input_consumed = false
is_input_consumed = process_input(action_id, action,
self.components[base_component.ON_INPUT], is_input_consumed)
local components = self.components[base_component.ON_INPUT]
check_sort_input_stack(self, components)
is_input_consumed = process_input(action_id, action, components, is_input_consumed)
self._is_input_processing = false

View File

@ -81,6 +81,7 @@ embedded_instances {
"gain: 1.0\\n"
"pan: 0.0\\n"
"speed: 1.0\\n"
"loopcount: 0\\n"
"\"\n"
" position {\n"
" x: 0.0\n"