template: Fix forced_height/forced_width and other fixup.
Thanks for the reviews!
This commit is contained in:
parent
452d21a634
commit
c8016f0c0d
|
@ -56,7 +56,7 @@ local gtimer = require("gears.timer")
|
||||||
|
|
||||||
local template = {
|
local template = {
|
||||||
mt = {},
|
mt = {},
|
||||||
queued_updates = {},
|
queued_updates = setmetatable({}, {__mode="k"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
local function lazy_load_child(self)
|
local function lazy_load_child(self)
|
||||||
|
@ -68,6 +68,14 @@ local function lazy_load_child(self)
|
||||||
wbase.check_widget(widget_instance)
|
wbase.check_widget(widget_instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- If `forced_height` and `forced_width` are set on the template, then
|
||||||
|
-- that's equivalent of setting them on the child.
|
||||||
|
for _, prop in ipairs { "forced_width", "forced_height" } do
|
||||||
|
if not widget_instance[prop] then
|
||||||
|
widget_instance[prop] = self._private[prop]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self._private.widget = widget_instance
|
self._private.widget = widget_instance
|
||||||
|
|
||||||
local rem = {}
|
local rem = {}
|
||||||
|
@ -131,12 +139,11 @@ end
|
||||||
|
|
||||||
--- Update the widget.
|
--- Update the widget.
|
||||||
--
|
--
|
||||||
-- This function will call the `update_callback` function at the end of the
|
-- Updates are batched. Multiple calls to @{update} within the same event loop
|
||||||
-- current GLib event loop. Updates are batched by event loop, it means that the
|
-- iteration will be collected. At the end of the loop iteration, they will be
|
||||||
-- widget can only be update once by event loop. If the `template:update` method
|
-- combined into a single call to the function provided as @{update_callback}.
|
||||||
-- is called multiple times during the same GLib event loop, only the first call
|
-- All the properties of the table argument are collected and provided to the
|
||||||
-- will be run.
|
-- queued @{update_callback} in the table parameter.
|
||||||
-- All arguments are passed to the queued `update_callback` call.
|
|
||||||
--
|
--
|
||||||
-- @tparam[opt={}] table args A table to pass to the widget update function.
|
-- @tparam[opt={}] table args A table to pass to the widget update function.
|
||||||
-- @method update
|
-- @method update
|
||||||
|
@ -161,7 +168,8 @@ end
|
||||||
--
|
--
|
||||||
-- Note that this will discard the existing widget instance. Thus, any
|
-- Note that this will discard the existing widget instance. Thus, any
|
||||||
-- `set_property` will no longer be honored. `bind_property`, on the other hand,
|
-- `set_property` will no longer be honored. `bind_property`, on the other hand,
|
||||||
-- will still be honored.
|
-- will still be honored. The connections stay intact, but until the signal
|
||||||
|
-- fires again, the value will stay `nil`.
|
||||||
--
|
--
|
||||||
-- @property template
|
-- @property template
|
||||||
-- @tparam[opt=nil] table|nil template The new widget to use as a
|
-- @tparam[opt=nil] table|nil template The new widget to use as a
|
||||||
|
@ -187,6 +195,24 @@ function template:get_children_by_id(...)
|
||||||
return w:get_children_by_id(...)
|
return w:get_children_by_id(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- The width and height need to be forwarded to the inner widget so it's fit
|
||||||
|
-- is properly overriden. The other way would be to do it in `:fit()`, but
|
||||||
|
-- since they are methods, they might have been overriden by the widget and
|
||||||
|
-- have a special meaning.
|
||||||
|
for _, prop in ipairs {"forced_width", "forced_height" } do
|
||||||
|
template["get_"..prop] = function(self)
|
||||||
|
return self._private.widget
|
||||||
|
and self._private.widget[prop]
|
||||||
|
or self._private[prop]
|
||||||
|
end
|
||||||
|
template["set_"..prop] = function(self, value)
|
||||||
|
if self._private.widget then
|
||||||
|
self._private.widget[prop] = value
|
||||||
|
end
|
||||||
|
self._private[prop] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Set a property on one or more template sub-widget instances.
|
--- Set a property on one or more template sub-widget instances.
|
||||||
--
|
--
|
||||||
-- This method allows to set a value at any time on any of the sub widget of
|
-- This method allows to set a value at any time on any of the sub widget of
|
||||||
|
@ -196,9 +222,7 @@ end
|
||||||
--
|
--
|
||||||
--@DOC_wibox_widget_template_set_property_existing_EXAMPLE@
|
--@DOC_wibox_widget_template_set_property_existing_EXAMPLE@
|
||||||
--
|
--
|
||||||
-- It is also possible to take this one step further and apply a property
|
-- This example adds an inline setter method for `client`:
|
||||||
-- to the entire sub-widget tree. This allows users to implement their own
|
|
||||||
-- template even if it doesn't use the same "roles" as the default one:
|
|
||||||
--
|
--
|
||||||
--@DOC_wibox_widget_template_set_property_custom_EXAMPLE@
|
--@DOC_wibox_widget_template_set_property_custom_EXAMPLE@
|
||||||
--
|
--
|
||||||
|
@ -347,6 +371,8 @@ function template:get_update_callback()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Undocumented, for backward compatibility
|
-- Undocumented, for backward compatibility
|
||||||
|
-- @deprecatedmethod
|
||||||
|
-- @hidden
|
||||||
function template:get_create_callback()
|
function template:get_create_callback()
|
||||||
return rawget(lazy_load_child(self), "create_callback")
|
return rawget(lazy_load_child(self), "create_callback")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue