mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Add Bind layout and hotkey node bind
This commit is contained in:
@@ -23,6 +23,7 @@ local component = require("druid.component")
|
||||
---@field style druid.hotkey.style The style of the hotkey component
|
||||
---@field private _hotkeys table The list of hotkeys
|
||||
---@field private _modificators table The list of modificators
|
||||
---@field private _node node|nil The node to bind the hotkey to
|
||||
local M = component.create("hotkey")
|
||||
|
||||
|
||||
@@ -35,7 +36,7 @@ function M:init(keys, callback, callback_argument)
|
||||
|
||||
self._hotkeys = {}
|
||||
self._modificators = {}
|
||||
|
||||
self._node = nil
|
||||
self.on_hotkey_pressed = event.create()
|
||||
self.on_hotkey_released = event.create(callback)
|
||||
|
||||
@@ -134,6 +135,10 @@ function M:on_input(action_id, action)
|
||||
return false
|
||||
end
|
||||
|
||||
if self._node and not gui.is_enabled(self._node, true) then
|
||||
return false
|
||||
end
|
||||
|
||||
if self._modificators[action_id] ~= nil and action.pressed then
|
||||
self._modificators[action_id] = true
|
||||
end
|
||||
@@ -192,4 +197,14 @@ function M:set_repeat(is_enabled_repeated)
|
||||
end
|
||||
|
||||
|
||||
---If node is provided, the hotkey can be disabled, if the node is disabled
|
||||
---@param node node|nil The node to bind the hotkey to. Nil to unbind the node
|
||||
---@return druid.hotkey self Current instance
|
||||
function M:bind_node(node)
|
||||
self._node = node
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@@ -56,9 +56,11 @@ function M:init(node_or_node_id, layout_type)
|
||||
self.size = gui.get_size(self.node)
|
||||
|
||||
self.padding = gui.get_slice9(self.node)
|
||||
-- Grab default margins from slice9 z/w values
|
||||
-- Margin X is a Slice9 R Value
|
||||
-- Margin Y is a Slice9 B Value
|
||||
self.margin = { x = self.padding.z, y = self.padding.w }
|
||||
-- Use symmetrical padding from x/z
|
||||
-- Padding X is a Slice9 L Value
|
||||
-- Padding Y is a Slice9 T Value
|
||||
self.padding.z = self.padding.x
|
||||
self.padding.w = self.padding.y
|
||||
|
||||
@@ -86,6 +88,12 @@ function M:get_entities()
|
||||
end
|
||||
|
||||
|
||||
---@return number count The count of entities in layout
|
||||
function M:get_entities_count()
|
||||
return #self.entities
|
||||
end
|
||||
|
||||
|
||||
---@param node node The node to set the index of
|
||||
---@param index number The index to set the node to
|
||||
---@return druid.layout self for chaining
|
||||
|
Reference in New Issue
Block a user