1 ---------------------------------------------------------------------------
2 -- @author Uli Schlachter
3 -- @copyright 2010 Uli Schlachter
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
11 local setmetatable
= setmetatable
12 local tostring = tostring
13 local base
= require("wibox.layout.base")
14 local widget_base
= require("wibox.widget.base")
16 -- wibox.layout.rotate
17 local rotate
= { mt
= {} }
19 local function transform(layout
, width
, height
)
20 local dir
= layout
:get_direction()
21 if dir
== "east" or dir
== "west" then
28 function rotate
.draw(layout
, wibox
, cr
, width
, height
)
29 if not layout
.widget
then return { width
= 0, height
= 0 } end
31 local dir
= layout
:get_direction()
35 cr
:translate(0, -width
)
36 elseif dir
== "south" then
38 cr
:translate(-width
, -height
)
39 elseif dir
== "east" then
41 cr
:translate(-height
, 0)
44 -- Since we rotated, we might have to swap width and height.
45 -- transform() does that for us.
46 base
.draw_widget(wibox
, cr
, layout
.widget
, 0, 0, transform(layout
, width
, height
))
49 --- Fit this layout into the given area
50 function rotate
.fit(layout
, width
, height
)
51 if not layout
.widget
then
54 return transform(layout
, layout
.widget
:fit(transform(layout
, width
, height
)))
57 --- Set the widget that this layout rotates.
58 function rotate
.set_widget(layout
, widget
)
60 layout
.widget
:disconnect_signal("widget::updated", layout
._emit_updated
)
63 widget_base
.check_widget(widget
)
64 widget
:connect_signal("widget::updated", layout
._emit_updated
)
66 layout
.widget
= widget
67 layout
._emit_updated()
70 --- Reset this layout. The widget will be removed and the rotation reset.
71 function rotate
.reset(layout
)
72 layout
.direction
= nil
73 layout
:set_widget(nil)
76 --- Set the direction of this rotating layout. Valid values are "north", "east",
77 -- "south" and "west". On an invalid value, this function will throw an error.
78 function rotate
.set_direction(layout
, dir
)
86 if not allowed
[dir
] then
87 error("Invalid direction for rotate layout: " .. tostring(dir
))
90 layout
.direction
= dir
91 layout
._emit_updated()
94 --- Get the direction of this rotating layout
95 function rotate
.get_direction(layout
)
96 return layout
.direction
or "north"
99 --- Returns a new rotate layout. A rotate layout rotates a given widget. Use
100 -- :set_widget() to set the widget and :set_direction() for the direction.
101 -- The default direction is "north" which doesn't change anything.
103 local ret
= widget_base
.make_widget()
105 for k
, v
in pairs(rotate
) do
106 if type(v
) == "function" then
111 ret
._emit_updated
= function()
112 ret
:emit_signal("widget::updated")
118 function rotate
.mt
:__call(...)
122 return setmetatable(rotate
, rotate
.mt
)
124 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80