wibox.hierarchy: Remove _parent member
The parent was needed for :get_matrix_to_device() which recursively walked parents and multiplied together their transformation matrices. This is now replaced by calculating all these matrices while constructing the hierarchy. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
dc73a4586a
commit
6b6b448b56
|
@ -15,23 +15,13 @@ local base = require("wibox.widget.base")
|
||||||
|
|
||||||
local hierarchy = {}
|
local hierarchy = {}
|
||||||
|
|
||||||
--- Create a new widget hierarchy that has no parent.
|
local function hierarchy_new(context, widget, width, height, redraw_callback, layout_callback, callback_arg,
|
||||||
-- @param context The context in which we are laid out.
|
matrix_to_parent, matrix_to_device)
|
||||||
-- @param widget The widget that is at the base of the hierarchy.
|
|
||||||
-- @param width The available width for this hierarchy.
|
|
||||||
-- @param height The available height for this hierarchy.
|
|
||||||
-- @param redraw_callback Callback that is called with the corresponding widget
|
|
||||||
-- hierarchy on widget::redraw_needed on some widget.
|
|
||||||
-- @param layout_callback Callback that is called with the corresponding widget
|
|
||||||
-- hierarchy on widget::layout_changed on some widget.
|
|
||||||
-- @param callback_arg A second argument that is given to the above callbacks.
|
|
||||||
-- @return A new widget hierarchy
|
|
||||||
function hierarchy.new(context, widget, width, height, redraw_callback, layout_callback, callback_arg)
|
|
||||||
local children = base.layout_widget(context, widget, width, height)
|
local children = base.layout_widget(context, widget, width, height)
|
||||||
local draws_x1, draws_y1, draws_x2, draws_y2 = 0, 0, width, height
|
local draws_x1, draws_y1, draws_x2, draws_y2 = 0, 0, width, height
|
||||||
local result = {
|
local result = {
|
||||||
_parent = nil,
|
_matrix = matrix_to_parent,
|
||||||
_matrix = cairo.Matrix.create_identity(),
|
_matrix_to_device = matrix_to_device,
|
||||||
_widget = widget,
|
_widget = widget,
|
||||||
_size = {
|
_size = {
|
||||||
width = width,
|
width = width,
|
||||||
|
@ -47,10 +37,11 @@ function hierarchy.new(context, widget, width, height, redraw_callback, layout_c
|
||||||
widget:weak_connect_signal("widget::layout_changed", result._layout)
|
widget:weak_connect_signal("widget::layout_changed", result._layout)
|
||||||
|
|
||||||
for _, w in ipairs(children or {}) do
|
for _, w in ipairs(children or {}) do
|
||||||
local r = hierarchy.new(context, w._widget, w._width, w._height,
|
local to_dev = cairo.Matrix.create_identity()
|
||||||
redraw_callback, layout_callback, callback_arg)
|
to_dev:multiply(matrix_to_device, w._matrix)
|
||||||
r._matrix = w._matrix
|
|
||||||
r._parent = result
|
local r = hierarchy_new(context, w._widget, w._width, w._height, redraw_callback, layout_callback,
|
||||||
|
callback_arg, matrix.copy(w._matrix), to_dev)
|
||||||
table.insert(result._children, r)
|
table.insert(result._children, r)
|
||||||
|
|
||||||
-- Update our drawing extents
|
-- Update our drawing extents
|
||||||
|
@ -78,6 +69,22 @@ function hierarchy.new(context, widget, width, height, redraw_callback, layout_c
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Create a new widget hierarchy that has no parent.
|
||||||
|
-- @param context The context in which we are laid out.
|
||||||
|
-- @param widget The widget that is at the base of the hierarchy.
|
||||||
|
-- @param width The available width for this hierarchy.
|
||||||
|
-- @param height The available height for this hierarchy.
|
||||||
|
-- @param redraw_callback Callback that is called with the corresponding widget
|
||||||
|
-- hierarchy on widget::redraw_needed on some widget.
|
||||||
|
-- @param layout_callback Callback that is called with the corresponding widget
|
||||||
|
-- hierarchy on widget::layout_changed on some widget.
|
||||||
|
-- @param callback_arg A second argument that is given to the above callbacks.
|
||||||
|
-- @return A new widget hierarchy
|
||||||
|
function hierarchy.new(context, widget, width, height, redraw_callback, layout_callback, callback_arg)
|
||||||
|
return hierarchy_new(context, widget, width, height, redraw_callback, layout_callback, callback_arg,
|
||||||
|
cairo.Matrix.create_identity(), cairo.Matrix.create_identity())
|
||||||
|
end
|
||||||
|
|
||||||
--- Get the widget that this hierarchy manages.
|
--- Get the widget that this hierarchy manages.
|
||||||
function hierarchy:get_widget()
|
function hierarchy:get_widget()
|
||||||
return self._widget
|
return self._widget
|
||||||
|
@ -95,15 +102,6 @@ end
|
||||||
-- hierarchy is applied upon) from this hierarchy's coordinate system.
|
-- hierarchy is applied upon) from this hierarchy's coordinate system.
|
||||||
-- @return A cairo matrix describing the transformation.
|
-- @return A cairo matrix describing the transformation.
|
||||||
function hierarchy:get_matrix_to_device()
|
function hierarchy:get_matrix_to_device()
|
||||||
if not self._matrix_to_device then
|
|
||||||
local m = cairo.Matrix.create_identity()
|
|
||||||
local state = self
|
|
||||||
while state ~= nil do
|
|
||||||
m:multiply(m, state._matrix)
|
|
||||||
state = state._parent
|
|
||||||
end
|
|
||||||
self._matrix_to_device = m
|
|
||||||
end
|
|
||||||
return matrix.copy(self._matrix_to_device)
|
return matrix.copy(self._matrix_to_device)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue