summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-05-26 23:09:50 +0200
committerAylur <[email protected]>2024-05-26 23:09:50 +0200
commitefa11dfdad3fdc52cc27239378f5d4c44239e6e2 (patch)
treeb0011b38e73d40513825cae422276756e992a0e7
parent57a49504bfc6cdc8d34c5f9f968a12a06149e817 (diff)
fix(lua): child and children bindings
-rw-r--r--lua/astal/widget.lua24
1 files changed, 21 insertions, 3 deletions
diff --git a/lua/astal/widget.lua b/lua/astal/widget.lua
index ade000e..2f58b7a 100644
--- a/lua/astal/widget.lua
+++ b/lua/astal/widget.lua
@@ -14,6 +14,18 @@ local function filter(tbl, fn)
return copy
end
+local function set_child(parent, child)
+ if parent.get_child ~= nil then
+ local rm = parent:get_child()
+ if rm ~= nil then
+ parent:remove(rm)
+ end
+ end
+ if parent.add ~= nil then
+ parent:add(child)
+ end
+end
+
Gtk.Widget._attribute.css = {
get = Astal.widget_get_css,
set = Astal.widget_set_css,
@@ -92,9 +104,15 @@ local function astalify(ctor)
local widget = ctor(props)
for prop, binding in pairs(bindings) do
- widget.on_destroy = binding:subscribe(function(v)
- widget[prop] = v
- end)
+ if prop == "child" then
+ widget.on_destroy = binding:subscribe(function(v)
+ set_child(widget, v)
+ end)
+ else
+ widget.on_destroy = binding:subscribe(function(v)
+ widget[prop] = v
+ end)
+ end
end
widget.visible = visible