Skip to content

Commit

Permalink
Widgets WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Nov 18, 2024
1 parent 299f850 commit dc8f3b9
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 25 deletions.
12 changes: 11 additions & 1 deletion druid/extended/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function M:init(node_or_node_id, layout_type)

self.is_dirty = true
self.entities = {}
self.size = gui.get_size(self.node)

self.padding = gui.get_slice9(self.node)
self.margin = { x = self.padding.z, y = self.padding.w }
Expand All @@ -52,7 +53,7 @@ function M:init(node_or_node_id, layout_type)
self.is_resize_height = false
self.is_justify = false

self.on_size_changed = event.create()
self.on_size_changed = event.create() --[[@as druid.event.on_size_changed]]
end


Expand Down Expand Up @@ -152,6 +153,9 @@ function M:add(node_or_node_id)
end


---Remove node from layout
---@param node_or_node_id node|string node_or_node_id
---@return druid.layout self for chaining
function M:remove(node_or_node_id)
local node = type(node_or_node_id) == "table" and node_or_node_id.node or self:get_node(node_or_node_id)

Expand All @@ -167,6 +171,11 @@ function M:remove(node_or_node_id)
end


---@return vector3
function M:get_size()
return self.size
end

---@return druid.layout
function M:refresh_layout()
local layout_node = self.node
Expand Down Expand Up @@ -295,6 +304,7 @@ function M:refresh_layout()
size.y = rows_data.total_height + padding.y + padding.w
end
gui.set_size(layout_node, size)
self.size = size

self.on_size_changed(size)
end
Expand Down
11 changes: 7 additions & 4 deletions druid/widget/properties_panel/properties/property_button.gui
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ nodes {
type: TYPE_BOX
texture: "druid/empty"
id: "root"
pivot: PIVOT_NW
adjust_mode: ADJUST_MODE_STRETCH
inherit_alpha: true
visible: false
}
nodes {
position {
y: -20.0
x: -200.0
}
scale {
x: 0.65
Expand Down Expand Up @@ -58,8 +57,7 @@ nodes {
}
nodes {
position {
x: 267.0
y: -20.0
x: 200.0
}
size {
x: 226.0
Expand All @@ -73,6 +71,7 @@ nodes {
type: TYPE_BOX
texture: "druid/rect_round2_width2"
id: "button"
pivot: PIVOT_E
parent: "root"
inherit_alpha: true
slice9 {
Expand All @@ -84,6 +83,7 @@ nodes {
}
nodes {
position {
x: -113.0
y: -20.0
}
size {
Expand All @@ -104,6 +104,9 @@ nodes {
inherit_alpha: true
}
nodes {
position {
x: -113.0
}
scale {
x: 0.65
y: 0.65
Expand Down
5 changes: 5 additions & 0 deletions druid/widget/properties_panel/properties/property_button.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---@class property_button: druid.widget
---@field root node
---@field container druid.container
---@field text_name druid.text
---@field button druid.button
---@field text_button druid.text
Expand All @@ -18,6 +19,10 @@ function M:init(template, nodes)

self.button = self.druid:new_button("button", self.on_click)
self.text_button = self.druid:new_text("text_button")

self.container = self.druid:new_container(self.root)
self.container:add_container("text_name")
self.container:add_container("button")
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ nodes {
type: TYPE_BOX
texture: "druid/empty"
id: "root"
pivot: PIVOT_NW
adjust_mode: ADJUST_MODE_STRETCH
inherit_alpha: true
visible: false
}
nodes {
position {
y: -20.0
x: -200.0
}
scale {
x: 0.65
Expand Down Expand Up @@ -58,8 +57,7 @@ nodes {
}
nodes {
position {
x: 174.0
y: -20.0
x: -20.0
}
size {
x: 40.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function M:init(template, nodes)
self.text_name = self.druid:new_lang_text("text_name")

self.button = self.druid:new_button("button", self.on_click)

self.container = self.druid:new_container(self.root)
self.container:add_container("text_name")
self.container:add_container("button")
end


Expand Down
15 changes: 6 additions & 9 deletions druid/widget/properties_panel/properties/property_slider.gui
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ nodes {
type: TYPE_BOX
texture: "druid/empty"
id: "root"
pivot: PIVOT_NW
adjust_mode: ADJUST_MODE_STRETCH
inherit_alpha: true
visible: false
}
nodes {
position {
y: -20.0
x: -200.0
}
scale {
x: 0.65
Expand Down Expand Up @@ -58,11 +57,10 @@ nodes {
}
nodes {
position {
x: 234.0
y: -20.0
x: 40.0
}
size {
x: 160.0
x: 190.0
y: 40.0
}
color {
Expand All @@ -78,7 +76,7 @@ nodes {
}
nodes {
size {
x: 160.0
x: 166.0
y: 8.0
}
color {
Expand All @@ -100,7 +98,7 @@ nodes {
}
nodes {
position {
x: -68.0
x: -83.0
}
size {
x: 24.0
Expand All @@ -125,8 +123,7 @@ nodes {
}
nodes {
position {
x: 380.0
y: -20.0
x: 200.0
}
size {
x: 60.0
Expand Down
8 changes: 7 additions & 1 deletion druid/widget/properties_panel/properties/property_slider.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---@class property_slider: druid.widget
---@field root node
---@field container druid.container
---@field druid druid_instance
---@field text_name druid.lang_text
---@field text_value druid.text
Expand All @@ -19,12 +20,17 @@ function M:init(template, nodes)

self.text_name = self.druid:new_lang_text("text_name") --[[@as druid.lang_text]]
self.text_value = self.druid:new_text("text_value")
self.slider = self.druid:new_slider("slider_pin", vmath.vector3(68, 0, 0), self._on_slider_change_by_user) --[[@as druid.slider]]
self.slider = self.druid:new_slider("slider_pin", vmath.vector3(183, 0, 0), self._on_slider_change_by_user) --[[@as druid.slider]]
self.slider:set_input_node("slider")

self:set_text_function(function(value)
return math.floor(value * 100) .. "%"
end)

self.container = self.druid:new_container(self.root)
self.container:add_container("text_name")
self.container:add_container("slider")
self.container:add_container("button")
end


Expand Down
16 changes: 10 additions & 6 deletions druid/widget/properties_panel/properties_panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ function M:init(template, nodes)
self.container = self.druid:new_container(self.root)
self.container:add_container("text_header")
self.container:add_container("icon_drag")
local container_scroll_view = self.container:add_container("scroll_view")
container_scroll_view:add_container("scroll_content")

self.container_scroll_view = self.container:add_container("scroll_view")
self.contaienr_scroll_content = self.container_scroll_view:add_container("scroll_content")
end


Expand All @@ -62,10 +63,7 @@ end


function M:on_size_changed(new_size)
new_size.x = new_size.x + 8
new_size.y = new_size.y + 50 + 8

self.container:set_size(new_size.x, new_size.y, gui.PIVOT_N)
self.container:set_size(new_size.x + 8, new_size.y + 50 + 8, gui.PIVOT_N)
end


Expand All @@ -85,6 +83,8 @@ function M:add_checkbox(text_id, initial_value, on_change_callback)
gui.set_enabled(instance.root, true)
self.layout:add(instance.root)
table.insert(self.properties, instance)
instance.container:set_size(self.layout:get_size().x)

gui.set_enabled(self.text_no_properties, false)

return instance
Expand All @@ -104,6 +104,8 @@ function M:add_slider(text_id, initial_value, on_change_callback)
gui.set_enabled(instance.root, true)
self.layout:add(instance.root)
table.insert(self.properties, instance)
instance.container:set_size(self.layout:get_size().x)

gui.set_enabled(self.text_no_properties, false)

instance.slider.on_change_value:subscribe(function(_, value)
Expand All @@ -125,6 +127,8 @@ function M:add_button(text_id, on_click_callback, callback_context)
gui.set_enabled(instance.root, true)
self.layout:add(instance.root)
table.insert(self.properties, instance)
instance.container:set_size(self.layout:get_size().x)

gui.set_enabled(self.text_no_properties, false)

if on_click_callback then
Expand Down

0 comments on commit dc8f3b9

Please sign in to comment.