Skip to content

Commit 4e71fee

Browse files
committed
Add Bind layout and hotkey node bind
1 parent c33dbd5 commit 4e71fee

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

druid/base/scroll.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,33 @@ function M:bind_grid(grid)
445445
end
446446

447447

448+
---Bind the layout component to recalculate
449+
-- scroll size on layout changes
450+
---@param layout druid.layout|nil Druid layout component
451+
---@return druid.scroll self Current scroll instance
452+
function M:bind_layout(layout)
453+
if self._layout_on_change then
454+
self._layout_on_change:unsubscribe(self._layout_on_change_callback)
455+
456+
self._layout_on_change = nil
457+
self._layout_on_change_callback = nil
458+
end
459+
460+
if not layout then
461+
return self
462+
end
463+
464+
self._layout_on_change = layout.on_size_changed
465+
self._layout_on_change_callback = function(size)
466+
self:set_size(size)
467+
end
468+
self._layout_on_change:subscribe(self._layout_on_change_callback)
469+
self:set_size(layout:get_size())
470+
471+
return self
472+
end
473+
474+
448475
---Strict drag scroll area. Useful for
449476
-- restrict events outside stencil node
450477
---@param node node|string Gui node

druid/base/static_grid.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ function M:remove(index, shift_policy, is_instant)
243243
end
244244

245245

246+
---Return items count in grid
247+
---@return number count The items count in grid
248+
function M:get_items_count()
249+
return #self.nodes
250+
end
251+
252+
246253
---Return grid content size
247254
---@return vector3 size The grid content size
248255
function M:get_size()

druid/extended/hotkey.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local component = require("druid.component")
2323
---@field style druid.hotkey.style The style of the hotkey component
2424
---@field private _hotkeys table The list of hotkeys
2525
---@field private _modificators table The list of modificators
26+
---@field private _node node|nil The node to bind the hotkey to
2627
local M = component.create("hotkey")
2728

2829

@@ -35,7 +36,7 @@ function M:init(keys, callback, callback_argument)
3536

3637
self._hotkeys = {}
3738
self._modificators = {}
38-
39+
self._node = nil
3940
self.on_hotkey_pressed = event.create()
4041
self.on_hotkey_released = event.create(callback)
4142

@@ -134,6 +135,10 @@ function M:on_input(action_id, action)
134135
return false
135136
end
136137

138+
if self._node and not gui.is_enabled(self._node, true) then
139+
return false
140+
end
141+
137142
if self._modificators[action_id] ~= nil and action.pressed then
138143
self._modificators[action_id] = true
139144
end
@@ -192,4 +197,14 @@ function M:set_repeat(is_enabled_repeated)
192197
end
193198

194199

200+
---If node is provided, the hotkey can be disabled, if the node is disabled
201+
---@param node node|nil The node to bind the hotkey to. Nil to unbind the node
202+
---@return druid.hotkey self Current instance
203+
function M:bind_node(node)
204+
self._node = node
205+
206+
return self
207+
end
208+
209+
195210
return M

druid/extended/layout.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ function M:init(node_or_node_id, layout_type)
5656
self.size = gui.get_size(self.node)
5757

5858
self.padding = gui.get_slice9(self.node)
59-
-- Grab default margins from slice9 z/w values
59+
-- Margin X is a Slice9 R Value
60+
-- Margin Y is a Slice9 B Value
6061
self.margin = { x = self.padding.z, y = self.padding.w }
61-
-- Use symmetrical padding from x/z
62+
-- Padding X is a Slice9 L Value
63+
-- Padding Y is a Slice9 T Value
6264
self.padding.z = self.padding.x
6365
self.padding.w = self.padding.y
6466

@@ -86,6 +88,12 @@ function M:get_entities()
8688
end
8789

8890

91+
---@return number count The count of entities in layout
92+
function M:get_entities_count()
93+
return #self.entities
94+
end
95+
96+
8997
---@param node node The node to set the index of
9098
---@param index number The index to set the node to
9199
---@return druid.layout self for chaining

wiki/changelog.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,12 @@ By the way, the PR number of this release is #300. Sounds veeery huge and long j
589589

590590
- **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).
591591

592-
- **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.
593-
594592
- **No more calling `druid.register()`!** All Druid components are now available by default with `self.druid:new_*` functions, making getting started simpler than ever.
595593

596594
- **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:
597595
- Add GUI template to your GUI scene
598596
- Call `self.widget = self.druid:new_widget(widget_file, "template_id")` to init widget
597+
- 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
599598

600599

601600
- **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.

0 commit comments

Comments
 (0)