Small Update

- Fixed MonitorFrame
- Added MonitorFrame Docs
This commit is contained in:
Robert Jelic
2023-05-03 19:50:35 +02:00
parent 6c235b04df
commit 4b2d417d75
9 changed files with 190 additions and 32 deletions

View File

@@ -142,12 +142,18 @@ return function(name, basalt)
end,
updateTerm = function(self)
basaltDraw.update()
if(basaltDraw~=nil)then
basaltDraw.update()
end
end,
setTerm = function(self, newTerm)
termObject = newTerm
basaltDraw = drawSystem(termObject)
if(newTerm==nil)then
basaltDraw = nil
else
basaltDraw = drawSystem(termObject)
end
return self
end,
@@ -187,6 +193,14 @@ return function(name, basalt)
end,
}
for k,v in pairs({mouse_click={"mouseHandler", true},mouse_up={"mouseUpHandler", false},mouse_drag={"dragHandler", false},mouse_scroll={"scrollHandler", true},mouse_hover={"hoverHandler", false}})do
object[v[1]] = function(self, btn, x, y, ...)
if(base[v[1]](self, btn, x, y, ...))then
basalt.setActiveFrame(self)
end
end
end
for k,v in pairs({"drawBackgroundBox", "drawForegroundBox", "drawTextBox"})do
object[v] = function(self, x, y, width, height, symbol)
local obx, oby = self:getPosition()

View File

@@ -351,8 +351,8 @@ return function(name, basalt)
if(v[2])then
self:removeFocusedObject()
end
return true
end
return true
end
end
end

View File

@@ -56,7 +56,7 @@ return function(name, basalt)
return dropdownW, dropdownH
end,
mouseHandler = function(self, button, x, y)
mouseHandler = function(self, button, x, y, isMon)
if (isOpened) then
local obx, oby = self:getAbsolutePosition()
if(button==1)then
@@ -69,6 +69,12 @@ return function(name, basalt)
self:updateDraw()
local val = self:sendEvent("mouse_click", self, "mouse_click", dir, x, y)
if(val==false)then return val end
if(isMon)then
basalt.schedule(function()
sleep(0.1)
self:mouseUpHandler(button, x, y)
end)()
end
return true
end
end

View File

@@ -1,12 +1,17 @@
local basaltMon = require("basaltMon")
local max,min,sub,rep = math.max,math.min,string.sub,string.rep
return function(name, basalt)
local base = basalt.getObject("BaseFrame")(name, basalt)
local objectType = "MonitorFrame"
base:hide()
base:setTerm(nil)
local isMonitorGroup = false
local monGroup
local object = {
getType = function()
return objectType
end,
@@ -19,22 +24,58 @@ return function(name, basalt)
return base
end,
setMonitor = function(self, name)
local mon = peripheral.wrap(name)
if(mon~=nil)then
self:setTerm(mon)
setMonitor = function(self, newMon)
if(type(newMon)=="string")then
local mon = peripheral.wrap(newMon)
if(mon~=nil)then
self:setTerm(mon)
end
elseif(type(newMon)=="table")then
self:setTerm(newMon)
end
return self
end,
setMonitorGroup = function(self, monGrp)
monGroup = basaltMon(monGrp)
self:setTerm(monGroup)
isMonitorGroup = true
return self
end,
render = function(self)
if(self:getTerm()~=nil)then
base.render(self)
end
end,
show = function(self)
if(basalt.getTerm()~=self:getTerm())then
base.show()
base:getBase().show(self)
basalt.setActiveFrame(self)
for k,v in pairs(colors)do
if(type(v)=="number")then
termObject.setPaletteColor(v, colors.packRGB(term.nativePaletteColor((v))))
end
end
for k,v in pairs(colorTheme)do
if(type(v)=="number")then
termObject.setPaletteColor(type(k)=="number" and k or colors[k], v)
else
local r,g,b = table.unpack(v)
termObject.setPaletteColor(type(k)=="number" and k or colors[k], r,g,b)
end
end
return self
end,
}
object.mouseHandler = function(self, btn, x, y, isMon, monitor, ...)
if(isMonitorGroup)then
x, y = monGroup.calculateClick(monitor, x, y)
end
base.mouseHandler(self, btn, x, y, isMon, monitor, ...)
end
object.__index = object
return setmetatable(object, base)
end