mirror of
https://github.com/Insality/druid.git
synced 2025-11-26 19:00:50 +01:00
Added navigation handler for gamepad/keyboard navigation.
This commit is contained in:
@@ -163,7 +163,6 @@ function M:_can_use_input_component(component)
|
||||
return can_by_blacklist and can_by_whitelist
|
||||
end
|
||||
|
||||
|
||||
local function schedule_late_init(self)
|
||||
if self._late_init_timer_id then
|
||||
return
|
||||
@@ -203,7 +202,6 @@ function M.create_druid_instance(context, style)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
---Create new Druid component instance
|
||||
---@generic T: druid.component
|
||||
---@param component T The component class to create
|
||||
@@ -223,7 +221,6 @@ function M:new(component, ...)
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
---Call this in gui_script final function.
|
||||
function M:final()
|
||||
local components = self.components_all
|
||||
@@ -240,7 +237,6 @@ function M:final()
|
||||
events.unsubscribe("druid.language_change", self.on_language_change, self)
|
||||
end
|
||||
|
||||
|
||||
---Remove created component from Druid instance.
|
||||
---
|
||||
---Component `on_remove` function will be invoked, if exist.
|
||||
@@ -292,7 +288,6 @@ function M:remove(component)
|
||||
return is_removed
|
||||
end
|
||||
|
||||
|
||||
---Get a context of Druid instance (usually a self of gui script)
|
||||
---@package
|
||||
---@return any context The Druid context
|
||||
@@ -300,7 +295,6 @@ function M:get_context()
|
||||
return self._context
|
||||
end
|
||||
|
||||
|
||||
---Get a style of Druid instance
|
||||
---@package
|
||||
---@return table style The Druid style table
|
||||
@@ -308,7 +302,6 @@ function M:get_style()
|
||||
return self._style
|
||||
end
|
||||
|
||||
|
||||
---Druid late update function called after initialization and before the regular update step.
|
||||
---This function is used to check the GUI state and perform actions after all components and nodes have been created.
|
||||
---An example use case is performing an auto stencil check in the GUI hierarchy for input components.
|
||||
@@ -326,7 +319,6 @@ function M:late_init()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---Call this in gui_script update function.
|
||||
---@param dt number Delta time
|
||||
function M:update(dt)
|
||||
@@ -341,7 +333,6 @@ function M:update(dt)
|
||||
self:_clear_late_remove()
|
||||
end
|
||||
|
||||
|
||||
---Call this in gui_script on_input function.
|
||||
---@param action_id hash Action_id from on_input
|
||||
---@param action table Action from on_input
|
||||
@@ -375,7 +366,6 @@ function M:on_input(action_id, action)
|
||||
return is_input_consumed
|
||||
end
|
||||
|
||||
|
||||
---Call this in gui_script on_message function.
|
||||
---@param message_id hash Message_id from on_message
|
||||
---@param message table Message from on_message
|
||||
@@ -396,7 +386,6 @@ function M:on_message(message_id, message, sender)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---Called when the window event occurs
|
||||
---@param window_event number The window event
|
||||
function M:on_window_event(window_event)
|
||||
@@ -418,7 +407,6 @@ function M:on_window_event(window_event)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---Calls the on_language_change function in all related components
|
||||
---This one called by global druid.on_language_change, but can be called manually to update all translations
|
||||
---@private
|
||||
@@ -429,7 +417,6 @@ function M:on_language_change()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---Set whitelist components for input processing.
|
||||
---If whitelist is not empty and component not contains in this list,
|
||||
---component will be not processed on the input step
|
||||
@@ -449,7 +436,6 @@ function M:set_whitelist(whitelist_components)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
---Set blacklist components for input processing.
|
||||
---If blacklist is not empty and component is contained in this list,
|
||||
---component will be not processed on the input step DruidInstance
|
||||
@@ -469,7 +455,6 @@ function M:set_blacklist(blacklist_components)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
---Remove all components on late remove step DruidInstance
|
||||
---@private
|
||||
function M:_clear_late_remove()
|
||||
@@ -483,7 +468,6 @@ function M:_clear_late_remove()
|
||||
self._late_remove = {}
|
||||
end
|
||||
|
||||
|
||||
---Create new Druid widget instance
|
||||
---@generic T: druid.component
|
||||
---@param widget T The widget class to create
|
||||
@@ -506,7 +490,6 @@ function M:new_widget(widget, template, nodes, ...)
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
local button = require("druid.base.button")
|
||||
---Create Button component
|
||||
---@param node string|node The node_id or gui.get_node(node_id)
|
||||
@@ -518,7 +501,6 @@ function M:new_button(node, callback, params, anim_node)
|
||||
return self:new(button, node, callback, params, anim_node)
|
||||
end
|
||||
|
||||
|
||||
local blocker = require("druid.base.blocker")
|
||||
---Create Blocker component
|
||||
---@param node string|node The node_id or gui.get_node(node_id)
|
||||
@@ -527,7 +509,6 @@ function M:new_blocker(node)
|
||||
return self:new(blocker, node)
|
||||
end
|
||||
|
||||
|
||||
local back_handler = require("druid.base.back_handler")
|
||||
---Create BackHandler component
|
||||
---@param callback function|event|nil The callback(self, custom_args) to call on back event
|
||||
@@ -537,7 +518,6 @@ function M:new_back_handler(callback, params)
|
||||
return self:new(back_handler, callback, params)
|
||||
end
|
||||
|
||||
|
||||
local hover = require("druid.base.hover")
|
||||
---Create Hover component
|
||||
---@param node string|node The node_id or gui.get_node(node_id)
|
||||
@@ -548,6 +528,14 @@ function M:new_hover(node, on_hover_callback, on_mouse_hover_callback)
|
||||
return self:new(hover, node, on_hover_callback, on_mouse_hover_callback)
|
||||
end
|
||||
|
||||
local navigation_handler = require("druid.base.navigation_handler")
|
||||
---Create NavigationHandler component
|
||||
---@param button druid.button The button that should be selected on start.
|
||||
---@param tolerance number|nil How far to allow misalignment on the perpendicular axis when finding the next button.
|
||||
---@return druid.navigation_handler navigation_handler The new navigation handler component.
|
||||
function M:new_navigation_handler(button, tolerance)
|
||||
return self:new(navigation_handler, button, tolerance)
|
||||
end
|
||||
|
||||
local text = require("druid.base.text")
|
||||
---Create Text component
|
||||
@@ -559,7 +547,6 @@ function M:new_text(node, value, adjust_type)
|
||||
return self:new(text, node, value, adjust_type)
|
||||
end
|
||||
|
||||
|
||||
local static_grid = require("druid.base.static_grid")
|
||||
---Create Grid component
|
||||
---@param parent_node string|node The node_id or gui.get_node(node_id). Parent of all Grid items.
|
||||
@@ -570,7 +557,6 @@ function M:new_grid(parent_node, item, in_row)
|
||||
return self:new(static_grid, parent_node, item, in_row)
|
||||
end
|
||||
|
||||
|
||||
local scroll = require("druid.base.scroll")
|
||||
---Create Scroll component
|
||||
---@param view_node string|node The node_id or gui.get_node(node_id). Will be used as user input node.
|
||||
@@ -580,7 +566,6 @@ function M:new_scroll(view_node, content_node)
|
||||
return self:new(scroll, view_node, content_node)
|
||||
end
|
||||
|
||||
|
||||
local drag = require("druid.base.drag")
|
||||
---Create Drag component
|
||||
---@param node string|node The node_id or gui.get_node(node_id). Will be used as user input node.
|
||||
@@ -590,7 +575,6 @@ function M:new_drag(node, on_drag_callback)
|
||||
return self:new(drag, node, on_drag_callback)
|
||||
end
|
||||
|
||||
|
||||
local swipe = require("druid.extended.swipe")
|
||||
---Create Swipe component
|
||||
---@param node string|node The node_id or gui.get_node(node_id). Will be used as user input node.
|
||||
@@ -600,7 +584,6 @@ function M:new_swipe(node, on_swipe_callback)
|
||||
return self:new(swipe, node, on_swipe_callback)
|
||||
end
|
||||
|
||||
|
||||
local lang_text = require("druid.extended.lang_text")
|
||||
---Create LangText component
|
||||
---@param node string|node The node_id or gui.get_node(node_id)
|
||||
@@ -611,7 +594,6 @@ function M:new_lang_text(node, locale_id, adjust_type)
|
||||
return self:new(lang_text, node, locale_id, adjust_type)
|
||||
end
|
||||
|
||||
|
||||
local slider = require("druid.extended.slider")
|
||||
---Create Slider component
|
||||
---@param pin_node string|node The node_id or gui.get_node(node_id).
|
||||
@@ -622,7 +604,6 @@ function M:new_slider(pin_node, end_pos, callback)
|
||||
return self:new(slider, pin_node, end_pos, callback)
|
||||
end
|
||||
|
||||
|
||||
local input = require("druid.extended.input")
|
||||
---Create Input component
|
||||
---@param click_node string|node Button node to enable input component
|
||||
@@ -633,7 +614,6 @@ function M:new_input(click_node, text_node, keyboard_type)
|
||||
return self:new(input, click_node, text_node, keyboard_type)
|
||||
end
|
||||
|
||||
|
||||
local data_list = require("druid.extended.data_list")
|
||||
---Create DataList component
|
||||
---@param druid_scroll druid.scroll The Scroll instance for Data List component
|
||||
@@ -644,7 +624,6 @@ function M:new_data_list(druid_scroll, druid_grid, create_function)
|
||||
return self:new(data_list, druid_scroll, druid_grid, create_function)
|
||||
end
|
||||
|
||||
|
||||
local timer_component = require("druid.extended.timer")
|
||||
---Create Timer component
|
||||
---@param node string|node Gui text node
|
||||
@@ -656,7 +635,6 @@ function M:new_timer(node, seconds_from, seconds_to, callback)
|
||||
return self:new(timer_component, node, seconds_from, seconds_to, callback)
|
||||
end
|
||||
|
||||
|
||||
local progress = require("druid.extended.progress")
|
||||
---Create Progress component
|
||||
---@param node string|node Progress bar fill node or node name
|
||||
@@ -667,7 +645,6 @@ function M:new_progress(node, key, init_value)
|
||||
return self:new(progress, node, key, init_value)
|
||||
end
|
||||
|
||||
|
||||
local layout = require("druid.extended.layout")
|
||||
---Create Layout component
|
||||
---@param node string|node The node_id or gui.get_node(node_id).
|
||||
@@ -677,7 +654,6 @@ function M:new_layout(node, mode)
|
||||
return self:new(layout, node, mode)
|
||||
end
|
||||
|
||||
|
||||
local container = require("druid.extended.container")
|
||||
---Create Container component
|
||||
---@param node string|node The node_id or gui.get_node(node_id).
|
||||
@@ -688,7 +664,6 @@ function M:new_container(node, mode, callback)
|
||||
return self:new(container, node, mode, callback)
|
||||
end
|
||||
|
||||
|
||||
local hotkey = require("druid.extended.hotkey")
|
||||
---Create Hotkey component
|
||||
---@param keys_array string|string[] Keys for trigger action. Should contains one action key and any amount of modificator keys
|
||||
@@ -699,7 +674,6 @@ function M:new_hotkey(keys_array, callback, callback_argument)
|
||||
return self:new(hotkey, keys_array, callback, callback_argument)
|
||||
end
|
||||
|
||||
|
||||
local rich_text = require("druid.custom.rich_text.rich_text")
|
||||
---Create RichText component.
|
||||
---@param text_node string|node The text node to make Rich Text
|
||||
@@ -709,7 +683,6 @@ function M:new_rich_text(text_node, value)
|
||||
return self:new(rich_text, text_node, value)
|
||||
end
|
||||
|
||||
|
||||
local rich_input = require("druid.custom.rich_input.rich_input")
|
||||
---Create RichInput component.
|
||||
---As a template please check rich_input.gui layout.
|
||||
@@ -720,5 +693,4 @@ function M:new_rich_input(template, nodes)
|
||||
return self:new(rich_input, template, nodes)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user