Fix resizing problem for nested nodes

Should fix problem reported in:

https://github.com/drmargarido/TodoTreeView/issues/3
This commit is contained in:
Francesco Abbate 2021-05-06 15:35:40 +02:00
parent f1621192f9
commit 55a6888818
1 changed files with 36 additions and 12 deletions

View File

@ -484,7 +484,8 @@ function Node:close_all_docviews()
end end
end end
-- Returns true for nodes that accept either "proportional" resizes (based on the
-- node.divider) or "locked" resizable nodes (along the resize axis).
function Node:is_resizable(axis) function Node:is_resizable(axis)
if self.type == 'leaf' then if self.type == 'leaf' then
return not self.locked or not self.locked[axis] or self.resizable return not self.locked or not self.locked[axis] or self.resizable
@ -496,22 +497,42 @@ function Node:is_resizable(axis)
end end
-- Return true iff it is a locked pane along the rezise axis and is
-- declared "resizable".
function Node:is_locked_resizable(axis)
return self.locked and self.locked[axis] and self.resizable
end
function Node:resize(axis, value) function Node:resize(axis, value)
if self.type == 'leaf' then if self.type == 'leaf' then
-- The logic here is: accept the resize only if locked along the axis -- If it is not locked we don't accept the
-- and is declared "resizable". If it is not locked we don't accept the
-- resize operation here because for proportional panes the resize is -- resize operation here because for proportional panes the resize is
-- done using the "divider" value of the parent node. -- done using the "divider" value of the parent node.
if (self.locked and self.locked[axis]) and self.resizable then if self:is_locked_resizable(axis) then
assert(self.active_view.set_target_size, "internal error: the view of a resizable \"locked\" node do not provide a set_target_size method")
return self.active_view:set_target_size(axis, value) return self.active_view:set_target_size(axis, value)
end end
else else
local a_resizable = self.a:is_resizable(axis) if self.type == (axis == "x" and "hsplit" or "vsplit") then
local b_resizable = self.b:is_resizable(axis) -- we are resizing a node that is splitted along the resize axis
if a_resizable and b_resizable then if self.a:is_locked_resizable(axis) and self.b:is_locked_resizable(axis) then
self.a:resize(axis, value) local rem_value = value - self.a.size[axis]
self.b:resize(axis, value) if rem_value >= 0 then
return self.b.active_view:set_target_size(axis, rem_value)
else
self.b.active_view:set_target_size(axis, 0)
return self.a.active_view:set_target_size(axis, value)
end
end
else
-- we are resizing a node that is splitted along the axis perpendicular
-- to the resize axis
local a_resizable = self.a:is_resizable(axis)
local b_resizable = self.b:is_resizable(axis)
if a_resizable and b_resizable then
self.a:resize(axis, value)
self.b:resize(axis, value)
end
end end
end end
end end
@ -619,7 +640,10 @@ end
local function resize_child_node(node, axis, value, delta) local function resize_child_node(node, axis, value, delta)
local accept_resize = node.a:resize(axis, value) or node.b:resize(axis, node.size[axis] - value) local accept_resize = node.a:resize(axis, value)
if not accept_resize then
accept_resize = node.b:resize(axis, node.size[axis] - value)
end
if not accept_resize then if not accept_resize then
node.divider = node.divider + delta / node.size[axis] node.divider = node.divider + delta / node.size[axis]
end end