Fix resize behavior of treeview and toolbar

Now toolbarview always compute up-to-date sizes and spacing to adapt to
changes in icon big font.

For treeview and toolbarview revert the goto_size approach to use the
original approach of rxi/lite. In order to make it work when user resizes
dragging the divider we use the view optional method set_target_size().
This latter changes the view's target size instead of changing its size
right away. The size is only changed by the lite's layout and animation
system.

Remove the config.treeview_size variable that was no longer working because
plugins are loaded before the user's config.
This commit is contained in:
Francesco Abbate
2021-02-27 12:13:11 +01:00
parent 7802202625
commit 4d734e933c
3 changed files with 35 additions and 37 deletions
+17 -18
View File
@@ -6,7 +6,7 @@ local keymap = require "core.keymap"
local style = require "core.style"
local View = require "core.view"
config.treeview_size = 200 * SCALE
local treeview_size = 200 * SCALE
local function get_depth(filename)
local n = 1
@@ -23,12 +23,21 @@ function TreeView:new()
TreeView.super.new(self)
self.scrollable = true
self.visible = true
self.init_size = config.treeview_size
self.init_size = true
self.target_size = treeview_size
self.cache = {}
self.last = {}
end
function TreeView:set_target_size(axis, value)
if axis == "x" then
self.target_size = value
return true
end
end
function TreeView:get_cached(item, dirname)
local dir_cache = self.cache[dirname]
if not dir_cache then
@@ -184,15 +193,12 @@ end
function TreeView:update()
-- update width
local dest = self.visible and self.target_size or 0
if self.init_size then
self.size.x = self.init_size
self.init_size = nil
elseif self.goto_size then
if self.goto_size ~= self.size.x then
self:move_towards(self.size, "x", self.goto_size)
else
self.goto_size = nil
end
self.size.x = dest
self.init_size = false
else
self:move_towards(self.size, "x", dest)
end
TreeView.super.update(self)
@@ -277,14 +283,7 @@ end
-- register commands and keymap
command.add(nil, {
["treeview:toggle"] = function()
if view.visible then
view.previous_size = view.size.x
view.visible = false
view.goto_size = 0
else
view.visible = true
view.goto_size = view.previous_size
end
view.visible = not view.visible
end,
})