From 9fc185af2ff44c5c6a58312a9534bdf416c6c90d Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 1 May 2020 23:54:53 +0100 Subject: [PATCH] Added scroll bounds Resolves #9 Resolves #6 Resolves #3 --- data/core/docview.lua | 2 +- data/core/logview.lua | 1 - data/core/view.lua | 11 +++++++++-- data/plugins/projectsearch.lua | 2 -- data/plugins/treeview.lua | 2 -- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/data/core/docview.lua b/data/core/docview.lua index bb6e42f..beada8c 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -127,7 +127,7 @@ end function DocView:get_scrollable_size() - return self:get_line_height() * #self.doc.lines + style.padding.y * 2 + return self:get_line_height() * (#self.doc.lines - 1) + self.size.y end diff --git a/data/core/logview.lua b/data/core/logview.lua index f583706..53ea6d2 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -27,7 +27,6 @@ function LogView:update() self.yoffset = -(style.font:get_height() + style.padding.y) end - self.scroll.to.y = math.max(0, self.scroll.to.y) self:move_towards("yoffset", 0) LogView.super.update(self) diff --git a/data/core/view.lua b/data/core/view.lua index 818bc82..d9230b6 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -45,13 +45,13 @@ end function View:get_scrollable_size() - return 0 + return math.huge end function View:get_scrollbar_rect() local sz = self:get_scrollable_size() - if sz <= self.size.y then + if sz <= self.size.y or sz == math.huge then return 0, 0, 0, 0 end local h = math.max(20, self.size.y * self.size.y / sz) @@ -117,7 +117,14 @@ function View:get_content_offset() end +function View:clamp_scroll_position() + local max = self:get_scrollable_size() - self.size.y + self.scroll.to.y = common.clamp(self.scroll.to.y, 0, max) +end + + function View:update() + self:clamp_scroll_position() self:move_towards(self.scroll, "x", self.scroll.to.x, 0.3) self:move_towards(self.scroll, "y", self.scroll.to.y, 0.3) end diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index baa876d..66c9f0d 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -102,7 +102,6 @@ end function ResultsView:update() - self.scroll.to.y = math.max(0, self.scroll.to.y) ResultsView.super.update(self) end @@ -118,7 +117,6 @@ end function ResultsView:get_scrollable_size() - local rh = style.padding.y + style.font:get_height() return self:get_results_yoffset() + #self.results * self:get_line_height() end diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 8f992e6..e429d75 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -124,8 +124,6 @@ end function TreeView:update() - self.scroll.to.y = math.max(0, self.scroll.to.y) - -- update width local dest = self.visible and config.treeview_size or 0 self:move_towards(self.size, "x", dest)