diff --git a/druid/component.lua b/druid/component.lua index 350ebcb..e7deb30 100644 --- a/druid/component.lua +++ b/druid/component.lua @@ -39,29 +39,6 @@ local M = {} 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 function M.create_uid() @@ -310,8 +287,8 @@ function M:__get_interests() end local interests = {} - for index = 1, #M.ALL_INTERESTS do - local interest = M.ALL_INTERESTS[index] + for index = 1, #const.ALL_INTERESTS do + local interest = const.ALL_INTERESTS[index] if self[interest] and type(self[interest]) == "function" then table.insert(interests, interest) end diff --git a/druid/const.lua b/druid/const.lua index 3ebb4d5..46ac38c 100755 --- a/druid/const.lua +++ b/druid/const.lua @@ -27,6 +27,18 @@ M.ON_LAYOUT_CHANGE = "on_layout_change" M.ON_WINDOW_RESIZED = "on_window_resized" 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") -- Components with higher priority value processed first diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 1a4547e..e39fad1 100755 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -49,7 +49,7 @@ end 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 return end @@ -215,8 +215,8 @@ function M:initialize(context, style) self.components_all = {} self.components_interest = {} - for i = 1, #base_component.ALL_INTERESTS do - self.components_interest[base_component.ALL_INTERESTS[i]] = {} + for i = 1, #const.ALL_INTERESTS do + self.components_interest[const.ALL_INTERESTS[i]] = {} end 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. ---@private 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 late_init_components[1]:on_late_init() table.remove(late_init_components, 1) 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 set_input_state(self, true) end @@ -337,7 +337,7 @@ end function M:update(dt) 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 components[i]:update(dt) end @@ -354,7 +354,7 @@ end function M:on_input(action_id, action) 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) local is_input_consumed = process_input(self, action_id, action, components) @@ -372,13 +372,13 @@ end function M:on_message(message_id, message, sender) if message_id == const.MSG_LAYOUT_CHANGED then -- 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 components[i]:on_layout_change() end else -- 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 components[i]:on_message(message_id, message, sender) end @@ -388,17 +388,17 @@ end function M:on_window_event(window_event) 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 components[i]:on_focus_lost() end 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 components[i]:on_focus_gained() end 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 components[i]:on_window_resized() end @@ -411,7 +411,7 @@ end -- call manualy to update all translations ---@private 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 components[i]:on_language_change() end diff --git a/druid/widget/properties_panel/properties_panel.lua b/druid/widget/properties_panel/properties_panel.lua index a23f5c8..6934dda 100644 --- a/druid/widget/properties_panel/properties_panel.lua +++ b/druid/widget/properties_panel/properties_panel.lua @@ -212,6 +212,13 @@ function M:add_left_right_selector(text, value, on_change_callback) end + +---@param widget druid.widget +function M:add_widget(widget) + self:add_property(widget) +end + + ---@private function M:create_from_prefab(widget_class, widget_name, prefab) local instance = self.druid:new_widget(widget_class, widget_name, prefab)