mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 02:17:52 +02:00
Add Bind layout and hotkey node bind
This commit is contained in:
parent
c33dbd5942
commit
4e71fee9ba
@ -445,6 +445,33 @@ function M:bind_grid(grid)
|
||||
end
|
||||
|
||||
|
||||
---Bind the layout component to recalculate
|
||||
-- scroll size on layout changes
|
||||
---@param layout druid.layout|nil Druid layout component
|
||||
---@return druid.scroll self Current scroll instance
|
||||
function M:bind_layout(layout)
|
||||
if self._layout_on_change then
|
||||
self._layout_on_change:unsubscribe(self._layout_on_change_callback)
|
||||
|
||||
self._layout_on_change = nil
|
||||
self._layout_on_change_callback = nil
|
||||
end
|
||||
|
||||
if not layout then
|
||||
return self
|
||||
end
|
||||
|
||||
self._layout_on_change = layout.on_size_changed
|
||||
self._layout_on_change_callback = function(size)
|
||||
self:set_size(size)
|
||||
end
|
||||
self._layout_on_change:subscribe(self._layout_on_change_callback)
|
||||
self:set_size(layout:get_size())
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
---Strict drag scroll area. Useful for
|
||||
-- restrict events outside stencil node
|
||||
---@param node node|string Gui node
|
||||
|
@ -243,6 +243,13 @@ function M:remove(index, shift_policy, is_instant)
|
||||
end
|
||||
|
||||
|
||||
---Return items count in grid
|
||||
---@return number count The items count in grid
|
||||
function M:get_items_count()
|
||||
return #self.nodes
|
||||
end
|
||||
|
||||
|
||||
---Return grid content size
|
||||
---@return vector3 size The grid content size
|
||||
function M:get_size()
|
||||
|
@ -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
|
||||
|
@ -589,13 +589,12 @@ By the way, the PR number of this release is #300. Sounds veeery huge and long j
|
||||
|
||||
- **Widgets** are here! This is the evolution of custom components, but with no boilerplate code and far more convenient usage. All Druid examples have been migrated to use widgets. Widgets are now a default way to create a new custom components (basically any of your GUI element on the screen).
|
||||
|
||||
- **Experimental features** like shader pipeline in GUI and widget usage in GO scripts. Curious Defolders can find examples of these features and try them out.
|
||||
|
||||
- **No more calling `druid.register()`!** All Druid components are now available by default with `self.druid:new_*` functions, making getting started simpler than ever.
|
||||
|
||||
- **Druid UI Kit** brings fonts, atlas, and ready-to-use GUI templates right out of the box - a long-requested feature that lets you use Druid UI elements instantly in your projects. I think now it's a possible to create a external dependencies with a set of GUI templates and Druid's widgets to make a ready to use UI kit for projects! The flow to init widgets always now from two steps:
|
||||
- Add GUI template to your GUI scene
|
||||
- Call `self.widget = self.druid:new_widget(widget_file, "template_id")` to init widget
|
||||
- Call `self.widget = self.druid:new_widget(widget_file, "template_id", "tempalate_id/root")` to clone root node from template and init widget from it
|
||||
|
||||
|
||||
- **Completely reworked documentation** with full code annotations. Start with the [Quick API Reference](/api/quick_api_reference.md) to get familiar with **Druid**. Any documentation are generated from the code annotations, so in case to update documentation, you need to update annotations in the code.
|
||||
|
Loading…
x
Reference in New Issue
Block a user