ENH generalize static drawing module

This commit is contained in:
Nathan Dwarshuis 2022-07-10 16:25:12 -04:00
parent 360f08f4c9
commit 673038d43a
3 changed files with 43 additions and 39 deletions

2
core

@ -1 +1 @@
Subproject commit 9b0b36d18a7d69535a9516712bfb53f7aafeb4f2 Subproject commit 8107eb193fcdd53899af16b44c7ce8eaafb412c4

View File

@ -1,8 +1,10 @@
local common = require 'common' local common = require 'common'
local geometry = require 'geometry' local pure = require 'pure'
local fill_rect = require 'fill_rect' local geometry = require 'geometry'
local geom = require 'geom'
local fill_rect = require 'fill_rect'
return function(left_modules, center_modules, right_modules) return function(module_sets)
local __cairo_set_source_surface = cairo_set_source_surface local __cairo_set_source_surface = cairo_set_source_surface
local __cairo_image_surface_create = cairo_image_surface_create local __cairo_image_surface_create = cairo_image_surface_create
local __cairo_translate = cairo_translate local __cairo_translate = cairo_translate
@ -10,16 +12,16 @@ return function(left_modules, center_modules, right_modules)
local __cairo_destroy = cairo_destroy local __cairo_destroy = cairo_destroy
local __cairo_paint = cairo_paint local __cairo_paint = cairo_paint
local _make_static_surface = function(x, y, w, h, modules) local _make_static_surface = function(box, modules)
local panel_line_thickness = 1 local panel_line_thickness = 1
-- move over by half a pixel so the lines don't need to be antialiased -- move over by half a pixel so the lines don't need to be antialiased
local _x = x + 0.5 local _x = box.corner.x + 0.5
local _y = y + 0.5 local _y = box.corner.y + 0.5
local panel = common.make_panel(_x, _y, w, h, panel_line_thickness) local panel = common.make_panel(_x, _y, box.width, box.height, panel_line_thickness)
local cs_x = _x - panel_line_thickness * 0.5 local cs_x = _x - panel_line_thickness * 0.5
local cs_y = _y - panel_line_thickness * 0.5 local cs_y = _y - panel_line_thickness * 0.5
local cs_w = w + panel_line_thickness local cs_w = box.width + panel_line_thickness
local cs_h = h + panel_line_thickness local cs_h = box.height + panel_line_thickness
local cs = __cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h) local cs = __cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
local cr = __cairo_create(cs) local cr = __cairo_create(cs)
@ -34,29 +36,29 @@ return function(left_modules, center_modules, right_modules)
return { x = cs_x, y = cs_y, s = cs } return { x = cs_x, y = cs_y, s = cs }
end end
local cs_left = _make_static_surface( -- TODO pull this out eventually
geometry.LEFT_X - geometry.PANEL_MARGIN_X, local boxes = {
geometry.TOP_Y - geometry.PANEL_MARGIN_Y, geom.make_box(
geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2, geometry.LEFT_X - geometry.PANEL_MARGIN_X,
geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2, geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
left_modules geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2,
) geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2
),
geom.make_box(
geometry.CENTER_LEFT_X - geometry.PANEL_MARGIN_X,
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
geometry.CENTER_WIDTH + geometry.PANEL_MARGIN_Y * 2 + geometry.CENTER_PAD,
geometry.CENTER_HEIGHT + geometry.PANEL_MARGIN_Y * 2
),
geom.make_box(
geometry.RIGHT_X - geometry.PANEL_MARGIN_X,
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2,
geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2
)
}
local cs_center = _make_static_surface( local cs = pure.zip_with(_make_static_surface, boxes, module_sets)
geometry.CENTER_LEFT_X - geometry.PANEL_MARGIN_X,
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
geometry.CENTER_WIDTH + geometry.PANEL_MARGIN_Y * 2 + geometry.CENTER_PAD,
geometry.CENTER_HEIGHT + geometry.PANEL_MARGIN_Y * 2,
center_modules
)
local cs_right = _make_static_surface(
geometry.RIGHT_X - geometry.PANEL_MARGIN_X,
geometry.TOP_Y - geometry.PANEL_MARGIN_Y,
geometry.SECTION_WIDTH + geometry.PANEL_MARGIN_X * 2,
geometry.SIDE_HEIGHT + geometry.PANEL_MARGIN_Y * 2,
right_modules
)
local draw_static_surface = function(cr, cs_obj) local draw_static_surface = function(cr, cs_obj)
__cairo_set_source_surface(cr, cs_obj.s, cs_obj.x, cs_obj.y) __cairo_set_source_surface(cr, cs_obj.s, cs_obj.x, cs_obj.y)
@ -64,8 +66,8 @@ return function(left_modules, center_modules, right_modules)
end end
return function(cr) return function(cr)
draw_static_surface(cr, cs_left) for i = 1, #cs do
draw_static_surface(cr, cs_center) draw_static_surface(cr, cs[i])
draw_static_surface(cr, cs_right) end
end end
end end

View File

@ -52,9 +52,11 @@ function conky_start(update_interval)
local using_ac = sys.battery_status_reader(battery) local using_ac = sys.battery_status_reader(battery)
local draw_static = static( local draw_static = static(
{stm.static, gfx.static, proc.static}, {
{rw.static, net.static}, {stm.static, gfx.static, proc.static},
{pcm.static, fs.static, pwr.static, mem.static} {rw.static, net.static},
{pcm.static, fs.static, pwr.static, mem.static}
}
) )
local STATS_FILE = '/tmp/.conky_pacman' local STATS_FILE = '/tmp/.conky_pacman'