2016-05-23 05:56:45 +02:00
|
|
|
---------------------------------------------------------------------------
|
2016-05-23 09:43:25 +02:00
|
|
|
-- A container rotating the conained widget by 90 degrees.
|
|
|
|
--
|
2016-05-24 18:51:08 +02:00
|
|
|
--@DOC_wibox_container_defaults_rotate_EXAMPLE@
|
2016-05-23 05:56:45 +02:00
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2010 Uli Schlachter
|
2019-06-06 08:10:36 +02:00
|
|
|
-- @containermod wibox.container.rotate
|
2016-05-23 05:56:45 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local error = error
|
|
|
|
local pi = math.pi
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local tostring = tostring
|
|
|
|
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 rotate = { mt = {} }
|
|
|
|
|
|
|
|
local function transform(layout, width, height)
|
|
|
|
local dir = layout:get_direction()
|
|
|
|
if dir == "east" or dir == "west" then
|
|
|
|
return height, width
|
|
|
|
end
|
|
|
|
return width, height
|
|
|
|
end
|
|
|
|
|
2016-05-23 09:02:11 +02:00
|
|
|
-- Layout this layout
|
2016-05-23 05:56:45 +02:00
|
|
|
function rotate:layout(_, width, height)
|
2016-05-26 22:34:44 +02:00
|
|
|
if not self._private.widget or not self._private.widget._private.visible then
|
2016-05-23 05:56:45 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local dir = self:get_direction()
|
|
|
|
|
|
|
|
local m = matrix.identity
|
|
|
|
if dir == "west" then
|
|
|
|
m = m:rotate(pi / 2)
|
|
|
|
m = m:translate(0, -width)
|
|
|
|
elseif dir == "south" then
|
|
|
|
m = m:rotate(pi)
|
|
|
|
m = m:translate(-width, -height)
|
|
|
|
elseif dir == "east" then
|
|
|
|
m = m:rotate(3 * pi / 2)
|
|
|
|
m = m:translate(-height, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Since we rotated, we might have to swap width and height.
|
|
|
|
-- transform() does that for us.
|
2016-05-26 22:34:44 +02:00
|
|
|
return { base.place_widget_via_matrix(self._private.widget, m, transform(self, width, height)) }
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
2016-05-23 09:02:11 +02:00
|
|
|
-- Fit this layout into the given area
|
2016-05-23 05:56:45 +02:00
|
|
|
function rotate:fit(context, width, height)
|
2016-05-26 22:34:44 +02:00
|
|
|
if not self._private.widget then
|
2016-05-23 05:56:45 +02:00
|
|
|
return 0, 0
|
|
|
|
end
|
2016-05-26 22:34:44 +02:00
|
|
|
return transform(self, base.fit_widget(self, context, self._private.widget, transform(self, width, height)))
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
2016-05-26 22:34:44 +02:00
|
|
|
--- The widget to be rotated.
|
|
|
|
-- @property widget
|
|
|
|
-- @tparam widget widget The widget
|
|
|
|
|
2018-12-27 05:54:10 +01:00
|
|
|
rotate.set_widget = base.set_widget_common
|
2016-05-23 05:56:45 +02:00
|
|
|
|
2016-05-26 22:34:44 +02:00
|
|
|
function rotate:get_widget()
|
|
|
|
return self._private.widget
|
|
|
|
end
|
|
|
|
|
2016-05-23 05:56:45 +02:00
|
|
|
function rotate:get_children()
|
2016-05-26 22:34:44 +02:00
|
|
|
return {self._private.widget}
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function rotate:set_children(children)
|
|
|
|
self:set_widget(children[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Reset this layout. The widget will be removed and the rotation reset.
|
2019-06-06 22:32:53 +02:00
|
|
|
-- @method reset
|
2016-05-23 05:56:45 +02:00
|
|
|
function rotate:reset()
|
2016-05-26 22:34:44 +02:00
|
|
|
self._private.direction = nil
|
2016-05-23 05:56:45 +02:00
|
|
|
self:set_widget(nil)
|
|
|
|
end
|
|
|
|
|
2016-05-26 22:34:44 +02:00
|
|
|
--@DOC_widget_COMMON@
|
|
|
|
|
|
|
|
--@DOC_object_COMMON@
|
|
|
|
|
|
|
|
--- The direction of this rotating container.
|
2016-05-23 09:43:25 +02:00
|
|
|
-- Valid values are:
|
|
|
|
--
|
|
|
|
-- * *north*
|
|
|
|
-- * *east*
|
|
|
|
-- * *south*
|
|
|
|
-- * *north*
|
|
|
|
--
|
|
|
|
--@DOC_wibox_container_rotate_angle_EXAMPLE@
|
2016-05-26 22:34:44 +02:00
|
|
|
-- @property direction
|
2016-05-23 09:43:25 +02:00
|
|
|
-- @tparam string dir The direction
|
2016-05-26 22:34:44 +02:00
|
|
|
|
2016-05-23 05:56:45 +02:00
|
|
|
function rotate:set_direction(dir)
|
|
|
|
local allowed = {
|
|
|
|
north = true,
|
|
|
|
east = true,
|
|
|
|
south = true,
|
|
|
|
west = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if not allowed[dir] then
|
|
|
|
error("Invalid direction for rotate layout: " .. tostring(dir))
|
|
|
|
end
|
|
|
|
|
2016-05-26 22:34:44 +02:00
|
|
|
self._private.direction = dir
|
2016-05-23 05:56:45 +02:00
|
|
|
self:emit_signal("widget::layout_changed")
|
|
|
|
end
|
|
|
|
|
2019-06-06 22:32:53 +02:00
|
|
|
-- Get the direction of this rotating layout
|
2016-05-23 05:56:45 +02:00
|
|
|
function rotate:get_direction()
|
2016-05-26 22:34:44 +02:00
|
|
|
return self._private.direction or "north"
|
2016-05-23 05:56:45 +02:00
|
|
|
end
|
|
|
|
|
2016-05-23 08:46:28 +02:00
|
|
|
--- Returns a new rotate container.
|
|
|
|
-- A rotate container rotates a given widget. Use
|
2016-05-23 05:56:45 +02:00
|
|
|
-- :set_widget() to set the widget and :set_direction() for the direction.
|
|
|
|
-- The default direction is "north" which doesn't change anything.
|
|
|
|
-- @param[opt] widget The widget to display.
|
|
|
|
-- @param[opt] dir The direction to rotate to.
|
2016-05-23 08:46:28 +02:00
|
|
|
-- @treturn table A new rotate container.
|
2019-06-07 20:59:34 +02:00
|
|
|
-- @constructorfct wibox.container.rotate
|
2016-05-23 05:56:45 +02:00
|
|
|
local function new(widget, dir)
|
2016-05-26 22:34:44 +02:00
|
|
|
local ret = base.make_widget(nil, nil, {enable_properties = true})
|
2016-05-23 05:56:45 +02:00
|
|
|
|
2017-03-08 21:18:33 +01:00
|
|
|
gtable.crush(ret, rotate, true)
|
2016-05-23 05:56:45 +02:00
|
|
|
|
|
|
|
ret:set_widget(widget)
|
|
|
|
ret:set_direction(dir or "north")
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
function rotate.mt:__call(...)
|
|
|
|
return new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(rotate, rotate.mt)
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|