Ensure treeview is large enough to show toolbar

This commit is contained in:
Francesco Abbate 2021-02-27 19:39:56 +01:00
parent e861ea1d66
commit 4d320c1946
2 changed files with 11 additions and 2 deletions

View File

@ -64,6 +64,13 @@ function ToolbarView:each_item()
end
function ToolbarView:get_min_width()
local icon_w = style.icon_big_font:get_width("D")
local space = icon_w / 2
return 2 * style.padding.x + (icon_w + space) * #toolbar_commands - space
end
function ToolbarView:draw()
self:draw_background(style.background2)

View File

@ -6,7 +6,7 @@ local keymap = require "core.keymap"
local style = require "core.style"
local View = require "core.view"
local treeview_size = 200 * SCALE
local default_treeview_size = 200 * SCALE
local function get_depth(filename)
local n = 1
@ -24,7 +24,7 @@ function TreeView:new()
self.scrollable = true
self.visible = true
self.init_size = true
self.target_size = treeview_size
self.target_size = default_treeview_size
self.cache = {}
self.last = {}
end
@ -272,6 +272,8 @@ local toolbar_plugin, ToolbarView = core.try(require, "plugins.toolbarview")
if config.toolbarview ~= false and toolbar_plugin then
local toolbar_view = ToolbarView()
treeview_node:split("down", toolbar_view, {y = true})
local min_toolbar_width = toolbar_view:get_min_width()
view:set_target_size("x", math.max(default_treeview_size, min_toolbar_width))
command.add(nil, {
["toolbar:toggle"] = function()
toolbar_view:toggle_visible()