smaller changes

- fixed setTheme
- changed drag event (it does not have to be inside the parent frame anymore
- added a bg symbol feature to setBackground - obj:setBackground(bgcolor, bgsymbol, bgsymbolcolor)
This commit is contained in:
Robert Jelic
2022-08-17 22:55:25 +02:00
parent 948b1dac96
commit 97df49d7c2
5 changed files with 82 additions and 77 deletions

View File

@@ -77,17 +77,6 @@ return function(name, parent, pTerm, basalt)
end
end
if (parent ~= nil) then
base.parent = parent
base.width, base.height = parent:getSize()
base.bgColor = parent:getTheme("FrameBG")
base.fgColor = parent:getTheme("FrameText")
else
base.width, base.height = termObject.getSize()
base.bgColor = basalt.getTheme("BasaltBG")
base.fgColor = basalt.getTheme("BasaltText")
end
local function getObject(name)
for _, value in pairs(objects) do
for _, b in pairs(value) do
@@ -409,8 +398,12 @@ return function(name, parent, pTerm, basalt)
return self
end;
setTheme = function(self, _theme)
theme = _theme
setTheme = function(self, _theme, col)
if(type(_theme)=="table")then
theme = _theme
elseif(type(_theme)=="string")then
theme[_theme] = col
end
self:updateDraw()
return self
end,
@@ -851,24 +844,22 @@ return function(name, parent, pTerm, basalt)
self:updateDraw()
return true
end
if(base.dragHandler(self, button, x, y))then
if(events["mouse_drag"]~=nil)then
for _, index in ipairs(eventZIndex["mouse_drag"]) do
if (events["mouse_drag"][index] ~= nil) then
for _, value in rpairs(events["mouse_drag"][index]) do
if (value.dragHandler ~= nil) then
if (value:dragHandler(button, x, y)) then
focusSystem(self)
return true
end
if(events["mouse_drag"]~=nil)then
for _, index in ipairs(eventZIndex["mouse_drag"]) do
if (events["mouse_drag"][index] ~= nil) then
for _, value in rpairs(events["mouse_drag"][index]) do
if (value.dragHandler ~= nil) then
if (value:dragHandler(button, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
focusSystem(self)
return true
end
focusSystem(self)
base.dragHandler(self, button, x, y)
return false
end,
@@ -1017,17 +1008,10 @@ return function(name, parent, pTerm, basalt)
if(isMonitor)and not(monitorAttached)then return false end;
if(self.parent==nil)then if(self:getDraw()==false)then return false end end
if (base.draw(self))then
--if(self.parent==nil)then log("DRAW") end
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
local w,h = self:getSize()
if (self.parent ~= nil) then
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
self.parent:drawTextBox(anchx, anchy, w, h, " ")
end
if(self.bgColor~=false)then self.parent:drawForegroundBox(anchx, anchy, w, h, self.fgColor) end
else
if (self.parent == nil) then
if(self.bgColor~=false)then
basaltDraw.drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
basaltDraw.drawTextBox(anchx, anchy, w, h, " ")
@@ -1090,7 +1074,19 @@ return function(name, parent, pTerm, basalt)
addFrame = function(self, name)
local obj = basalt.newFrame(name or uuid(), self, nil, basalt)
return addObject(obj)
end;
end,
init = function(self)
if (parent ~= nil) then
base.width, base.height = parent:getSize()
self:setBackground(parent:getTheme("FrameBG"))
self:setForeground(parent:getTheme("FrameText"))
else
base.width, base.height = termObject.getSize()
self:setBackground(basalt.getTheme("BasaltBG"))
self:setForeground(basalt.getTheme("BasaltText"))
end
end,
}
for k,v in pairs(_OBJECTS)do
object["add"..k] = function(self, name)

View File

@@ -26,6 +26,11 @@ return function(name)
local isDragging = false
local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0
local bgSymbol = " "
local bgSymbolColor = colors.black
local bgColor = colors.black
local transparentColor = false
local draw = true
local activeEvents = {}
@@ -168,6 +173,7 @@ return function(name)
if (self.parent ~= nil) then
self.parent:removeObject(self)
end
self:updateDraw()
return self
end;
@@ -301,8 +307,17 @@ return function(name)
return self
end,
setBackground = function(self, color)
setBackground = function(self, color, symbol, symbolCol)
self.bgColor = color or false
bgColor = color or false
bgSymbol = symbol or (color~=false and bgSymbol or false)
bgSymbolColor = symbolCol or bgSymbolColor
self:updateDraw()
return self
end;
setTransparent = function(self, color)
transparentColor = color or false
self:updateDraw()
return self
end;
@@ -382,6 +397,18 @@ return function(name)
if(self.parent~=nil)then
local x, y = self:getAnchorPosition()
local w,h = self:getSize()
local wP,hP = self.parent:getSize()
if(x+w<1)or(x>wP)or(y+h<1)or(y>hP)then return false end
if(transparentColor~=false)then
self.parent:drawForegroundBox(x, y, w, h, transparentColor)
end
if(bgColor~=false)then
self.parent:drawBackgroundBox(x, y, w, h, bgColor)
end
if(bgSymbol~=false)then
self.parent:drawForegroundBox(x, y, w, h, bgSymbolColor)
self.parent:drawTextBox(x, y, w, h, bgSymbol)
end
if(shadow)then
self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor)
self.parent:drawBackgroundBox(x+w, y+1, 1, h, shadowColor)
@@ -510,14 +537,13 @@ return function(name)
onChange = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("value_changed", v, value)
self:registerEvent("value_changed", v)
end
end
return self
end;
onClick = function(self, ...)
if(isEnabled)then
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_click", v)
@@ -528,12 +554,10 @@ return function(name)
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
end
end
return self
end;
onClickUp = function(self, ...)
if(isEnabled)then
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_up", v)
@@ -543,13 +567,11 @@ return function(name)
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
end
end
return self
end;
onScroll = function(self, ...)
if(isEnabled)then
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_scroll", v)
@@ -559,22 +581,21 @@ return function(name)
self.parent:addEvent("mouse_scroll", self)
activeEvents["mouse_scroll"] = true
end
end
return self
end;
onDrag = function(self, ...)
if(isEnabled)then
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_drag", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_drag", self)
activeEvents["mouse_drag"] = true
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_drag", v)
end
end
self.parent:addEvent("mouse_drag", self)
activeEvents["mouse_drag"] = true
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
return self
end;
@@ -697,6 +718,8 @@ return function(name)
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
isDragging = true
dragStartX, dragStartY = x, y
return true
end
return false
@@ -737,27 +760,21 @@ return function(name)
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end
local dX, dY = x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO
local val = eventSystem:sendEvent(event, self, event, button, dX, dY, dragStartX, dragStartY, x, y)
if(val~=nil)then return val end
if(self:isCoordsInObject(x, y))then
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
return true
end
return false
end
if(self:isCoordsInObject(x, y))then
local val = eventSystem:sendEvent("mouse_drag", self, button, dX, dY, dragStartX-x, dragStartY-y, x, y)
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
isDragging = true
dragStartX, dragStartY = x, y
dragXOffset, dragYOffset = objX - x, objY - y
if(val~=nil)then return val end
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
return true
end
if(self:isCoordsInObject(x, y))then
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
dragStartX, dragStartY = x, y
dragXOffset, dragYOffset = objX - x, objY - y
end
return false
end,
@@ -807,7 +824,7 @@ return function(name)
end,
valueChangedHandler = function(self)
eventSystem:sendEvent("value_changed", self)
eventSystem:sendEvent("value_changed", self, value)
end;
eventHandler = function(self, event, p1, p2, p3, p4)
@@ -822,6 +839,7 @@ return function(name)
end;
loseFocusHandler = function(self)
isDragging = false
local val = eventSystem:sendEvent("lose_focus", self)
if(val~=nil)then return val end
return true

View File

@@ -302,6 +302,7 @@ basalt = {
end
end
local newFrame = Frame(name,nil,nil,bInstance)
newFrame:init()
table.insert(frames, newFrame)
if(mainFrame==nil)and(newFrame:getName()~="basaltDebuggingFrame")then
newFrame:show()

View File

@@ -14,16 +14,6 @@ return function(name)
return objectType
end;
draw = function(self)
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor)
end
end
end,
}

View File

@@ -31,7 +31,7 @@ return { -- The default main theme for basalt!
ScrollbarBG = colors.lightGray,
ScrollbarText = colors.gray,
ScrollbarSymbolColor = colors.black,
SliderBG = colors.lightGray,
SliderBG = false,
SliderText = colors.gray,
SliderSymbolColor = colors.black,
SwitchBG = colors.lightGray,