diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 9c102d25..a51a160b 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -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) diff --git a/data/plugins/toolbarview.lua b/data/plugins/toolbarview.lua index 9437daf5..24ff4515 100644 --- a/data/plugins/toolbarview.lua +++ b/data/plugins/toolbarview.lua @@ -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 diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index f2a1e443..71930361 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" -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, })