Small Fixes
- Fixed Timer throwing a getNames is nil error - Fixed Scrollbars not calculating opened dropdowns properly - Fixed Dropdowns not using getSelectionColor - Fixed ScrollbarFrames not prioritizing the scroll event on their childrens before they actually scroll - Dropdowns now calculate their height based on added items, you can change that behaviour by using setDropdownSize
This commit is contained in:
@@ -162,6 +162,10 @@ return function(name, basalt)
|
||||
return elements
|
||||
end
|
||||
|
||||
local function getEvents(self, event)
|
||||
return event~=nil and events[event] or events
|
||||
end
|
||||
|
||||
container = {
|
||||
getType = function()
|
||||
return objectType
|
||||
@@ -280,6 +284,7 @@ return function(name, basalt)
|
||||
getDeepObject = getDeepObject,
|
||||
addObject = addObject,
|
||||
removeObject = removeObject,
|
||||
getEvents = getEvents,
|
||||
getEvent = getEvent,
|
||||
addEvent = addEvent,
|
||||
removeEvent = removeEvent,
|
||||
|
||||
@@ -8,14 +8,13 @@ return function(name, basalt)
|
||||
base:setSize(12, 1)
|
||||
base:setZIndex(6)
|
||||
|
||||
local itemSelectedBG = colors.black
|
||||
local itemSelectedFG = colors.lightGray
|
||||
local selectionColorActive = true
|
||||
local align = "left"
|
||||
local yOffset = 0
|
||||
|
||||
local dropdownW = 16
|
||||
local dropdownH = 6
|
||||
local dropdownW = 0
|
||||
local dropdownH = 0
|
||||
local autoSize = true
|
||||
local closedSymbol = "\16"
|
||||
local openedSymbol = "\31"
|
||||
local isOpened = false
|
||||
@@ -46,8 +45,40 @@ return function(name, basalt)
|
||||
return yOffset
|
||||
end,
|
||||
|
||||
addItem = function(self, t, ...)
|
||||
base.addItem(self, t, ...)
|
||||
if(autoSize)then
|
||||
dropdownW = math.max(dropdownW, #t)
|
||||
dropdownH = dropdownH + 1
|
||||
end
|
||||
return self
|
||||
end,
|
||||
|
||||
removeItem = function(self, index)
|
||||
base.removeItem(self, index)
|
||||
if(autoSize)then
|
||||
dropdownW = 0
|
||||
dropdownH = 0
|
||||
for n = 1, #list do
|
||||
dropdownW = math.max(dropdownW, #list[n].text)
|
||||
end
|
||||
dropdownH = #list
|
||||
end
|
||||
end,
|
||||
|
||||
isOpened = function(self)
|
||||
return isOpened
|
||||
end,
|
||||
|
||||
setOpened = function(self, open)
|
||||
isOpened = open
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
setDropdownSize = function(self, width, height)
|
||||
dropdownW, dropdownH = width, height
|
||||
autoSize = false
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
@@ -84,7 +115,7 @@ return function(name, basalt)
|
||||
end
|
||||
local base = base:getBase()
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
isOpened = true
|
||||
isOpened = not isOpened
|
||||
self:getParent():setImportant(self)
|
||||
self:updateDraw()
|
||||
return true
|
||||
@@ -120,7 +151,19 @@ return function(name, basalt)
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if(isOpened)then
|
||||
local xPos, yPos = self:getAbsolutePosition()
|
||||
if(x >= xPos)and(x <= xPos + dropdownW)and(y >= yPos)and(y <= yPos + dropdownH)then
|
||||
self:setFocus()
|
||||
end
|
||||
end
|
||||
if (isOpened)and(self:isFocused()) then
|
||||
local xPos, yPos = self:getAbsolutePosition()
|
||||
if(x < xPos)or(x > xPos + dropdownW)or(y < yPos)or(y > yPos + dropdownH)then
|
||||
return false
|
||||
end
|
||||
if(#self:getAll() <= dropdownH)then return false end
|
||||
|
||||
local list = self:getAll()
|
||||
yOffset = yOffset + dir
|
||||
if (yOffset < 0) then
|
||||
@@ -163,6 +206,7 @@ return function(name, basalt)
|
||||
local t =utils.getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align)
|
||||
if (list[n + yOffset] == val) then
|
||||
if (selectionColorActive) then
|
||||
local itemSelectedBG, itemSelectedFG = self:getSelectionColor()
|
||||
self:addBlit(1, n+1, t, tHex[itemSelectedFG]:rep(#t), tHex[itemSelectedBG]:rep(#t))
|
||||
else
|
||||
self:addBlit(1, n+1, t, tHex[list[n + yOffset].fgCol]:rep(#t), tHex[list[n + yOffset].bgCol]:rep(#t))
|
||||
|
||||
@@ -14,10 +14,19 @@ return function(name, basalt)
|
||||
local objects = self:getObjects()
|
||||
for _, b in pairs(objects) do
|
||||
if(b.element.getWidth~=nil)and(b.element.getX~=nil)then
|
||||
local h, y = b.element:getWidth(), b.element:getX()
|
||||
local w, x = b.element:getWidth(), b.element:getX()
|
||||
local width = self:getWidth()
|
||||
if (h + y - width >= amount) then
|
||||
amount = max(h + y - width, 0)
|
||||
if(b.element:getType()=="Dropdown")then
|
||||
if(b.element:isOpened())then
|
||||
local dropdownW = b.element:getDropdownSize()
|
||||
if (dropdownW + x - width >= amount) then
|
||||
amount = max(dropdownW + x - width, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (h + x - width >= amount) then
|
||||
amount = max(w + x - width, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -31,6 +40,14 @@ return function(name, basalt)
|
||||
if(b.element.getHeight~=nil)and(b.element.getY~=nil)then
|
||||
local h, y = b.element:getHeight(), b.element:getY()
|
||||
local height = self:getHeight()
|
||||
if(b.element:getType()=="Dropdown")then
|
||||
if(b.element:isOpened())then
|
||||
local _,dropdownH = b.element:getDropdownSize()
|
||||
if (dropdownH + y - height >= amount) then
|
||||
amount = max(dropdownH + y - height, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
if (h + y - height >= amount) then
|
||||
amount = max(h + y - height, 0)
|
||||
end
|
||||
@@ -38,6 +55,19 @@ return function(name, basalt)
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
local function scrollHandler(self, dir)
|
||||
local xO, yO = self:getOffset()
|
||||
local scrollAmn
|
||||
if(direction==1)then
|
||||
scrollAmn = calculateScrollAmount and getHorizontalScrollAmount(self) or manualScrollAmount
|
||||
self:setOffset(min(scrollAmn, max(0, xO + dir)), yO)
|
||||
elseif(direction==0)then
|
||||
scrollAmn = calculateScrollAmount and getVerticalScrollAmount(self) or manualScrollAmount
|
||||
self:setOffset(xO, min(scrollAmn, max(0, yO + dir)))
|
||||
end
|
||||
self:updateDraw()
|
||||
end
|
||||
|
||||
local object = {
|
||||
getType = function()
|
||||
@@ -75,20 +105,36 @@ return function(name, basalt)
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if(base.scrollHandler(self, dir, x, y))then
|
||||
local xO, yO = self:getOffset()
|
||||
local scrollAmn
|
||||
if(direction==1)then
|
||||
scrollAmn = calculateScrollAmount and getHorizontalScrollAmount(self) or manualScrollAmount
|
||||
self:setOffset(min(scrollAmn, max(0, xO + dir)), yO)
|
||||
elseif(direction==0)then
|
||||
scrollAmn = calculateScrollAmount and getVerticalScrollAmount(self) or manualScrollAmount
|
||||
self:setOffset(xO, min(scrollAmn, max(0, yO + dir)))
|
||||
if(base:getBase().scrollHandler(self, dir, x, y))then
|
||||
self:sortElementOrder()
|
||||
for _, obj in ipairs(self:getEvents("mouse_scroll")) do
|
||||
if (obj.element.scrollHandler ~= nil) then
|
||||
local xO, yO = 0, 0
|
||||
if(self.getOffset~=nil)then
|
||||
xO, yO = self:getOffset()
|
||||
end
|
||||
if(obj.element.getIgnoreOffset())then
|
||||
xO, yO = 0, 0
|
||||
end
|
||||
if (obj.element.scrollHandler(obj.element, dir, x+xO, y+yO)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
scrollHandler(self, dir, x, y)
|
||||
self:removeFocusedObject()
|
||||
return true
|
||||
end
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
base.draw(self)
|
||||
self:addDraw("scrollableFrame", function()
|
||||
if(calculateScrollAmount)then
|
||||
scrollHandler(self, 0)
|
||||
end
|
||||
end, 0)
|
||||
end,
|
||||
}
|
||||
|
||||
object.__index = object
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
return function(name)
|
||||
return function(name, basalt)
|
||||
local base = basalt.getObject("Object")(name, basalt)
|
||||
local objectType = "Timer"
|
||||
|
||||
local timer = 0
|
||||
@@ -61,7 +62,7 @@ return function(name)
|
||||
end
|
||||
end,
|
||||
}
|
||||
object.__index = object
|
||||
|
||||
return object
|
||||
object.__index = object
|
||||
return setmetatable(object, base)
|
||||
end
|
||||
Reference in New Issue
Block a user