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:
parent
7802202625
commit
4d734e933c
|
@ -96,7 +96,8 @@ local type_map = { up="vsplit", down="vsplit", left="hsplit", right="hsplit" }
|
|||
-- and it indicates if the node want to have a fixed size along the axis where the
|
||||
-- boolean is true. If not it will be expanded to take all the available space.
|
||||
-- The "resizable" flag indicates if, along the "locked" axis the node can be resized
|
||||
-- by the user.
|
||||
-- by the user. If the node is marked as resizable their view should provide a
|
||||
-- set_target_size method.
|
||||
function Node:split(dir, view, locked, resizable)
|
||||
assert(self.type == "leaf", "Tried to split non-leaf node")
|
||||
local node_type = assert(type_map[dir], "Invalid direction")
|
||||
|
@ -461,9 +462,8 @@ function Node:resize(axis, value)
|
|||
-- resize operation here because for proportional panes the resize is
|
||||
-- done using the "divider" value of the parent node.
|
||||
if (self.locked and self.locked[axis]) and self.resizable then
|
||||
local view = self.active_view
|
||||
view.size[axis] = value
|
||||
return true
|
||||
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)
|
||||
end
|
||||
else
|
||||
local a_resizable = self.a:is_resizable(axis)
|
||||
|
|
|
@ -4,10 +4,6 @@ local command = require "core.command"
|
|||
local style = require "core.style"
|
||||
local View = require "core.view"
|
||||
|
||||
local icon_h, icon_w = style.icon_big_font:get_height(), style.icon_big_font:get_width("D")
|
||||
local toolbar_spacing = icon_w / 2
|
||||
local toolbar_height = icon_h + style.padding.y * 2
|
||||
|
||||
local ToolbarView = View:extend()
|
||||
|
||||
local toolbar_commands = {
|
||||
|
@ -20,36 +16,39 @@ local toolbar_commands = {
|
|||
}
|
||||
|
||||
|
||||
local function toolbar_height()
|
||||
return style.icon_big_font:get_height() + style.padding.y * 2
|
||||
end
|
||||
|
||||
|
||||
function ToolbarView:new()
|
||||
ToolbarView.super.new(self)
|
||||
self.visible = true
|
||||
self.init_size = toolbar_height
|
||||
self.init_size = true
|
||||
self.tooltip = false
|
||||
end
|
||||
|
||||
|
||||
function ToolbarView:update()
|
||||
local dest_size = self.visible and toolbar_height() or 0
|
||||
if self.init_size then
|
||||
self.size.y = self.init_size
|
||||
self.size.y = dest_size
|
||||
self.init_size = nil
|
||||
elseif self.goto_size then
|
||||
if self.goto_size ~= self.size.y then
|
||||
self:move_towards(self.size, "y", self.goto_size)
|
||||
else
|
||||
self.goto_size = nil
|
||||
end
|
||||
else
|
||||
self:move_towards(self.size, "y", dest_size)
|
||||
end
|
||||
ToolbarView.super.update(self)
|
||||
end
|
||||
|
||||
|
||||
function ToolbarView:toggle_visible()
|
||||
self.goto_size = self.visible and 0 or toolbar_height
|
||||
self.visible = not self.visible
|
||||
end
|
||||
|
||||
|
||||
function ToolbarView:each_item()
|
||||
local icon_h, icon_w = style.icon_big_font:get_height(), style.icon_big_font:get_width("D")
|
||||
local toolbar_spacing = icon_w / 2
|
||||
local ox, oy = self:get_content_offset()
|
||||
local index = 0
|
||||
local iter = function()
|
||||
|
@ -68,9 +67,9 @@ end
|
|||
function ToolbarView:draw()
|
||||
self:draw_background(style.background2)
|
||||
|
||||
for item, x, y in self:each_item() do
|
||||
for item, x, y, w, h in self:each_item() do
|
||||
local color = item == self.hovered_item and style.text or style.dim
|
||||
common.draw_text(style.icon_big_font, color, item.symbol, nil, x, y, 0, icon_h)
|
||||
common.draw_text(style.icon_big_font, color, item.symbol, nil, x, y, 0, h)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue