Skip to content

Commit

Permalink
#153 Add Druid acquire input to late_init step
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Jan 26, 2022
1 parent ef455a7 commit b7d2891
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions druid/system/druid_instance.lua
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ local DruidInstance = class("druid.druid_instance")


local function input_init(self)
if sys.get_config("druid.no_auto_input") == "1" then
if self._no_auto_input then
return
end

Expand All @@ -75,7 +75,7 @@ end


local function input_release(self)
if sys.get_config("druid.no_auto_input") == "1" then
if self._no_auto_input then
return
end

Expand Down Expand Up @@ -113,10 +113,6 @@ local function create(self, instance_class)
for i = 1, #register_to do
local interest = register_to[i]
table.insert(self.components[interest], instance)

if base_component.UI_INPUT[interest] then
input_init(self)
end
end

return instance
Expand Down Expand Up @@ -209,6 +205,7 @@ function DruidInstance.initialize(self, context, style)

self._input_blacklist = nil
self._input_whitelist = nil
self._no_auto_input = (sys.get_config("druid.no_auto_input") == "1")

self.components = {}
for i = 1, #base_component.ALL_INTERESTS do
Expand Down Expand Up @@ -316,6 +313,11 @@ function DruidInstance.update(self, dt)
table.remove(late_init_components, 1)
end

if not self.input_inited and #self.components[base_component.ON_INPUT] > 0 then
-- Input init on late init step, to be sure it goes after user go acquire input
input_init(self)
end

local components = self.components[base_component.ON_UPDATE]
for i = 1, #components do
components[i]:update(dt)
Expand Down Expand Up @@ -622,10 +624,11 @@ end
-- @tparam node node Gui node
-- @tparam function callback Checkbox callback
-- @tparam[opt=node] node click_node Trigger node, by default equals to node
-- @tparam[opt=false] boolean initial_state The initial state of checkbox, default - false
-- @treturn Checkbox checkbox component
function DruidInstance.new_checkbox(self, node, callback, click_node)
function DruidInstance.new_checkbox(self, node, callback, click_node, initial_state)
-- return helper.extended_component("checkbox")
return DruidInstance.new(self, checkbox, node, callback, click_node)
return DruidInstance.new(self, checkbox, node, callback, click_node, initial_state)
end


Expand Down

0 comments on commit b7d2891

Please sign in to comment.