From 3e41d975210043fb669e8992bc5a0a38a6fdec6e Mon Sep 17 00:00:00 2001 From: Stepets Date: Sat, 25 Oct 2014 22:58:36 +0400 Subject: [PATCH] small fixes --- objects/internal/scrollable/scrollbody.lua | 2 + objects/textinput.lua | 86 +++++++++++----------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/objects/internal/scrollable/scrollbody.lua b/objects/internal/scrollable/scrollbody.lua index 31cb509..35a8dd4 100644 --- a/objects/internal/scrollable/scrollbody.lua +++ b/objects/internal/scrollable/scrollbody.lua @@ -157,9 +157,11 @@ function newobject:update(dt) if self.bartype == "vertical" then self.height = self.parent.height self.staticx = self.parent.width - self.width + if parent.hbar then self.height = self.height - parent:GetHorizontalScrollBody().height end elseif self.bartype == "horizontal" then self.width = self.parent.width self.staticy = self.parent.height - self.height + if parent.vbar then self.width = self.width - parent:GetVerticalScrollBody().width end end end diff --git a/objects/textinput.lua b/objects/textinput.lua index 588584d..d6c76d8 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -938,50 +938,52 @@ function newobject:UpdateIndicator() end -- indicator should be visible, so correcting scrolls - local indicatorRelativeX = width + self.textoffsetx - self.offsetx - local leftlimit, rightlimit = 0, self:GetWidth() - if self.linenumberspanel then - leftlimit = leftlimit + self:GetLineNumbersPanel().width - end - if self.vbar then - rightlimit = rightlimit - self:GetVerticalScrollBody().width - end - if not (indicatorRelativeX > leftlimit and indicatorRelativeX < rightlimit) then - local hbody = self:GetHorizontalScrollBody() - if hbody then - local twidth = 0 - for k, v in ipairs(lines) do - local linewidth = 0 - if self.masked then - linewidth = font:getWidth(v:gsub(".", self.maskchar)) - else - linewidth = font:getWidth(v) - end - if linewidth > twidth then - twidth = linewidth - end - end - local correction = self:GetWidth() / 2 - if indicatorRelativeX < leftlimit then - correction = correction * -1 - end - print(correction) - hbody:GetScrollBar():ScrollTo((width + correction) / twidth) + if self.focus then + local indicatorRelativeX = width + self.textoffsetx - self.offsetx + local leftlimit, rightlimit = 25, self:GetWidth() - 25 + if self.linenumberspanel then + leftlimit = leftlimit + self:GetLineNumbersPanel().width end - end - local indicatorRelativeY = (line - 1) * theight + self.textoffsety - self.offsety - local uplimit, downlimit = 0, self:GetHeight() - if self.hbar then - downlimit = downlimit - self:GetHorizontalScrollBody().height - end - if not (indicatorRelativeY > uplimit and indicatorRelativeY < downlimit) then - local vbody = self:GetVerticalScrollBody() - if vbody then - local correction = self:GetHeight() / 2 / theight - if indicatorRelativeY < uplimit then - correction = correction * -1 + if self.vbar then + rightlimit = rightlimit - self:GetVerticalScrollBody().width + end + if not (indicatorRelativeX > leftlimit and indicatorRelativeX < rightlimit) then + local hbody = self:GetHorizontalScrollBody() + if hbody then + local twidth = 0 + for k, v in ipairs(lines) do + local linewidth = 0 + if self.masked then + linewidth = font:getWidth(v:gsub(".", self.maskchar)) + else + linewidth = font:getWidth(v) + end + if linewidth > twidth then + twidth = linewidth + end + end + local correction = self:GetWidth() / 2 + if indicatorRelativeX < leftlimit then + correction = correction * -1 + end + print(correction) + hbody:GetScrollBar():ScrollTo((width + correction) / twidth) + end + end + local indicatorRelativeY = (line - 1) * theight + self.textoffsety - self.offsety + local uplimit, downlimit = 25, self:GetHeight() - 25 + if self.hbar then + downlimit = downlimit - self:GetHorizontalScrollBody().height + end + if not (indicatorRelativeY > uplimit and indicatorRelativeY < downlimit) then + local vbody = self:GetVerticalScrollBody() + if vbody then + local correction = self:GetHeight() / 2 / theight + if indicatorRelativeY < uplimit then + correction = correction * -1 + end + vbody:GetScrollBar():ScrollTo((line - 1 + correction)/#lines) end - vbody:GetScrollBar():ScrollTo((line - 1 + correction)/#lines) end end