2010-10-06 12:42:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2010 Uli Schlachter
|
2015-02-25 11:18:53 +01:00
|
|
|
-- @classmod wibox.widget
|
2010-10-06 12:42:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2017-05-30 10:32:02 +02:00
|
|
|
local cairo = require("lgi").cairo
|
|
|
|
local hierarchy = require("wibox.hierarchy")
|
|
|
|
|
|
|
|
local widget = {
|
|
|
|
base = require("wibox.widget.base");
|
2012-06-12 15:55:10 +02:00
|
|
|
textbox = require("wibox.widget.textbox");
|
|
|
|
imagebox = require("wibox.widget.imagebox");
|
|
|
|
background = require("wibox.widget.background");
|
|
|
|
systray = require("wibox.widget.systray");
|
2016-05-23 06:46:01 +02:00
|
|
|
textclock = require("wibox.widget.textclock");
|
2016-05-23 07:22:35 +02:00
|
|
|
progressbar = require("wibox.widget.progressbar");
|
2016-05-23 07:30:44 +02:00
|
|
|
graph = require("wibox.widget.graph");
|
2016-07-26 07:58:53 +02:00
|
|
|
checkbox = require("wibox.widget.checkbox");
|
2016-07-28 08:47:29 +02:00
|
|
|
piechart = require("wibox.widget.piechart");
|
2016-08-05 00:12:38 +02:00
|
|
|
slider = require("wibox.widget.slider");
|
2017-03-31 01:00:04 +02:00
|
|
|
calendar = require("wibox.widget.calendar");
|
2017-08-07 22:11:38 +02:00
|
|
|
separator = require("wibox.widget.separator");
|
2017-05-30 10:32:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setmetatable(widget, {
|
|
|
|
__call = function(_, args)
|
|
|
|
return widget.base.make_widget_declarative(args)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
--- Draw a widget directly to a given cairo context.
|
|
|
|
-- This function creates a temporary `wibox.hierarchy` instance and uses that to
|
|
|
|
-- draw the given widget once to the given cairo context.
|
|
|
|
-- @tparam widget wdg A widget to draw
|
|
|
|
-- @tparam cairo_context cr The cairo context to draw the widget on
|
|
|
|
-- @tparam number width The width of the widget
|
|
|
|
-- @tparam number height The height of the widget
|
|
|
|
-- @tparam[opt={dpi=96}] table context The context information to give to the widget.
|
|
|
|
function widget.draw_to_cairo_context(wdg, cr, width, height, context)
|
|
|
|
local function no_op() end
|
|
|
|
context = context or {dpi=96}
|
|
|
|
local h = hierarchy.new(context, wdg, width, height, no_op, no_op, {})
|
|
|
|
h:draw(context, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create an SVG file showing this widget.
|
|
|
|
-- @tparam widget wdg A widget
|
|
|
|
-- @tparam string path The output file path
|
|
|
|
-- @tparam number width The surface width
|
|
|
|
-- @tparam number height The surface height
|
|
|
|
-- @tparam[opt={dpi=96}] table context The context information to give to the widget.
|
|
|
|
function widget.draw_to_svg_file(wdg, path, width, height, context)
|
|
|
|
local img = cairo.SvgSurface.create(path, width, height)
|
|
|
|
local cr = cairo.Context(img)
|
|
|
|
widget.draw_to_cairo_context(wdg, cr, width, height, context)
|
|
|
|
img:finish()
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a cairo image surface showing this widget.
|
|
|
|
-- @tparam widget wdg A widget
|
|
|
|
-- @tparam number width The surface width
|
|
|
|
-- @tparam number height The surface height
|
|
|
|
-- @param[opt=cairo.Format.ARGB32] format The surface format
|
|
|
|
-- @tparam[opt={dpi=96}] table context The context information to give to the widget.
|
|
|
|
-- @return The cairo surface
|
|
|
|
function widget.draw_to_image_surface(wdg, width, height, format, context)
|
|
|
|
local img = cairo.ImageSurface(format or cairo.Format.ARGB32, width, height)
|
|
|
|
local cr = cairo.Context(img)
|
|
|
|
widget.draw_to_cairo_context(wdg, cr, width, height, context)
|
|
|
|
return img
|
|
|
|
end
|
|
|
|
|
|
|
|
return widget
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|