Merge wibox.layout.base and wibox.widget.base
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
9b8cbf7539
commit
3338718b93
|
@ -10,8 +10,7 @@ local table = table
|
|||
local pairs = pairs
|
||||
local type = type
|
||||
local floor = math.floor
|
||||
local base = require("wibox.layout.base")
|
||||
local widget_base = require("wibox.widget.base")
|
||||
local base = require("wibox.widget.base")
|
||||
|
||||
local align = {}
|
||||
|
||||
|
@ -46,7 +45,7 @@ function align:layout(context, width, height)
|
|||
-- if all the space is taken, skip the rest, and draw just the middle
|
||||
-- widget
|
||||
if size_second >= size_remains then
|
||||
return { widget_base.place_widget_at(self.second, 0, 0, width, height) }
|
||||
return { base.place_widget_at(self.second, 0, 0, width, height) }
|
||||
else
|
||||
-- the middle widget is sized first, the outside widgets are given
|
||||
-- the remaining space if available we will draw later
|
||||
|
@ -84,7 +83,7 @@ function align:layout(context, width, height)
|
|||
w = size_remains
|
||||
end
|
||||
end
|
||||
table.insert(result, widget_base.place_widget_at(self.first, 0, 0, w, h))
|
||||
table.insert(result, base.place_widget_at(self.first, 0, 0, w, h))
|
||||
end
|
||||
-- size_remains will be <= 0 if first used all the space
|
||||
if self.third and size_remains > 0 then
|
||||
|
@ -110,7 +109,7 @@ function align:layout(context, width, height)
|
|||
end
|
||||
end
|
||||
local x, y = width - w, height - h
|
||||
table.insert(result, widget_base.place_widget_at(self.third, x, y, w, h))
|
||||
table.insert(result, base.place_widget_at(self.third, x, y, w, h))
|
||||
end
|
||||
-- here we either draw the second widget in the space set aside for it
|
||||
-- in the beginning, or in the remaining space, if it is "inside"
|
||||
|
@ -133,7 +132,7 @@ function align:layout(context, width, height)
|
|||
x = floor( (width -w)/2 )
|
||||
end
|
||||
end
|
||||
table.insert(result, widget_base.place_widget_at(self.second, x, y, w, h))
|
||||
table.insert(result, base.place_widget_at(self.second, x, y, w, h))
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
@ -212,7 +211,7 @@ function align:reset()
|
|||
end
|
||||
|
||||
local function get_layout(dir)
|
||||
local ret = widget_base.make_widget()
|
||||
local ret = base.make_widget()
|
||||
ret.dir = dir
|
||||
|
||||
for k, v in pairs(align) do
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
---------------------------------------------------------------------------
|
||||
-- @author Uli Schlachter
|
||||
-- @copyright 2010 Uli Schlachter
|
||||
-- @release @AWESOME_VERSION@
|
||||
-- @classmod wibox.layout.base
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local xpcall = xpcall
|
||||
local print = print
|
||||
local cairo = require("lgi").cairo
|
||||
local wbase = require("wibox.widget.base")
|
||||
|
||||
local base = {}
|
||||
|
||||
--- Fit a widget for the given available width and height
|
||||
-- @param context The context in which we are fit.
|
||||
-- @param widget The widget to fit (this uses widget:fit(width, height)).
|
||||
-- @param width The available width for the widget
|
||||
-- @param height The available height for the widget
|
||||
-- @return The width and height that the widget wants to use
|
||||
function base.fit_widget(context, widget, width, height)
|
||||
if not widget.visible then
|
||||
return 0, 0
|
||||
end
|
||||
-- Sanitize the input. This also filters out e.g. NaN.
|
||||
local width = math.max(0, width)
|
||||
local height = math.max(0, height)
|
||||
|
||||
local w, h = widget:fit(context, width, height)
|
||||
|
||||
-- Also sanitize the output.
|
||||
w = math.max(0, math.min(w, width))
|
||||
h = math.max(0, math.min(h, height))
|
||||
return w, h
|
||||
end
|
||||
|
||||
--- Draw a widget via a cairo context
|
||||
-- @param context The context in which we are drawn.
|
||||
-- @param cr The cairo context used
|
||||
-- @param widget The widget to draw (this uses widget:draw(cr, width, height)).
|
||||
-- @param x The position that the widget should get
|
||||
-- @param y The position that the widget should get
|
||||
-- @param width The widget's width
|
||||
-- @param height The widget's height
|
||||
function base.draw_widget(context, cr, widget, x, y, width, height)
|
||||
if not widget.visible then
|
||||
return
|
||||
end
|
||||
|
||||
-- Use save() / restore() so that our modifications aren't permanent
|
||||
cr:save()
|
||||
|
||||
-- Move (0, 0) to the place where the widget should show up
|
||||
cr:translate(x, y)
|
||||
|
||||
-- Make sure the widget cannot draw outside of the allowed area
|
||||
cr:rectangle(0, 0, width, height)
|
||||
cr:clip()
|
||||
|
||||
if widget.opacity ~= 1 then
|
||||
cr:push_group()
|
||||
end
|
||||
-- Let the widget draw itself
|
||||
xpcall(function()
|
||||
widget:draw(context, cr, width, height)
|
||||
end, function(err)
|
||||
print(debug.traceback("Error while drawing widget: "..tostring(err), 2))
|
||||
end)
|
||||
if widget.opacity ~= 1 then
|
||||
cr:pop_group_to_source()
|
||||
cr.operator = cairo.Operator.OVER
|
||||
cr:paint_with_alpha(widget.opacity)
|
||||
end
|
||||
|
||||
-- Register the widget for input handling
|
||||
context:widget_at(widget, wbase.rect_to_device_geometry(cr, 0, 0, width, height))
|
||||
|
||||
cr:restore()
|
||||
end
|
||||
|
||||
return base
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
|
@ -5,8 +5,7 @@
|
|||
-- @classmod wibox.layout.fixed
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local base = require("wibox.layout.base")
|
||||
local widget_base = require("wibox.widget.base")
|
||||
local base = require("wibox.widget.base")
|
||||
local table = table
|
||||
local pairs = pairs
|
||||
|
||||
|
@ -45,14 +44,14 @@ function fixed:layout(context, width, height)
|
|||
(self.dir ~= "y" and pos-spacing > width) then
|
||||
break
|
||||
end
|
||||
table.insert(result, widget_base.place_widget_at(v, x, y, w, h))
|
||||
table.insert(result, base.place_widget_at(v, x, y, w, h))
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
--- Add a widget to the given fixed layout
|
||||
function fixed:add(widget)
|
||||
widget_base.check_widget(widget)
|
||||
base.check_widget(widget)
|
||||
table.insert(self.widgets, widget)
|
||||
self:emit_signal("widget::layout_changed")
|
||||
end
|
||||
|
@ -113,7 +112,7 @@ function fixed:fill_space(val)
|
|||
end
|
||||
|
||||
local function get_layout(dir)
|
||||
local ret = widget_base.make_widget()
|
||||
local ret = base.make_widget()
|
||||
|
||||
for k, v in pairs(fixed) do
|
||||
if type(v) == "function" then
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
-- @classmod wibox.layout.flex
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local base = require("wibox.layout.base")
|
||||
local widget_base = require("wibox.widget.base")
|
||||
local base = require("wibox.widget.base")
|
||||
local table = table
|
||||
local pairs = pairs
|
||||
local floor = math.floor
|
||||
|
@ -48,7 +47,7 @@ function flex:layout(context, width, height)
|
|||
x, y = round(pos), 0
|
||||
w, h = floor(space_per_item), height
|
||||
end
|
||||
table.insert(result, widget_base.place_widget_at(v, x, y, w, h))
|
||||
table.insert(result, base.place_widget_at(v, x, y, w, h))
|
||||
|
||||
pos = pos + space_per_item + spacing
|
||||
|
||||
|
@ -98,7 +97,7 @@ function flex:fit(context, orig_width, orig_height)
|
|||
end
|
||||
|
||||
function flex:add(widget)
|
||||
widget_base.check_widget(widget)
|
||||
base.check_widget(widget)
|
||||
table.insert(self.widgets, widget)
|
||||
self:emit_signal("widget::layout_changed")
|
||||
end
|
||||
|
@ -125,7 +124,7 @@ function flex:reset()
|
|||
end
|
||||
|
||||
local function get_layout(dir)
|
||||
local ret = widget_base.make_widget()
|
||||
local ret = base.make_widget()
|
||||
|
||||
for k, v in pairs(flex) do
|
||||
if type(v) == "function" then
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
return
|
||||
{
|
||||
base = require("wibox.layout.base");
|
||||
fixed = require("wibox.layout.fixed");
|
||||
align = require("wibox.layout.align");
|
||||
flex = require("wibox.layout.flex");
|
||||
|
|
|
@ -11,8 +11,7 @@ local pi = math.pi
|
|||
local type = type
|
||||
local setmetatable = setmetatable
|
||||
local tostring = tostring
|
||||
local base = require("wibox.layout.base")
|
||||
local widget_base = require("wibox.widget.base")
|
||||
local base = require("wibox.widget.base")
|
||||
local Matrix = require("lgi").cairo.Matrix
|
||||
|
||||
local rotate = { mt = {} }
|
||||
|
@ -61,7 +60,7 @@ end
|
|||
--- Set the widget that this layout rotates.
|
||||
function rotate:set_widget(widget)
|
||||
if widget then
|
||||
widget_base.check_widget(widget)
|
||||
base.check_widget(widget)
|
||||
end
|
||||
self.widget = widget
|
||||
self:emit_signal("widget::layout_changed")
|
||||
|
@ -102,7 +101,7 @@ end
|
|||
-- @param[opt] widget The widget to display.
|
||||
-- @param[opt] dir The direction to rotate to.
|
||||
local function new(widget, dir)
|
||||
local ret = widget_base.make_widget()
|
||||
local ret = base.make_widget()
|
||||
|
||||
for k, v in pairs(rotate) do
|
||||
if type(v) == "function" then
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
local base = require("wibox.widget.base")
|
||||
local color = require("gears.color")
|
||||
local layout_base = require("wibox.layout.base")
|
||||
local surface = require("gears.surface")
|
||||
local cairo = require("lgi").cairo
|
||||
local setmetatable = setmetatable
|
||||
|
@ -53,7 +52,7 @@ function background:fit(context, width, height)
|
|||
return 0, 0
|
||||
end
|
||||
|
||||
return layout_base.fit_widget(context, self.widget, width, height)
|
||||
return base.fit_widget(context, self.widget, width, height)
|
||||
end
|
||||
|
||||
--- Set the widget that is drawn on top of the background
|
||||
|
|
|
@ -6,19 +6,18 @@
|
|||
local object = require("gears.object")
|
||||
local cache = require("gears.cache")
|
||||
local matrix_equals = require("gears.matrix").equals
|
||||
local wbase = require("wibox.widget.base")
|
||||
local lbase = require("wibox.layout.base")
|
||||
local base = require("wibox.widget.base")
|
||||
local say = require("say")
|
||||
local assert = require("luassert")
|
||||
local spy = require("luassert.spy")
|
||||
local stub = require("luassert.stub")
|
||||
|
||||
local real_draw_widget = wbase.draw_widget
|
||||
local real_draw_widget = base.draw_widget
|
||||
local widgets_drawn = nil
|
||||
|
||||
-- This function would reject stubbed widgets
|
||||
local real_check_widget = wbase.check_widget
|
||||
wbase.check_widget = function()
|
||||
local real_check_widget = base.check_widget
|
||||
base.check_widget = function()
|
||||
end
|
||||
|
||||
local function stub_draw_widget(wibox, cr, widget, x, y, width, height)
|
||||
|
@ -36,7 +35,7 @@ local function widget_fit(state, arguments)
|
|||
local widget = arguments[1]
|
||||
local given = arguments[2]
|
||||
local expected = arguments[3]
|
||||
local w, h = lbase.fit_widget({ "fake context" }, widget, given[1], given[2])
|
||||
local w, h = base.fit_widget({ "fake context" }, widget, given[1], given[2])
|
||||
|
||||
local fits = expected[1] == w and expected[2] == h
|
||||
if state.mod == fits then
|
||||
|
@ -117,12 +116,12 @@ return {
|
|||
end,
|
||||
|
||||
stub_draw_widget = function()
|
||||
lbase.draw_widget = stub_draw_widget
|
||||
base.draw_widget = stub_draw_widget
|
||||
widgets_drawn = {}
|
||||
end,
|
||||
|
||||
revert_draw_widget = function()
|
||||
lbase.draw_widget = real_draw_widget
|
||||
base.draw_widget = real_draw_widget
|
||||
widgets_drawn = nil
|
||||
end,
|
||||
|
||||
|
|
Loading…
Reference in New Issue