From 4f0d154b31492c28efcff32326e28be2cd70c6ad Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Wed, 3 May 2023 21:00:20 +0200 Subject: [PATCH] Small Fixes Fixed Scrollbar issue causing too long without yield Fixed ignoreOffset bug --- Basalt/objects/Container.lua | 3 +++ Basalt/objects/Object.lua | 2 +- Basalt/objects/Scrollbar.lua | 10 ++++++---- Basalt/objects/VisualObject.lua | 4 ++++ Basalt/plugins/animations.lua | 21 +++++++++++++++++++++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Basalt/objects/Container.lua b/Basalt/objects/Container.lua index c8802d8..e81eb72 100644 --- a/Basalt/objects/Container.lua +++ b/Basalt/objects/Container.lua @@ -343,6 +343,9 @@ return function(name, basalt) if(self.getOffset~=nil)then xO, yO = self:getOffset() end + if(obj.element.getIgnoreOffset())then + xO, yO = 0, 0 + end if (obj.element[v[1]](obj.element, btn, x+xO, y+yO, ...)) then return true end diff --git a/Basalt/objects/Object.lua b/Basalt/objects/Object.lua index d17a2cd..f3b209f 100644 --- a/Basalt/objects/Object.lua +++ b/Basalt/objects/Object.lua @@ -141,7 +141,7 @@ return function(name, basalt) end, sendEvent = function(self, event, ...) - return eventSystem:sendEvent(event, self, ...) + return eventSystem:sendEvent(event, self, event, ...) end, onClick = function(self, ...) diff --git a/Basalt/objects/Scrollbar.lua b/Basalt/objects/Scrollbar.lua index a1954f7..7bbabeb 100644 --- a/Basalt/objects/Scrollbar.lua +++ b/Basalt/objects/Scrollbar.lua @@ -10,7 +10,7 @@ return function(name, basalt) local barType = "vertical" local symbol = " " - local symbolBG = colors.yellow + local symbolBG = colors.black local symbolFG = colors.black local scrollAmount = 3 local index = 1 @@ -23,6 +23,7 @@ return function(name, basalt) symbolSize = math.max((barType == "vertical" and h or w-(#symbol)) - (scrollAmount-1), 1) end end + updateSymbolSize() local function mouseEvent(self, button, x, y) local obx, oby = self:getPosition() @@ -67,7 +68,7 @@ return function(name, basalt) index = 1 end local w,h = self:getSize() - index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) + --index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) updateSymbolSize() self:updateDraw() return self @@ -145,8 +146,9 @@ return function(name, basalt) return self end, + scrollbarMoveHandler = function(self) - self:sendEvent("scrollbar_moved", self, self:getIndex()) + self:sendEvent("scrollbar_moved", self:getIndex()) end, customEventHandler = function(self, event, ...) @@ -170,7 +172,7 @@ return function(name, basalt) for n = 0, h - 1 do if (index == n + 1) then for curIndexOffset = 0, math.min(symbolSize - 1, h) do - self:blit(1, index + curIndexOffset, symbol:rep(math.max(#symbol, w)), tHex[symbolFG]:rep(math.max(#symbol, w)), tHex[symbolBG]:rep(math.max(#symbol, w))) + self:addBlit(1, index + curIndexOffset, symbol:rep(math.max(#symbol, w)), tHex[symbolFG]:rep(math.max(#symbol, w)), tHex[symbolBG]:rep(math.max(#symbol, w))) end end end diff --git a/Basalt/objects/VisualObject.lua b/Basalt/objects/VisualObject.lua index c050d29..14d02b4 100644 --- a/Basalt/objects/VisualObject.lua +++ b/Basalt/objects/VisualObject.lua @@ -212,6 +212,10 @@ return function(name, basalt) return self end, + getIgnoreOffset = function(self) + return ignOffset + end, + isCoordsInObject = function(self, x, y) if(isVisible)and(self:isEnabled())then if(x==nil)or(y==nil)then return false end diff --git a/Basalt/plugins/animations.lua b/Basalt/plugins/animations.lua index b1c7663..ca84ab3 100644 --- a/Basalt/plugins/animations.lua +++ b/Basalt/plugins/animations.lua @@ -255,6 +255,19 @@ return { self:listenEvent("other_event") end + local function createColorAnimation(self, duration, timeOffset, typ, set, ...) + local newColors = {...} + if(activeAnimations[typ]~=nil)then + os.cancelTimer(activeAnimations[typ].timerId) + end + activeAnimations[typ] = {} + local colorIndex = 1 + activeAnimations[typ].call = function() + local color = newColors[colorIndex] + set(self, color) + end + end + local object = { animatePosition = function(self, x, y, duration, timeOffset, mode, f) mode = mode or defaultMode @@ -282,6 +295,14 @@ return { return self end, + animateBackground = function(self, color, duration, timeOffset, mode, f) + mode = mode or defaultMode + duration = duration or 1 + timeOffset = timeOffset or 0 + createColorAnimation(self, color, nil, duration, timeOffset, mode, "background", f, self.getBackground, self.setBackground) + return self + end, + doneHandler = function(self, timerId, ...) for k,v in pairs(activeAnimations)do if(v.timerId==timerId)then