Merge the draw() context into graph's draw_callback_options
The context fields aren't mentioned in documentation, because their documentation should be linked instead of copied, but there's no documented table for it, no matter where I looked.
This commit is contained in:
parent
d051a340bc
commit
d8762eb245
|
@ -650,7 +650,7 @@ local function graph_choose_coordinate_system(self, scaling_values, drawn_values
|
||||||
return min_value, max_value, baseline_y
|
return min_value, max_value, baseline_y
|
||||||
end
|
end
|
||||||
|
|
||||||
local function graph_draw_values(self, cr, width, height, drawn_values_num)
|
local function graph_draw_values(self, context, cr, width, height, drawn_values_num)
|
||||||
local values = self._private.values
|
local values = self._private.values
|
||||||
|
|
||||||
local step_spacing = self._private.step_spacing or prop_fallbacks.step_spacing
|
local step_spacing = self._private.step_spacing or prop_fallbacks.step_spacing
|
||||||
|
@ -688,14 +688,14 @@ local function graph_draw_values(self, cr, width, height, drawn_values_num)
|
||||||
-- @tfield number _height The height of the values draw area.
|
-- @tfield number _height The height of the values draw area.
|
||||||
-- @tfield number _group_idx Index of the currently drawn data group.
|
-- @tfield number _group_idx Index of the currently drawn data group.
|
||||||
-- @tfield wibox.widget.graph _graph The graph widget itself, explicitly named.
|
-- @tfield wibox.widget.graph _graph The graph widget itself, explicitly named.
|
||||||
local options = {
|
local options = setmetatable({
|
||||||
_step_width = step_width,
|
_step_width = step_width,
|
||||||
_step_spacing = step_spacing,
|
_step_spacing = step_spacing,
|
||||||
_width = width,
|
_width = width,
|
||||||
_height = height,
|
_height = height,
|
||||||
_group_idx = nil, -- will be set later
|
_group_idx = nil, -- will be set later
|
||||||
_graph = self,
|
_graph = self,
|
||||||
}
|
}, {__index = context})
|
||||||
|
|
||||||
-- The user callback to call before drawing each data group
|
-- The user callback to call before drawing each data group
|
||||||
local group_start = self._private.group_start
|
local group_start = self._private.group_start
|
||||||
|
@ -799,7 +799,7 @@ local function graph_draw_values(self, cr, width, height, drawn_values_num)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function graph:draw(_, cr, width, height)
|
function graph:draw(context, cr, width, height)
|
||||||
local border_width = self._private.border_width or prop_fallbacks.border_width
|
local border_width = self._private.border_width or prop_fallbacks.border_width
|
||||||
local drawn_values_num = self:compute_drawn_values_num(width-2*border_width)
|
local drawn_values_num = self:compute_drawn_values_num(width-2*border_width)
|
||||||
|
|
||||||
|
@ -822,7 +822,7 @@ function graph:draw(_, cr, width, height)
|
||||||
local values_width = width - 2*border_width
|
local values_width = width - 2*border_width
|
||||||
local values_height = height - 2*border_width
|
local values_height = height - 2*border_width
|
||||||
|
|
||||||
graph_draw_values(self, cr, values_width, values_height, drawn_values_num)
|
graph_draw_values(self, context, cr, values_width, values_height, drawn_values_num)
|
||||||
|
|
||||||
-- Undo the cr:translate() for the border and step shapes
|
-- Undo the cr:translate() for the border and step shapes
|
||||||
cr:restore()
|
cr:restore()
|
||||||
|
|
|
@ -585,6 +585,8 @@ describe("wibox.widget.graph", function()
|
||||||
-- Ensure it's integer.
|
-- Ensure it's integer.
|
||||||
assert.is.equal(math.floor(options._group_idx), options._group_idx)
|
assert.is.equal(math.floor(options._group_idx), options._group_idx)
|
||||||
assert.is.equal(widget, options._graph)
|
assert.is.equal(widget, options._graph)
|
||||||
|
-- It also contains the draw context
|
||||||
|
assert.is.equal("fake context", options.fake_context)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe("property step_hook()", function()
|
describe("property step_hook()", function()
|
||||||
|
|
Loading…
Reference in New Issue