Small improvements

- added term_resize event for craft os pc
- added auto resize on baseframe until you use :setSize()
- added auto max. scrollheight (it will be automatically calculated based on the frames children positions) you can cancel that when using :setMaxScroll()
This commit is contained in:
Robert Jelic
2022-07-30 19:02:14 +02:00
parent a19cddfc37
commit 5f76a059cc
4 changed files with 42 additions and 7 deletions

View File

@@ -30,7 +30,7 @@ return function(name, parent, pTerm, basalt)
local dragYOffset = 0
local isScrollable = false
local minScroll = 0
local maxScroll = 10
local maxScroll = 0
local mirrorActive = false
local mirrorAttached = false
local mirrorSide = ""
@@ -38,6 +38,8 @@ return function(name, parent, pTerm, basalt)
local focusedOBjectCache
local focusedObject
local autoSize = true
local autoScroll = true
base:setZIndex(10)
@@ -225,6 +227,9 @@ return function(name, parent, pTerm, basalt)
if(#dynamicValues[n][3]<=0)then dynamicValues[n][3] = dynValueGetObjects(dynamicValues[n][4], dynamicValues[n][2]) end
numberStr = dynValueObjectToNumber(dynamicValues[n][2], dynamicValues[n][3])
dynamicValues[n][1] = stringToNumber(numberStr)
if(dynamicValues[n][4]:getType()=="Frame")then
dynamicValues[n][4]:recalculateDynamicValues()
end
end
end
end
@@ -234,6 +239,17 @@ return function(name, parent, pTerm, basalt)
return dynamicValues[id][1]
end
local function calculateMaxScroll(self)
for _, value in pairs(objects) do
for _, b in pairs(value) do
local h, y = b:getHeight(), b:getY()
if (h + y > maxScroll) then
maxScroll = math.max((h + y) - self:getHeight(), 0)
end
end
end
end
object = {
barActive = false,
@@ -262,6 +278,9 @@ return function(name, parent, pTerm, basalt)
setSize = function(self, w, h, rel)
base.setSize(self, w, h, rel)
if(self.parent==nil)then
basaltDraw = BasaltDraw()
end
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
@@ -271,6 +290,8 @@ return function(name, parent, pTerm, basalt)
end
end
end
recalculateDynamicValues()
autoSize = false
return self
end;
@@ -361,6 +382,7 @@ return function(name, parent, pTerm, basalt)
setMaxScroll = function(self, max)
maxScroll = max or maxScroll
autoScroll = false
return self
end,
@@ -519,6 +541,7 @@ return function(name, parent, pTerm, basalt)
basalt.setMonitorFrame(monSide, nil)
end
end
self:setSize(termObject.getSize())
basaltDraw = BasaltDraw(termObject)
monSide = side or nil
return self;
@@ -593,6 +616,14 @@ return function(name, parent, pTerm, basalt)
end
end
end
if(autoSize)then
if(self.parent==nil)then
if(event=="term_resize")then
self:setSize(termObject.getSize())
autoSize = true
end
end
end
if(isMonitor)then
if(event == "peripheral")and(p1==monSide)then
if(peripheral.getType(monSide)=="monitor")then
@@ -655,6 +686,7 @@ return function(name, parent, pTerm, basalt)
if(isScrollable)and(importantScroll)then
if(event=="mouse_scroll")then
if(button>0)or(button<0)then
if(autoScroll)then calculateMaxScroll(self) end
yOffset = max(min(yOffset-button, -minScroll),-maxScroll)
end
end
@@ -681,6 +713,7 @@ return function(name, parent, pTerm, basalt)
if(isScrollable)and(not importantScroll)then
if(event=="mouse_scroll")then
if(button>0)or(button<0)then
if(autoScroll)then calculateMaxScroll(self) end
yOffset = max(min(yOffset-button, -minScroll),-maxScroll)
end
end

View File

@@ -206,10 +206,6 @@ return function(name)
return self.parent
end;
getObjectReferencesForDynVal = function(self, str)
end,
setPosition = function(self, xPos, yPos, rel)
if(type(xPos)=="number")then
self.x = rel and self:getX()+xPos or xPos

View File

@@ -28,6 +28,7 @@ return function(drawTerm)
createEmptyLines()
local function recreateWindowArray()
createEmptyLines()
local emptyText = emptySpaceLine
local emptyFG = emptyColorLines[colors.white]
local emptyBG = emptyColorLines[colors.black]
@@ -126,6 +127,11 @@ return function(drawTerm)
end
local drawHelper = {
setSize = function(w, h)
width, height = w, h
recreateWindowArray()
end,
setMirror = function(mirror)
mirrorTerm = mirror
end,

View File

@@ -192,7 +192,7 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
activeKey[p1] = false
end
for _, v in pairs(frames) do
for k, v in pairs(frames) do
v:eventHandler(event, p1, p2, p3, p4)
end
handleSchedules(event, p1, p2, p3, p4)
@@ -339,7 +339,7 @@ basalt = {
basalt.debugFrame = basalt.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug", colors.black, colors.gray)
basalt.debugFrame:addButton("back"):setAnchor("topRight"):setSize(1, 1):setText("\22"):onClick(function() if(basalt.oldFrame~=nil)then basalt.oldFrame:show() end end):setBackground(colors.red):show()
basalt.debugList = basalt.debugFrame:addList("debugList"):setSize(basalt.debugFrame.width - 2, basalt.debugFrame.height - 3):setPosition(2, 3):setScrollable(true):show()
basalt.debugList = basalt.debugFrame:addList("debugList"):setSize("parent.w - 2", "parent.h - 3"):setPosition(2, 3):setScrollable(true):show()
basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() basalt.oldFrame = mainFrame basalt.debugFrame:show() end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottomLeft"):ignoreOffset():setZIndex(20):show()
return basalt