From bf74ca8a8c2ec4035da3ca75afe1e5e5c3dda60c Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 26 May 2016 16:26:50 -0400 Subject: [PATCH] mirror: Enable the property system And add the missing documentation --- lib/wibox/container/mirror.lua | 60 +++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/lib/wibox/container/mirror.lua b/lib/wibox/container/mirror.lua index 975f57caf..d00e93f2a 100644 --- a/lib/wibox/container/mirror.lua +++ b/lib/wibox/container/mirror.lua @@ -9,57 +9,63 @@ local type = type local error = error -local pairs = pairs local ipairs = ipairs local setmetatable = setmetatable local base = require("wibox.widget.base") local matrix = require("gears.matrix") +local util = require("awful.util") local mirror = { mt = {} } -- Layout this layout function mirror:layout(_, width, height) - if not self.widget then return end + if not self._private.widget then return end local m = matrix.identity local t = { x = 0, y = 0 } -- translation local s = { x = 1, y = 1 } -- scale - if self.horizontal then + if self._private.horizontal then t.x = width s.x = -1 end - if self.vertical then + if self._private.vertical then t.y = height s.y = -1 end m = m:translate(t.x, t.y) m = m:scale(s.x, s.y) - return { base.place_widget_via_matrix(self.widget, m, width, height) } + return { base.place_widget_via_matrix(self._private.widget, m, width, height) } end -- Fit this layout into the given area function mirror:fit(context, ...) - if not self.widget then + if not self._private.widget then return 0, 0 end - return base.fit_widget(self, context, self.widget, ...) + return base.fit_widget(self, context, self._private.widget, ...) end ---- Set the widget that this layout mirrors. --- @param widget The widget to mirror +--- The widget to be reflected. +-- @property widget +-- @tparam widget widget The widget + function mirror:set_widget(widget) if widget then base.check_widget(widget) end - self.widget = widget + self._private.widget = widget self:emit_signal("widget::layout_changed") end +function mirror:get_widget() + return self._private.widget +end + --- Get the number of children element -- @treturn table The children function mirror:get_children() - return {self.widget} + return {self._private.widget} end --- Replace the layout children @@ -71,13 +77,11 @@ end --- Reset this layout. The widget will be removed and the axes reset. function mirror:reset() - self.horizontal = false - self.vertical = false + self._private.horizontal = false + self._private.vertical = false self:set_widget(nil) end ---- Set the reflection of this mirror layout. --- @param reflection a table which contains new values for horizontal and/or vertical (booleans) function mirror:set_reflection(reflection) if type(reflection) ~= 'table' then error("Invalid type of reflection for mirror layout: " .. @@ -85,16 +89,20 @@ function mirror:set_reflection(reflection) end for _, ref in ipairs({"horizontal", "vertical"}) do if reflection[ref] ~= nil then - self[ref] = reflection[ref] + self._private[ref] = reflection[ref] end end self:emit_signal("widget::layout_changed") end --- Get the reflection of this mirror layout. --- @return a table of booleans with the keys "horizontal", "vertical". +-- @property reflection +-- @param table reflection A table of booleans with the keys "horizontal", "vertical". +-- @param boolean reflection.horizontal +-- @param boolean reflection.vertical + function mirror:get_reflection() - return { horizontal = self.horizontal, vertical = self.vertical } + return { horizontal = self._private.horizontal, vertical = self._private.vertical } end --- Returns a new mirror container. @@ -107,15 +115,11 @@ end -- @treturn table A new mirror container -- @function wibox.container.mirror local function new(widget, reflection) - local ret = base.make_widget() - ret.horizontal = false - ret.vertical = false + local ret = base.make_widget(nil, nil, {enable_properties = true}) + ret._private.horizontal = false + ret._private.vertical = false - for k, v in pairs(mirror) do - if type(v) == "function" then - ret[k] = v - end - end + util.table.crush(ret, mirror, true) ret:set_widget(widget) ret:set_reflection(reflection or {}) @@ -127,6 +131,10 @@ function mirror.mt:__call(...) return new(...) end +--@DOC_widget_COMMON@ + +--@DOC_object_COMMON@ + return setmetatable(mirror, mirror.mt) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80