Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treeview: add horizontal scrolling #1717

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
treeview: add horizontal scrolling
This is taken from Pragtical but I wasn't able to cherry pick the commit,
so I ended up recreating it.

Co-authored-by: Jefferson González <jgmdev@gmail.com>
  • Loading branch information
takase1121 and jgmdev committed Feb 4, 2024
commit f2e6467c0b106aa8c001b556a597935d00f63744
28 changes: 21 additions & 7 deletions data/plugins/treeview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function TreeView:new()
self.scrollable = true
self.visible = true
self.init_size = true
self.scroll_width = 0
self.target_size = config.plugins.treeview.size
self.cache = {}
self.tooltip = { x = 0, y = 0, begin = 0, alpha = 0 }
Expand Down Expand Up @@ -344,6 +345,14 @@ function TreeView:get_scrollable_size()
end


function TreeView:get_h_scrollable_size()
local _, _, v_scroll_w = self.v_scrollbar:get_thumb_rect()
return self.scroll_width + (
self.size.x > self.scroll_width + v_scroll_w and 0 or style.padding.x
)
end


function TreeView:draw_tooltip()
local text = common.home_encode(self.hovered_item.abs_filename)
local w, h = style.font:get_width(text), style.font:get_height(text)
Expand Down Expand Up @@ -389,7 +398,7 @@ end

function TreeView:draw_item_text(item, active, hovered, x, y, w, h)
local item_text, item_font, item_color = self:get_item_text(item, active, hovered)
common.draw_text(item_font, item_color, item_text, nil, x, y, 0, h)
return common.draw_text(item_font, item_color, item_text, nil, x, y, 0, h)
end


Expand All @@ -402,7 +411,7 @@ end

function TreeView:draw_item_body(item, active, hovered, x, y, w, h)
x = x + self:draw_item_icon(item, active, hovered, x, y, w, h)
self:draw_item_text(item, active, hovered, x, y, w, h)
return self:draw_item_text(item, active, hovered, x, y, w, h)
end


Expand All @@ -420,9 +429,9 @@ function TreeView:draw_item_background(item, active, hovered, x, y, w, h)
if hovered then
local hover_color = { table.unpack(style.line_highlight) }
hover_color[4] = 160
renderer.draw_rect(x, y, w, h, hover_color)
renderer.draw_rect(self.position.x, y, self.size.x, h, hover_color)
elseif active then
renderer.draw_rect(x, y, w, h, style.line_highlight)
renderer.draw_rect(self.position.x, y, self.size.x, h, style.line_highlight)
end
end

Expand All @@ -433,7 +442,7 @@ function TreeView:draw_item(item, active, hovered, x, y, w, h)
x = x + item.depth * style.padding.x + style.padding.x
x = x + self:draw_item_chevron(item, active, hovered, x, y, w, h)

self:draw_item_body(item, active, hovered, x, y, w, h)
return self:draw_item_body(item, active, hovered, x, y, w, h)
end


Expand All @@ -445,12 +454,16 @@ function TreeView:draw()
local doc = core.active_view.doc
local active_filename = doc and system.absolute_path(doc.filename or "")

local ox = math.abs(self:get_content_offset())
for item, x,y,w,h in self:each_item() do
if y + h >= _y and y < _y + _h then
self:draw_item(item,
local w = self:draw_item(
item,
item == self.selected_item,
item == self.hovered_item,
x, y, w, h)
x, y, w, h
) + ox
self.scroll_width = math.max(w, self.scroll_width)
end
end

Expand Down Expand Up @@ -511,6 +524,7 @@ function TreeView:toggle_expand(toggle, item)
if not item then return end

if item.type == "dir" then
self.scroll_width = 0
if type(toggle) == "boolean" then
item.expanded = toggle
else
Expand Down
Loading