From 0e9a0cdee94a6b32f5435ae632d23abf0fc76add Mon Sep 17 00:00:00 2001 From: getzze Date: Fri, 31 Mar 2017 23:55:25 +0100 Subject: [PATCH 1/2] doc: improve doc for creating new widget --- docs/04-new-widgets.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/04-new-widgets.md b/docs/04-new-widgets.md index b519d8552..150698679 100644 --- a/docs/04-new-widgets.md +++ b/docs/04-new-widgets.md @@ -1,7 +1,7 @@ # Creating new widget -All widgets have to be generated via this function so that -the needed signals are added and mouse input handling is set up. +All widgets have to be generated by the `wibox.widget.base.make_widget` function +so that the needed signals are added and mouse input handling is set up. The returned widget will have a `:buttons` member function that can be used to register a set of mouse button events with the widget. @@ -111,3 +111,8 @@ looks like this: widget:after_draw_child(context, cr, child_index, child, width, height) end widget:after_draw_children(context, cr, width, height) + +The `:set_children()` method is called recursively when setting a widget with +the declarative layout system, therefore the method should be well defined. +It should probably hook to the `:add` or `:add_widget` methods or be overridden +to do nothing. From 59662bc971d63459c4df5a9575375b71d1698cb8 Mon Sep 17 00:00:00 2001 From: getzze Date: Fri, 31 Mar 2017 23:56:20 +0100 Subject: [PATCH 2/2] wibox.widget.base: do not call set_children if children is nil --- docs/04-new-widgets.md | 6 +++--- lib/wibox/widget/base.lua | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/04-new-widgets.md b/docs/04-new-widgets.md index 150698679..4203f3d3b 100644 --- a/docs/04-new-widgets.md +++ b/docs/04-new-widgets.md @@ -112,7 +112,7 @@ looks like this: end widget:after_draw_children(context, cr, width, height) -The `:set_children()` method is called recursively when setting a widget with +The `:set_children()` method gets called recursively when setting a widget with the declarative layout system, therefore the method should be well defined. -It should probably hook to the `:add` or `:add_widget` methods or be overridden -to do nothing. +It should probably hook into the `:add` or `:add_widget` methods or be +overridden to do nothing. diff --git a/lib/wibox/widget/base.lua b/lib/wibox/widget/base.lua index 351984328..2023f6e4e 100644 --- a/lib/wibox/widget/base.lua +++ b/lib/wibox/widget/base.lua @@ -504,7 +504,9 @@ local function drill(ids, content) end end -- Replace all children (if any) with the new ones. - l:set_children(widgets) + if widgets then + l:set_children(widgets) + end return l, id end