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
|
return elements
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function getEvents(self, event)
|
||||||
|
return event~=nil and events[event] or events
|
||||||
|
end
|
||||||
|
|
||||||
container = {
|
container = {
|
||||||
getType = function()
|
getType = function()
|
||||||
return objectType
|
return objectType
|
||||||
@@ -280,6 +284,7 @@ return function(name, basalt)
|
|||||||
getDeepObject = getDeepObject,
|
getDeepObject = getDeepObject,
|
||||||
addObject = addObject,
|
addObject = addObject,
|
||||||
removeObject = removeObject,
|
removeObject = removeObject,
|
||||||
|
getEvents = getEvents,
|
||||||
getEvent = getEvent,
|
getEvent = getEvent,
|
||||||
addEvent = addEvent,
|
addEvent = addEvent,
|
||||||
removeEvent = removeEvent,
|
removeEvent = removeEvent,
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ return function(name, basalt)
|
|||||||
base:setSize(12, 1)
|
base:setSize(12, 1)
|
||||||
base:setZIndex(6)
|
base:setZIndex(6)
|
||||||
|
|
||||||
local itemSelectedBG = colors.black
|
|
||||||
local itemSelectedFG = colors.lightGray
|
|
||||||
local selectionColorActive = true
|
local selectionColorActive = true
|
||||||
local align = "left"
|
local align = "left"
|
||||||
local yOffset = 0
|
local yOffset = 0
|
||||||
|
|
||||||
local dropdownW = 16
|
local dropdownW = 0
|
||||||
local dropdownH = 6
|
local dropdownH = 0
|
||||||
|
local autoSize = true
|
||||||
local closedSymbol = "\16"
|
local closedSymbol = "\16"
|
||||||
local openedSymbol = "\31"
|
local openedSymbol = "\31"
|
||||||
local isOpened = false
|
local isOpened = false
|
||||||
@@ -46,8 +45,40 @@ return function(name, basalt)
|
|||||||
return yOffset
|
return yOffset
|
||||||
end,
|
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)
|
setDropdownSize = function(self, width, height)
|
||||||
dropdownW, dropdownH = width, height
|
dropdownW, dropdownH = width, height
|
||||||
|
autoSize = false
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
@@ -84,7 +115,7 @@ return function(name, basalt)
|
|||||||
end
|
end
|
||||||
local base = base:getBase()
|
local base = base:getBase()
|
||||||
if (base.mouseHandler(self, button, x, y)) then
|
if (base.mouseHandler(self, button, x, y)) then
|
||||||
isOpened = true
|
isOpened = not isOpened
|
||||||
self:getParent():setImportant(self)
|
self:getParent():setImportant(self)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return true
|
return true
|
||||||
@@ -120,7 +151,19 @@ return function(name, basalt)
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
scrollHandler = function(self, dir, x, y)
|
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
|
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()
|
local list = self:getAll()
|
||||||
yOffset = yOffset + dir
|
yOffset = yOffset + dir
|
||||||
if (yOffset < 0) then
|
if (yOffset < 0) then
|
||||||
@@ -163,6 +206,7 @@ return function(name, basalt)
|
|||||||
local t =utils.getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align)
|
local t =utils.getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align)
|
||||||
if (list[n + yOffset] == val) then
|
if (list[n + yOffset] == val) then
|
||||||
if (selectionColorActive) then
|
if (selectionColorActive) then
|
||||||
|
local itemSelectedBG, itemSelectedFG = self:getSelectionColor()
|
||||||
self:addBlit(1, n+1, t, tHex[itemSelectedFG]:rep(#t), tHex[itemSelectedBG]:rep(#t))
|
self:addBlit(1, n+1, t, tHex[itemSelectedFG]:rep(#t), tHex[itemSelectedBG]:rep(#t))
|
||||||
else
|
else
|
||||||
self:addBlit(1, n+1, t, tHex[list[n + yOffset].fgCol]:rep(#t), tHex[list[n + yOffset].bgCol]:rep(#t))
|
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()
|
local objects = self:getObjects()
|
||||||
for _, b in pairs(objects) do
|
for _, b in pairs(objects) do
|
||||||
if(b.element.getWidth~=nil)and(b.element.getX~=nil)then
|
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()
|
local width = self:getWidth()
|
||||||
if (h + y - width >= amount) then
|
if(b.element:getType()=="Dropdown")then
|
||||||
amount = max(h + y - width, 0)
|
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
|
end
|
||||||
end
|
end
|
||||||
@@ -31,6 +40,14 @@ return function(name, basalt)
|
|||||||
if(b.element.getHeight~=nil)and(b.element.getY~=nil)then
|
if(b.element.getHeight~=nil)and(b.element.getY~=nil)then
|
||||||
local h, y = b.element:getHeight(), b.element:getY()
|
local h, y = b.element:getHeight(), b.element:getY()
|
||||||
local height = self:getHeight()
|
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
|
if (h + y - height >= amount) then
|
||||||
amount = max(h + y - height, 0)
|
amount = max(h + y - height, 0)
|
||||||
end
|
end
|
||||||
@@ -38,6 +55,19 @@ return function(name, basalt)
|
|||||||
end
|
end
|
||||||
return amount
|
return amount
|
||||||
end
|
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 = {
|
local object = {
|
||||||
getType = function()
|
getType = function()
|
||||||
@@ -75,20 +105,36 @@ return function(name, basalt)
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
scrollHandler = function(self, dir, x, y)
|
scrollHandler = function(self, dir, x, y)
|
||||||
if(base.scrollHandler(self, dir, x, y))then
|
if(base:getBase().scrollHandler(self, dir, x, y))then
|
||||||
local xO, yO = self:getOffset()
|
self:sortElementOrder()
|
||||||
local scrollAmn
|
for _, obj in ipairs(self:getEvents("mouse_scroll")) do
|
||||||
if(direction==1)then
|
if (obj.element.scrollHandler ~= nil) then
|
||||||
scrollAmn = calculateScrollAmount and getHorizontalScrollAmount(self) or manualScrollAmount
|
local xO, yO = 0, 0
|
||||||
self:setOffset(min(scrollAmn, max(0, xO + dir)), yO)
|
if(self.getOffset~=nil)then
|
||||||
elseif(direction==0)then
|
xO, yO = self:getOffset()
|
||||||
scrollAmn = calculateScrollAmount and getVerticalScrollAmount(self) or manualScrollAmount
|
end
|
||||||
self:setOffset(xO, min(scrollAmn, max(0, yO + dir)))
|
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
|
end
|
||||||
self:updateDraw()
|
scrollHandler(self, dir, x, y)
|
||||||
|
self:removeFocusedObject()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
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
|
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 objectType = "Timer"
|
||||||
|
|
||||||
local timer = 0
|
local timer = 0
|
||||||
@@ -61,7 +62,7 @@ return function(name)
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
object.__index = object
|
|
||||||
|
|
||||||
return object
|
object.__index = object
|
||||||
|
return setmetatable(object, base)
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user