From 4d320c1946ce69d336f9bf3d0f701dae04be09a6 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 27 Feb 2021 19:39:56 +0100 Subject: [PATCH] Ensure treeview is large enough to show toolbar --- data/plugins/toolbarview.lua | 7 +++++++ data/plugins/treeview.lua | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/data/plugins/toolbarview.lua b/data/plugins/toolbarview.lua index 24ff4515..65e782ae 100644 --- a/data/plugins/toolbarview.lua +++ b/data/plugins/toolbarview.lua @@ -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) diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 71930361..c9a1c74c 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -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()