2016-05-23 05:56:45 +02:00
|
|
|
---------------------------------------------------------------------------
|
2019-11-29 01:45:07 +01:00
|
|
|
-- Reflect a widget along one or both axis.
|
2016-05-24 19:34:25 +02:00
|
|
|
--
|
|
|
|
--@DOC_wibox_container_defaults_mirror_EXAMPLE@
|
2016-05-23 05:56:45 +02:00
|
|
|
-- @author dodo
|
|
|
|
-- @copyright 2012 dodo
|
2019-06-06 08:10:36 +02:00
|
|
|
-- @containermod wibox.container.mirror
|
2016-05-23 05:56:45 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local type = type
|
|
|
|
local error = error
|
|
|
|
local ipairs = ipairs
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local base = require("wibox.widget.base")
|
|
|
|
local matrix = require("gears.matrix")
|
2017-03-08 21:18:33 +01:00
|
|
|
local gtable = require("gears.table")
|
2016-05-23 05:56:45 +02:00
|
|
|
|
|
|
|
local mirror = { mt = {} }
|
|
|
|
|
2016-05-23 09:02:11 +02:00
|
|
|
-- Layout this layout
|
2016-05-23 05:56:45 +02:00
|
|
|
function mirror:layout(_, width, height)
|
2016-05-26 22:26:50 +02:00
|
|
|
if not self._private.widget then return end
|
2016-05-23 05:56:45 +02:00
|
|
|
|
|
|
|
local m = matrix.identity
|
|
|
|
local t = { x = 0, y = 0 } -- translation
|
|
|
|
local s = { x = 1, y = 1 } -- scale
|
2016-05-26 22:26:50 +02:00
|
|
|
if self._private.horizontal then
|
2016-05-23 05:56:45 +02:00
|
|
|
t.x = width
|
|
|
|
s.x = -1
|
|
|
|
end
|
2016-05-26 22:26:50 +02:00
|
|
|
if self._private.vertical then
|
2016-05-23 05:56:45 +02:00
|
|
|
t.y = height
|
|
|
|
s.y = -1
|
|
|
|
end
|
|
|
|
m = m:translate(t.x, t.y)
|
|
|
|
m = m:scale(s.x, s.y)
|
|
|
|
|
2016-05-26 22:26:50 +02:00
|
|
|
return { base.place_widget_via_matrix(self._private.widget, m, width, height) }
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
2019-11-29 01:45:07 +01:00
|
|
|
-- Fit this layout into the given area.
|
2016-05-23 05:56:45 +02:00
|
|
|
function mirror:fit(context, ...)
|
2016-05-26 22:26:50 +02:00
|
|
|
if not self._private.widget then
|
2016-05-23 05:56:45 +02:00
|
|
|
return 0, 0
|
|
|
|
end
|
2016-05-26 22:26:50 +02:00
|
|
|
return base.fit_widget(self, context, self._private.widget, ...)
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
2016-05-26 22:26:50 +02:00
|
|
|
--- The widget to be reflected.
|
2019-11-29 01:45:07 +01:00
|
|
|
--
|
2016-05-26 22:26:50 +02:00
|
|
|
-- @property widget
|
2019-11-29 01:45:07 +01:00
|
|
|
-- @tparam widget widget The widget.
|
|
|
|
-- @interface container
|
2016-05-26 22:26:50 +02:00
|
|
|
|
2018-12-27 05:54:10 +01:00
|
|
|
mirror.set_widget = base.set_widget_common
|
2016-05-23 05:56:45 +02:00
|
|
|
|
2016-05-26 22:26:50 +02:00
|
|
|
function mirror:get_widget()
|
|
|
|
return self._private.widget
|
|
|
|
end
|
|
|
|
|
2016-05-23 05:56:45 +02:00
|
|
|
function mirror:get_children()
|
2016-05-26 22:26:50 +02:00
|
|
|
return {self._private.widget}
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function mirror:set_children(children)
|
|
|
|
self:set_widget(children[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Reset this layout. The widget will be removed and the axes reset.
|
2019-11-29 01:45:07 +01:00
|
|
|
--
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method reset
|
2019-11-29 01:45:07 +01:00
|
|
|
-- @interface container
|
2016-05-23 05:56:45 +02:00
|
|
|
function mirror:reset()
|
2016-05-26 22:26:50 +02:00
|
|
|
self._private.horizontal = false
|
|
|
|
self._private.vertical = false
|
2016-05-23 05:56:45 +02:00
|
|
|
self:set_widget(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
function mirror:set_reflection(reflection)
|
|
|
|
if type(reflection) ~= 'table' then
|
|
|
|
error("Invalid type of reflection for mirror layout: " ..
|
|
|
|
type(reflection) .. " (should be a table)")
|
|
|
|
end
|
|
|
|
for _, ref in ipairs({"horizontal", "vertical"}) do
|
|
|
|
if reflection[ref] ~= nil then
|
2016-05-26 22:26:50 +02:00
|
|
|
self._private[ref] = reflection[ref]
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
self:emit_signal("widget::layout_changed")
|
2019-11-29 01:45:07 +01:00
|
|
|
self:emit_signal("property::reflection", reflection)
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the reflection of this mirror layout.
|
2019-11-29 01:45:07 +01:00
|
|
|
--
|
2016-05-26 22:26:50 +02:00
|
|
|
-- @property reflection
|
2017-06-05 00:22:03 +02:00
|
|
|
-- @tparam table reflection A table of booleans with the keys "horizontal", "vertical".
|
|
|
|
-- @tparam boolean reflection.horizontal
|
|
|
|
-- @tparam boolean reflection.vertical
|
2019-11-29 01:45:07 +01:00
|
|
|
-- @propemits true false
|
2016-05-26 22:26:50 +02:00
|
|
|
|
2016-05-23 05:56:45 +02:00
|
|
|
function mirror:get_reflection()
|
2016-05-26 22:26:50 +02:00
|
|
|
return { horizontal = self._private.horizontal, vertical = self._private.vertical }
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
2016-05-23 08:46:28 +02:00
|
|
|
--- Returns a new mirror container.
|
2019-11-29 01:45:07 +01:00
|
|
|
--
|
|
|
|
-- A mirror container mirrors a given widget. Use the `widget` property to set
|
|
|
|
-- the widget and `reflection` property to set the direction.
|
2016-05-23 05:56:45 +02:00
|
|
|
-- horizontal and vertical are by default false which doesn't change anything.
|
2019-11-29 01:45:07 +01:00
|
|
|
--
|
|
|
|
-- @tparam[opt] widget widget The widget to display.
|
|
|
|
-- @tparam[opt] table reflection A table describing the reflection to apply.
|
2016-05-23 08:46:28 +02:00
|
|
|
-- @treturn table A new mirror container
|
2019-06-07 20:59:34 +02:00
|
|
|
-- @constructorfct wibox.container.mirror
|
2016-05-23 05:56:45 +02:00
|
|
|
local function new(widget, reflection)
|
2016-05-26 22:26:50 +02:00
|
|
|
local ret = base.make_widget(nil, nil, {enable_properties = true})
|
|
|
|
ret._private.horizontal = false
|
|
|
|
ret._private.vertical = false
|
2016-05-23 05:56:45 +02:00
|
|
|
|
2017-03-08 21:18:33 +01:00
|
|
|
gtable.crush(ret, mirror, true)
|
2016-05-23 05:56:45 +02:00
|
|
|
|
|
|
|
ret:set_widget(widget)
|
|
|
|
ret:set_reflection(reflection or {})
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
function mirror.mt:__call(...)
|
|
|
|
return new(...)
|
|
|
|
end
|
|
|
|
|
2016-05-26 22:26:50 +02:00
|
|
|
--@DOC_widget_COMMON@
|
|
|
|
|
|
|
|
--@DOC_object_COMMON@
|
|
|
|
|
2016-05-23 05:56:45 +02:00
|
|
|
return setmetatable(mirror, mirror.mt)
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|