awesome/lib/awful/widget/layout/horizontal.lua.in

91 lines
4.3 KiB
Lua
Raw Normal View History

-------------------------------------------------
-- @author Gregor Best <farhaven@googlemail.com>, Lukas Hrazky <lukkash@email.cz>
-- @copyright 2009 Gregor Best, Lukas Hrazky
-- @release @AWESOME_VERSION@
-------------------------------------------------
local require = require
local ipairs = ipairs
local pairs = pairs
local util = require("awful.util")
local layout = require("awful.widget.layout")
local linear = require("awful.widget.layout.linear_common")
--- Horizontal widget layouts
module("awful.widget.layout.horizontal")
-- index used for horizontal layouts
local idx = layout.regular_index
--- Places the widgets in a row, aligned to the left.
-- This is the default layout.
-- It recognizes the following attributes in the encompassing table:
-- <p><code>width</code>: Maximum width of the layout. (optional)<br/>
-- <code>height</code>: Height of the layout. If set, all widgets are resized to this height. (optional)</p>
-- @param bounds The geometry of the bounds for the layout.
-- @param widgets The table of the widgets to layout. When layout function is placed in
-- a table, it is the table that is passed as this argument.
-- @param screen The screen of the wibox.
-- @return A table of geometries of all the widgets.
function leftright(bounds, widgets, screen)
return linear.fixed(idx, bounds, widgets, screen)
end
--- Places the widgets in a row, aligned to the right.
-- It recognizes the following attributes in the encompassing table:
-- <p><code>width</code>: Maximum width of the layout. (optional)<br/>
-- <code>height</code>: Height of the layout. If set, all widgets are resized to this height. (optional)</p>
-- @param bounds The geometry of the bounds for the layout.
-- @param widgets The table of the widgets to layout. When layout function is placed in
-- a table, it is the table that is passed as this argument.
-- @param screen The screen of the wibox.
-- @return A table of geometries of all the widgets.
function rightleft(bounds, widgets, screen)
local g = linear.fixed(idx, util.table.clone(bounds), widgets, screen)
for _, w in pairs(g) do
w.x = w.x + bounds.width - g.total.width
end
return g
end
--- Places the widgets in a row, aligned to the center.
-- It recognizes the following attributes in the encompassing table:
-- <p><code>width</code>: Maximum width of the layout. (optional)<br/>
-- <code>height</code>: Height of the layout. If set, all widgets are resized to this height. (optional)</p>
-- The widgets will be placed in the center of the free space that is left after all widgets
-- preceding the table with this layout were placed. The area covered by widgets with this layout
-- is not subtracted from the total free area (so the widgets "cover no space"). Therefore, if you
-- put anything after a table with center layout, the widgets may overlap.<br/>
-- @param bounds The geometry of the bounds for the layout.
-- @param widgets The table of the widgets to layout. When layout function is placed in
-- a table, it is the table that is passed as this argument.
-- @param screen The screen of the wibox.
-- @return A table of geometries of all the widgets.
function center(bounds, widgets, screen)
local g = linear.fixed(idx, util.table.clone(bounds), widgets, screen)
for _, w in ipairs(g) do
w.x = w.x + (bounds.width - g.total.width) / 2
end
g.total.x = 0
g.total.width = 0
return g
end
--- Places the widgets in a row, making them equally wide.
-- It recognizes the following attributes in the encompassing table:
-- <p><code>width</code>: Maximum width of the layout. (optional)<br/>
-- <code>height</code>: Height of the layout. If set, all widgets are resized to this height. (optional)<br/>
-- <code>max_size</code>: Maximum width of one item. If not set, widgets' widths are set so that they always
-- cover all available space. (optional)<br/>
-- <code>gap</code>: Gap between the widgets. (optional)</p>
-- @param bounds The geometry of the bounds for the layout.
-- @param widgets The table of the widgets to layout. When layout function is placed in
-- a table, it is the table that is passed as this argument.
-- @param screen The screen of the wibox.
-- @return A table of geometries of all the widgets.
function flex(bounds, widgets, screen)
return linear.flex(idx, bounds, widgets, screen)
end
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80