mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Update components interests link
This commit is contained in:
parent
5a1668a8af
commit
af44d0d26e
@ -39,29 +39,6 @@ local M = {}
|
|||||||
|
|
||||||
local INTERESTS = {} -- Cache interests per component class in runtime
|
local INTERESTS = {} -- Cache interests per component class in runtime
|
||||||
|
|
||||||
-- Component Interests
|
|
||||||
M.ON_INPUT = const.ON_INPUT
|
|
||||||
M.ON_UPDATE = const.ON_UPDATE
|
|
||||||
M.ON_MESSAGE = const.ON_MESSAGE
|
|
||||||
M.ON_LATE_INIT = const.ON_LATE_INIT
|
|
||||||
M.ON_FOCUS_LOST = const.ON_FOCUS_LOST
|
|
||||||
M.ON_FOCUS_GAINED = const.ON_FOCUS_GAINED
|
|
||||||
M.ON_LAYOUT_CHANGE = const.ON_LAYOUT_CHANGE
|
|
||||||
M.ON_WINDOW_RESIZED = const.ON_WINDOW_RESIZED
|
|
||||||
M.ON_LANGUAGE_CHANGE = const.ON_LANGUAGE_CHANGE
|
|
||||||
|
|
||||||
M.ALL_INTERESTS = {
|
|
||||||
M.ON_INPUT,
|
|
||||||
M.ON_UPDATE,
|
|
||||||
M.ON_MESSAGE,
|
|
||||||
M.ON_LATE_INIT,
|
|
||||||
M.ON_FOCUS_LOST,
|
|
||||||
M.ON_FOCUS_GAINED,
|
|
||||||
M.ON_LAYOUT_CHANGE,
|
|
||||||
M.ON_WINDOW_RESIZED,
|
|
||||||
M.ON_LANGUAGE_CHANGE,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
local uid = 0
|
local uid = 0
|
||||||
function M.create_uid()
|
function M.create_uid()
|
||||||
@ -310,8 +287,8 @@ function M:__get_interests()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local interests = {}
|
local interests = {}
|
||||||
for index = 1, #M.ALL_INTERESTS do
|
for index = 1, #const.ALL_INTERESTS do
|
||||||
local interest = M.ALL_INTERESTS[index]
|
local interest = const.ALL_INTERESTS[index]
|
||||||
if self[interest] and type(self[interest]) == "function" then
|
if self[interest] and type(self[interest]) == "function" then
|
||||||
table.insert(interests, interest)
|
table.insert(interests, interest)
|
||||||
end
|
end
|
||||||
|
@ -27,6 +27,18 @@ M.ON_LAYOUT_CHANGE = "on_layout_change"
|
|||||||
M.ON_WINDOW_RESIZED = "on_window_resized"
|
M.ON_WINDOW_RESIZED = "on_window_resized"
|
||||||
M.ON_LANGUAGE_CHANGE = "on_language_change"
|
M.ON_LANGUAGE_CHANGE = "on_language_change"
|
||||||
|
|
||||||
|
M.ALL_INTERESTS = {
|
||||||
|
M.ON_INPUT,
|
||||||
|
M.ON_UPDATE,
|
||||||
|
M.ON_MESSAGE,
|
||||||
|
M.ON_LATE_INIT,
|
||||||
|
M.ON_FOCUS_LOST,
|
||||||
|
M.ON_FOCUS_GAINED,
|
||||||
|
M.ON_LAYOUT_CHANGE,
|
||||||
|
M.ON_WINDOW_RESIZED,
|
||||||
|
M.ON_LANGUAGE_CHANGE,
|
||||||
|
}
|
||||||
|
|
||||||
M.MSG_LAYOUT_CHANGED = hash("layout_changed")
|
M.MSG_LAYOUT_CHANGED = hash("layout_changed")
|
||||||
|
|
||||||
-- Components with higher priority value processed first
|
-- Components with higher priority value processed first
|
||||||
|
@ -49,7 +49,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function sort_input_stack(self)
|
local function sort_input_stack(self)
|
||||||
local input_components = self.components_interest[base_component.ON_INPUT]
|
local input_components = self.components_interest[const.ON_INPUT]
|
||||||
if not input_components then
|
if not input_components then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -215,8 +215,8 @@ function M:initialize(context, style)
|
|||||||
|
|
||||||
self.components_all = {}
|
self.components_all = {}
|
||||||
self.components_interest = {}
|
self.components_interest = {}
|
||||||
for i = 1, #base_component.ALL_INTERESTS do
|
for i = 1, #const.ALL_INTERESTS do
|
||||||
self.components_interest[base_component.ALL_INTERESTS[i]] = {}
|
self.components_interest[const.ALL_INTERESTS[i]] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
events.subscribe("druid.window_event", self.on_window_event, self)
|
events.subscribe("druid.window_event", self.on_window_event, self)
|
||||||
@ -319,13 +319,13 @@ end
|
|||||||
-- An example use case is performing an auto stencil check in the GUI hierarchy for input components.
|
-- An example use case is performing an auto stencil check in the GUI hierarchy for input components.
|
||||||
---@private
|
---@private
|
||||||
function M:late_init()
|
function M:late_init()
|
||||||
local late_init_components = self.components_interest[base_component.ON_LATE_INIT]
|
local late_init_components = self.components_interest[const.ON_LATE_INIT]
|
||||||
while late_init_components[1] do
|
while late_init_components[1] do
|
||||||
late_init_components[1]:on_late_init()
|
late_init_components[1]:on_late_init()
|
||||||
table.remove(late_init_components, 1)
|
table.remove(late_init_components, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not self.input_inited and #self.components_interest[base_component.ON_INPUT] > 0 then
|
if not self.input_inited and #self.components_interest[const.ON_INPUT] > 0 then
|
||||||
-- Input init on late init step, to be sure it goes after user go acquire input
|
-- Input init on late init step, to be sure it goes after user go acquire input
|
||||||
set_input_state(self, true)
|
set_input_state(self, true)
|
||||||
end
|
end
|
||||||
@ -337,7 +337,7 @@ end
|
|||||||
function M:update(dt)
|
function M:update(dt)
|
||||||
self._is_late_remove_enabled = true
|
self._is_late_remove_enabled = true
|
||||||
|
|
||||||
local components = self.components_interest[base_component.ON_UPDATE]
|
local components = self.components_interest[const.ON_UPDATE]
|
||||||
for i = 1, #components do
|
for i = 1, #components do
|
||||||
components[i]:update(dt)
|
components[i]:update(dt)
|
||||||
end
|
end
|
||||||
@ -354,7 +354,7 @@ end
|
|||||||
function M:on_input(action_id, action)
|
function M:on_input(action_id, action)
|
||||||
self._is_late_remove_enabled = true
|
self._is_late_remove_enabled = true
|
||||||
|
|
||||||
local components = self.components_interest[base_component.ON_INPUT]
|
local components = self.components_interest[const.ON_INPUT]
|
||||||
check_sort_input_stack(self, components)
|
check_sort_input_stack(self, components)
|
||||||
local is_input_consumed = process_input(self, action_id, action, components)
|
local is_input_consumed = process_input(self, action_id, action, components)
|
||||||
|
|
||||||
@ -372,13 +372,13 @@ end
|
|||||||
function M:on_message(message_id, message, sender)
|
function M:on_message(message_id, message, sender)
|
||||||
if message_id == const.MSG_LAYOUT_CHANGED then
|
if message_id == const.MSG_LAYOUT_CHANGED then
|
||||||
-- Resend special message to all components with the related interest
|
-- Resend special message to all components with the related interest
|
||||||
local components = self.components_interest[base_component.ON_LAYOUT_CHANGE]
|
local components = self.components_interest[const.ON_LAYOUT_CHANGE]
|
||||||
for i = 1, #components do
|
for i = 1, #components do
|
||||||
components[i]:on_layout_change()
|
components[i]:on_layout_change()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Resend message to all components with on_message interest
|
-- Resend message to all components with on_message interest
|
||||||
local components = self.components_interest[base_component.ON_MESSAGE]
|
local components = self.components_interest[const.ON_MESSAGE]
|
||||||
for i = 1, #components do
|
for i = 1, #components do
|
||||||
components[i]:on_message(message_id, message, sender)
|
components[i]:on_message(message_id, message, sender)
|
||||||
end
|
end
|
||||||
@ -388,17 +388,17 @@ end
|
|||||||
|
|
||||||
function M:on_window_event(window_event)
|
function M:on_window_event(window_event)
|
||||||
if window_event == window.WINDOW_EVENT_FOCUS_LOST then
|
if window_event == window.WINDOW_EVENT_FOCUS_LOST then
|
||||||
local components = self.components_interest[base_component.ON_FOCUS_LOST]
|
local components = self.components_interest[const.ON_FOCUS_LOST]
|
||||||
for i = 1, #components do
|
for i = 1, #components do
|
||||||
components[i]:on_focus_lost()
|
components[i]:on_focus_lost()
|
||||||
end
|
end
|
||||||
elseif window_event == window.WINDOW_EVENT_FOCUS_GAINED then
|
elseif window_event == window.WINDOW_EVENT_FOCUS_GAINED then
|
||||||
local components = self.components_interest[base_component.ON_FOCUS_GAINED]
|
local components = self.components_interest[const.ON_FOCUS_GAINED]
|
||||||
for i = 1, #components do
|
for i = 1, #components do
|
||||||
components[i]:on_focus_gained()
|
components[i]:on_focus_gained()
|
||||||
end
|
end
|
||||||
elseif window_event == window.WINDOW_EVENT_RESIZED then
|
elseif window_event == window.WINDOW_EVENT_RESIZED then
|
||||||
local components = self.components_interest[base_component.ON_WINDOW_RESIZED]
|
local components = self.components_interest[const.ON_WINDOW_RESIZED]
|
||||||
for i = 1, #components do
|
for i = 1, #components do
|
||||||
components[i]:on_window_resized()
|
components[i]:on_window_resized()
|
||||||
end
|
end
|
||||||
@ -411,7 +411,7 @@ end
|
|||||||
-- call manualy to update all translations
|
-- call manualy to update all translations
|
||||||
---@private
|
---@private
|
||||||
function M:on_language_change()
|
function M:on_language_change()
|
||||||
local components = self.components_interest[base_component.ON_LANGUAGE_CHANGE]
|
local components = self.components_interest[const.ON_LANGUAGE_CHANGE]
|
||||||
for i = 1, #components do
|
for i = 1, #components do
|
||||||
components[i]:on_language_change()
|
components[i]:on_language_change()
|
||||||
end
|
end
|
||||||
|
@ -212,6 +212,13 @@ function M:add_left_right_selector(text, value, on_change_callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---@param widget druid.widget
|
||||||
|
function M:add_widget(widget)
|
||||||
|
self:add_property(widget)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function M:create_from_prefab(widget_class, widget_name, prefab)
|
function M:create_from_prefab(widget_class, widget_name, prefab)
|
||||||
local instance = self.druid:new_widget(widget_class, widget_name, prefab)
|
local instance = self.druid:new_widget(widget_class, widget_name, prefab)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user