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

View File

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

View File

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

View File

@@ -14,16 +14,6 @@ return function(name)
return objectType return objectType
end; 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, ScrollbarBG = colors.lightGray,
ScrollbarText = colors.gray, ScrollbarText = colors.gray,
ScrollbarSymbolColor = colors.black, ScrollbarSymbolColor = colors.black,
SliderBG = colors.lightGray, SliderBG = false,
SliderText = colors.gray, SliderText = colors.gray,
SliderSymbolColor = colors.black, SliderSymbolColor = colors.black,
SwitchBG = colors.lightGray, SwitchBG = colors.lightGray,