Convert the mirror layout to the new widget system
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
f2b1071875
commit
85ab3f045b
|
@ -10,21 +10,20 @@ local error = error
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local base = require("wibox.layout.base")
|
local base = require("wibox.widget.base")
|
||||||
local widget_base = require("wibox.widget.base")
|
local Matrix = require("lgi").cairo.Matrix
|
||||||
|
|
||||||
local mirror = { mt = {} }
|
local mirror = { mt = {} }
|
||||||
|
|
||||||
--- Draw this layout
|
--- Layout this layout
|
||||||
function mirror:draw(context, cr, width, height)
|
function mirror:layout(context, cr, width, height)
|
||||||
if not self.widget then return end
|
if not self.widget then return end
|
||||||
if not self.horizontal and not self.vertical then
|
if not self.horizontal and not self.vertical then
|
||||||
base.draw_widget(wibox, cr, self.widget, 0, 0, width, height)
|
base.draw_widget(wibox, cr, self.widget, 0, 0, width, height)
|
||||||
return -- nothing changed
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
cr:save()
|
local m = Matrix.create_identity()
|
||||||
|
|
||||||
local t = { x = 0, y = 0 } -- translation
|
local t = { x = 0, y = 0 } -- translation
|
||||||
local s = { x = 1, y = 1 } -- scale
|
local s = { x = 1, y = 1 } -- scale
|
||||||
if self.horizontal then
|
if self.horizontal then
|
||||||
|
@ -35,13 +34,10 @@ function mirror:draw(context, cr, width, height)
|
||||||
t.x = width
|
t.x = width
|
||||||
s.x = -1
|
s.x = -1
|
||||||
end
|
end
|
||||||
cr:translate(t.x, t.y)
|
m:translate(t.x, t.y)
|
||||||
cr:scale(s.x, s.y)
|
m:scale(s.x, s.y)
|
||||||
|
|
||||||
self.widget:draw(context, cr, width, height)
|
return base.place_widget_via_matrix(widget, m, width, height)
|
||||||
|
|
||||||
-- Undo the scale and translation from above.
|
|
||||||
cr:restore()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Fit this layout into the given area
|
--- Fit this layout into the given area
|
||||||
|
@ -55,15 +51,11 @@ end
|
||||||
--- Set the widget that this layout mirrors.
|
--- Set the widget that this layout mirrors.
|
||||||
-- @param widget The widget to mirror
|
-- @param widget The widget to mirror
|
||||||
function mirror:set_widget(widget)
|
function mirror:set_widget(widget)
|
||||||
if self.widget then
|
|
||||||
self.widget:disconnect_signal("widget::updated", self._emit_updated)
|
|
||||||
end
|
|
||||||
if widget then
|
if widget then
|
||||||
widget_base.check_widget(widget)
|
base.check_widget(widget)
|
||||||
widget:weak_connect_signal("widget::updated", self._emit_updated)
|
|
||||||
end
|
end
|
||||||
self.widget = widget
|
self.widget = widget
|
||||||
self._emit_updated()
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Reset this layout. The widget will be removed and the axes reset.
|
--- Reset this layout. The widget will be removed and the axes reset.
|
||||||
|
@ -85,7 +77,7 @@ function mirror:set_reflection(reflection)
|
||||||
self[ref] = reflection[ref]
|
self[ref] = reflection[ref]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self._emit_updated()
|
self:emit_signal("widget::layout_changed")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the reflection of this mirror layout.
|
--- Get the reflection of this mirror layout.
|
||||||
|
@ -101,7 +93,7 @@ end
|
||||||
-- @param[opt] widget The widget to display.
|
-- @param[opt] widget The widget to display.
|
||||||
-- @param[opt] reflection A table describing the reflection to apply.
|
-- @param[opt] reflection A table describing the reflection to apply.
|
||||||
local function new(widget, reflection)
|
local function new(widget, reflection)
|
||||||
local ret = widget_base.make_widget()
|
local ret = base.make_widget()
|
||||||
ret.horizontal = false
|
ret.horizontal = false
|
||||||
ret.vertical = false
|
ret.vertical = false
|
||||||
|
|
||||||
|
@ -111,10 +103,6 @@ local function new(widget, reflection)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ret._emit_updated = function()
|
|
||||||
ret:emit_signal("widget::updated")
|
|
||||||
end
|
|
||||||
|
|
||||||
ret:set_widget(widget)
|
ret:set_widget(widget)
|
||||||
ret:set_reflection(reflection or {})
|
ret:set_reflection(reflection or {})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue