Merge remote-tracking branch 'origin/master'

# Conflicts:
#	docs/home/gettingStarted.md
#	docs/home/installer.md
#	docs/tips/logic.md
This commit is contained in:
Samuel Pizette
2022-06-09 11:08:46 -04:00
37 changed files with 675 additions and 430 deletions

View File

@@ -1,7 +1,7 @@
local basalt = { debugger = true, version = 1 } local basalt = { debugger = true, version = 1 }
local activeFrame local activeFrame
local frames = {} local frames = {}
local keyModifier = {} local keyActive = {}
local parentTerminal = term.current() local parentTerminal = term.current()
local sub = string.sub local sub = string.sub
@@ -140,12 +140,11 @@ local function generateFontSize(size,yeld)
return true return true
end end
generateFontSize(3,false)
local function makeText(nSize, sString, nFC, nBC, bBlit) local function makeText(nSize, sString, nFC, nBC, bBlit)
if not type(sString) == "string" then error("Not a String",3) end --this should never happend with expects in place. if not type(sString) == "string" then error("Not a String",3) end --this should never happend with expects in place.
local cFC = type(nFC) == "string" and nFC:sub(1, 1) or tHex[nFC] or error("Wrong Front Color",3) local cFC = type(nFC) == "string" and nFC:sub(1, 1) or tHex[nFC] or error("Wrong Front Color",3)
local cBC = type(nBC) == "string" and nBC:sub(1, 1) or tHex[nBC] or error("Wrong Back Color",3) local cBC = type(nBC) == "string" and nBC:sub(1, 1) or tHex[nBC] or error("Wrong Back Color",3)
if(fonts[nSize]==nil)then generateFontSize(3,false) end
local font = fonts[nSize] or error("Wrong font size selected",3) local font = fonts[nSize] or error("Wrong font size selected",3)
if sString == "" then return {{""}, {""}, {""}} end if sString == "" then return {{""}, {""}, {""}} end
@@ -649,10 +648,6 @@ local function Object(name)
return isVisible return isVisible
end; end;
getZIndex = function(self)
return zIndex;
end;
setFocus = function(self) setFocus = function(self)
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setFocusedObject(self) self.parent:setFocusedObject(self)
@@ -669,6 +664,10 @@ local function Object(name)
return self return self
end; end;
getZIndex = function(self)
return zIndex;
end;
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -714,6 +713,7 @@ local function Object(name)
setVisualChanged = function(self, change) setVisualChanged = function(self, change)
visualsChanged = change or true visualsChanged = change or true
if(change == nil)then visualsChanged = true end
return self return self
end; end;
@@ -1122,6 +1122,7 @@ local function Button(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
@@ -1178,6 +1179,7 @@ local function Checkbox(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
@@ -1205,7 +1207,7 @@ local function Dropdown(name)
local dropdownH = 6 local dropdownH = 6
local closedSymbol = "\16" local closedSymbol = "\16"
local openedSymbol = "\31" local openedSymbol = "\31"
local state = 1 local isOpened = false
local object = { local object = {
getType = function(self) getType = function(self)
@@ -1282,7 +1284,7 @@ local function Dropdown(name)
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseClickHandler = function(self, event, button, x, y)
if (state == 2) then if (isOpened) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
@@ -1317,9 +1319,9 @@ local function Dropdown(name)
self:setVisualChanged() self:setVisualChanged()
end end
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseClickHandler(self, event, button, x, y)) then
state = 2 isOpened = true
else else
state = 1 isOpened = false
end end
end; end;
@@ -1328,33 +1330,27 @@ local function Dropdown(name)
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
if (#list >= 1) then local val = self:getValue()
if (self:getValue() ~= nil) then local text = getTextHorizontalAlign((val~=nil and val.text or ""), self.width, align):sub(1, self.width - 1) .. (isOpened and openedSymbol or closedSymbol)
if (self:getValue().text ~= nil) then self.parent:writeText(obx, oby, text, self.bgColor, self.fgColor)
if (state == 1) then
self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.width, align):sub(1, self.width - 1) .. closedSymbol, self.bgColor, self.fgColor) if (isOpened) then
else for n = 1, dropdownH do
self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.width, align):sub(1, self.width - 1) .. openedSymbol, self.bgColor, self.fgColor) if (list[n + yOffset] ~= nil) then
end if (list[n + yOffset] == val) then
end if (selectionColorActive) then
end self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), itemSelectedBG, itemSelectedFG)
if (state == 2) then
for n = 1, dropdownH do
if (list[n + yOffset] ~= nil) then
if (list[n + yOffset] == self:getValue()) then
if (selectionColorActive) then
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), itemSelectedBG, itemSelectedFG)
else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end
else else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol) self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end end
else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end end
end end
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -1547,6 +1543,7 @@ local function Image(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -1788,6 +1785,7 @@ local function Input(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -1884,6 +1882,7 @@ local function Label(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
@@ -2043,6 +2042,7 @@ local function List(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -2066,15 +2066,19 @@ local function Menubar(name)
local selectionColorActive = true local selectionColorActive = true
local align = "left" local align = "left"
local itemOffset = 0 local itemOffset = 0
local space = 2 local space = 1
local scrollable = false local scrollable = false
local function maxScroll() local function maxScroll()
local mScroll = 0 local mScroll = 0
local xPos = 1 local xPos = 0
for n = 1, #list do for n = 1, #list do
if (xPos + list[n].text:len() + space * 2 > object.w) then if (xPos + list[n].text:len() + space * 2 > object.width) then
mScroll = mScroll + list[n].text:len() + space * 2 if(xPos < object.width)then
mScroll = mScroll + (list[n].text:len() + space * 2-(object.width - xPos))
else
mScroll = mScroll + list[n].text:len() + space * 2
end
end end
xPos = xPos + list[n].text:len() + space * 2 xPos = xPos + list[n].text:len() + space * 2
@@ -2119,7 +2123,7 @@ local function Menubar(name)
return self return self
end; end;
setButtonOffset = function(self, offset) setPositionOffset = function(self, offset)
itemOffset = offset or 0 itemOffset = offset or 0
if (itemOffset < 0) then if (itemOffset < 0) then
itemOffset = 0 itemOffset = 0
@@ -2132,8 +2136,13 @@ local function Menubar(name)
return self return self
end; end;
getPositionOffset = function(self)
return itemOffset
end;
setScrollable = function(self, scroll) setScrollable = function(self, scroll)
scrollable = scroll scrollable = scroll
if(scroll==nil)then scrollable = true end
return self return self
end; end;
@@ -2169,41 +2178,41 @@ local function Menubar(name)
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseClickHandler = function(self, event, button, x, y)
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) if(base.mouseClickHandler(self, event, button, x, y))then
if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (self:isVisible()) then local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
if (self.parent ~= nil) then if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (self:isVisible()) then
self.parent:setFocusedObject(self) if (self.parent ~= nil) then
end self.parent:setFocusedObject(self)
if (event == "mouse_click") or (event == "monitor_touch") then end
local xPos = 1 if (event == "mouse_click") or (event == "monitor_touch") then
for n = 1 + itemOffset, #list do local xPos = 0
if (list[n] ~= nil) then for n = 1, #list do
if (xPos + list[n].text:len() + space * 2 <= self.width) then if (list[n] ~= nil) then
if (objX + (xPos - 1) <= x) and (objX + (xPos - 1) + list[n].text:len() + space * 2 > x) and (objY == y) then --if (xPos-1 + list[n].text:len() + space * 2 <= self.width) then
if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then
self:setValue(list[n]) self:setValue(list[n])
self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n]) self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
end end
xPos = xPos + list[n].text:len() + space * 2 xPos = xPos + list[n].text:len() + space * 2
else
break
end end
end end
end
end
if (event == "mouse_scroll") and (scrollable) then
itemOffset = itemOffset + button
if (itemOffset < 0) then
itemOffset = 0
end
local mScroll = maxScroll()
if (itemOffset > mScroll) then
itemOffset = mScroll
end
end
self:setVisualChanged(true)
return true
end end
if (event == "mouse_scroll") and (scrollable) then
itemOffset = itemOffset + button
if (itemOffset < 0) then
itemOffset = 0
end
local mScroll = maxScroll()
if (itemOffset > mScroll) then
itemOffset = mScroll
end
end
return true
end end
return false return false
end; end;
@@ -2213,27 +2222,26 @@ local function Menubar(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
local xPos = 0 local text = ""
for _, value in pairs(list) do local textBGCol = ""
if (xPos + value.text:len() + space * 2 <= self.width) then local textFGCol = ""
if (value == self:getValue()) then for _, v in pairs(list) do
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align), itemSelectedBG or value.bgCol, itemSelectedFG or value.fgCol) local newItem = (" "):rep(space) .. v.text .. (" "):rep(space)
else text = text .. newItem
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align), value.bgCol, value.fgCol) if(v == self:getValue())then
end textBGCol = textBGCol .. tHex[itemSelectedBG or v.bgCol or self.bgColor]:rep(newItem:len())
xPos = xPos + value.text:len() + space * 2 textFGCol = textFGCol .. tHex[itemSelectedFG or v.FgCol or self.fgColor]:rep(newItem:len())
else else
if (xPos < self.width + itemOffset) then textBGCol = textBGCol .. tHex[v.bgCol or self.bgColor]:rep(newItem:len())
if (value == self:getValue()) then textFGCol = textFGCol .. tHex[v.FgCol or self.fgColor]:rep(newItem:len())
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align):sub(1, self.width + itemOffset - xPos), itemSelectedBG or value.bgCol, itemSelectedFG or value.fgCol)
else
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align):sub(1, self.width + itemOffset - xPos), value.bgCol, value.fgCol)
end
xPos = xPos + value.text:len() + space * 2
end
end end
end end
self.parent:setText(obx, oby, text:sub(itemOffset+1, self.width+itemOffset))
self.parent:setBG(obx, oby, textBGCol:sub(itemOffset+1, self.width+itemOffset))
self.parent:setFG(obx, oby, textFGCol:sub(itemOffset+1, self.width+itemOffset))
end end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -2257,6 +2265,7 @@ local function Pane(name)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.bgColor)
end end
self:setVisualChanged(false)
end end
end; end;
@@ -2899,6 +2908,7 @@ local function Program(name)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
pWindow.basalt_update() pWindow.basalt_update()
end end
self:setVisualChanged(false)
end end
end; end;
@@ -2998,6 +3008,7 @@ local function Progressbar(name)
self.parent:drawTextBox(obx, oby, self.width / 100 * progress, self.height, activeBarSymbol) self.parent:drawTextBox(obx, oby, self.width / 100 * progress, self.height, activeBarSymbol)
end end
end end
self:setVisualChanged(false)
end end
end; end;
@@ -3123,6 +3134,7 @@ local function Radio(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -3252,6 +3264,7 @@ local function Scrollbar(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -3263,6 +3276,7 @@ local function Slider(name)
local objectType = "Slider" local objectType = "Slider"
base.width = 8 base.width = 8
base.height = 1
base.bgColor = colors.lightGray base.bgColor = colors.lightGray
base.fgColor = colors.gray base.fgColor = colors.gray
base:setValue(1) base:setValue(1)
@@ -3273,6 +3287,7 @@ local function Slider(name)
local bgSymbol = "\140" local bgSymbol = "\140"
local maxValue = base.width local maxValue = base.width
local index = 1 local index = 1
local symbolSize = 1
local object = { local object = {
getType = function(self) getType = function(self)
@@ -3285,6 +3300,22 @@ local function Slider(name)
return self return self
end; end;
setSymbolSize = function(self, size)
symbolSize = tonumber(size) or 1
if (barType == "vertical") then
self:setValue(index - 1 * (maxValue / (self.height - (symbolSize - 1))) - (maxValue / (self.height - (symbolSize - 1))))
elseif (barType == "horizontal") then
self:setValue(index - 1 * (maxValue / (self.width - (symbolSize - 1))) - (maxValue / (self.width - (symbolSize - 1))))
end
self:setVisualChanged()
return self
end;
setMaxValue = function(self, val)
maxValue = val
return self
end;
setBackgroundSymbol = function(self, _bgSymbol) setBackgroundSymbol = function(self, _bgSymbol)
bgSymbol = string.sub(_bgSymbol, 1, 1) bgSymbol = string.sub(_bgSymbol, 1, 1)
self:setVisualChanged() self:setVisualChanged()
@@ -3305,84 +3336,33 @@ local function Slider(name)
mouseClickHandler = function(self, event, button, x, y) mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (barType == "horizontal") then if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
for _index = 0, self.width - 1 do
if (obx + _index == x) and (oby <= y) and (oby + self.height > y) then
index = _index + 1
self:setValue(maxValue / self.width * (index))
self:setVisualChanged()
end
end
end
if (barType == "vertical") then
for _index = 0, self.height - 1 do
if (oby + _index == y) and (obx <= x) and (obx + self.width > x) then
index = _index + 1
self:setValue(maxValue / self.height * (index))
self:setVisualChanged()
end
end
end
--[[if(event=="mouse_scroll")then
self:setValue(self:getValue() + (maxValue/(barType=="vertical" and self.height or self.width))*typ)
self:setVisualChanged()
end
if(self:getValue()>maxValue)then self:setValue(maxValue) end
if(self:getValue()<maxValue/(barType=="vertical" and self.height or self.width))then self:setValue(maxValue/(barType=="vertical" and self.height or self.width)) end
]]
end
end;
draw = function(self)
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
if (barType == "horizontal") then if (barType == "horizontal") then
self.parent:writeText(obx, oby, bgSymbol:rep(index - 1), self.bgColor, self.fgColor) for _index = 0, self.width do
self.parent:writeText(obx + index - 1, oby, symbol, symbolColor, symbolColor) if (obx + _index == x) and (oby <= y) and (oby + self.height > y) then
self.parent:writeText(obx + index, oby, bgSymbol:rep(self.width - (index)), self.bgColor, self.fgColor) index = math.min(_index + 1, self.width - (symbolSize - 1))
self:setValue(maxValue / self.width * (index))
self:setVisualChanged()
end
end
end end
if (barType == "vertical") then if (barType == "vertical") then
for n = 0, self.height - 1 do for _index = 0, self.height do
if (n + 1 == index) then if (oby + _index == y) and (obx <= x) and (obx + self.width > x) then
self.parent:writeText(obx, oby + n, symbol, symbolColor, symbolColor) index = math.min(_index + 1, self.height - (symbolSize - 1))
else self:setValue(maxValue / self.height * (index))
self.parent:writeText(obx, oby + n, bgSymbol, self.bgColor, self.fgColor) self:setVisualChanged()
end end
end end
end end
end end
end if (event == "mouse_scroll") then
end; index = index + button
if (index < 1) then
} index = 1
end
return setmetatable(object, base) index = math.min(index, (barType == "vertical" and self.height or self.width) - (symbolSize - 1))
end self:setValue(maxValue / (barType == "vertical" and self.height or self.width) * index)
local function Switch(name)
local base = Object(name)
local objectType = "Switch"
base.width = 3
base.height = 1
base.bgColor = colors.lightGray
base.fgColor = colors.gray
base:setValue(false)
base:setZIndex(5)
local object = {
getType = function(self)
return objectType
end;
mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
end end
return true return true
end end
@@ -3392,8 +3372,96 @@ local function Switch(name)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
if (barType == "horizontal") then
self.parent:writeText(obx, oby, bgSymbol:rep(index - 1), self.bgColor, self.fgColor)
self.parent:writeText(obx + index - 1, oby, symbol:rep(symbolSize), symbolColor, symbolColor)
self.parent:writeText(obx + index + symbolSize - 1, oby, bgSymbol:rep(self.width - (index + symbolSize - 1)), self.bgColor, self.fgColor)
end
if (barType == "vertical") then
for n = 0, self.height - 1 do
if (index == n + 1) then
for curIndexOffset = 0, math.min(symbolSize - 1, self.height) do
self.parent:writeText(obx, oby + n + curIndexOffset, symbol, symbolColor, symbolColor)
end
else
if (n + 1 < index) or (n + 1 > index - 1 + symbolSize) then
self.parent:writeText(obx, oby + n, bgSymbol, self.bgColor, self.fgColor)
end
end
end
end
end end
self:setVisualChanged(false)
end
end;
}
return setmetatable(object, base)
end
local function Switch(name)
local base = Object(name)
local objectType = "Switch"
base.width = 2
base.height = 1
base.bgColor = colors.lightGray
base.fgColor = colors.gray
base:setValue(false)
base:setZIndex(5)
local bgSymbol = colors.black
local inactiveBG = colors.red
local activeBG = colors.green
local object = {
getType = function(self)
return objectType
end;
setSymbolColor = function(self, symbolColor)
bgSymbol = symbolColor
self:setVisualChanged()
return self
end;
setActiveBackground = function(self, bgcol)
activeBG = bgcol
self:setVisualChanged()
return self
end;
setInactiveBackground = function(self, bgcol)
inactiveBG = bgcol
self:setVisualChanged()
return self
end;
mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") and (button == 1))or(event=="monitor_touch") then
self:setValue(not self:getValue())
end
return true
end
end;
draw = function(self)
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
if(self:getValue())then
self.parent:drawBackgroundBox(obx, oby, 1, self.height, activeBG)
self.parent:drawBackgroundBox(obx+1, oby, 1, self.height, bgSymbol)
else
self.parent:drawBackgroundBox(obx, oby, 1, self.height, bgSymbol)
self.parent:drawBackgroundBox(obx+1, oby, 1, self.height, inactiveBG)
end
end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -3730,6 +3798,7 @@ local function Textfield(name)
self.parent:setText(obx, oby + n - 1, text) self.parent:setText(obx, oby + n - 1, text)
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
@@ -3813,6 +3882,7 @@ local function Timer(name)
local repeats = 0 local repeats = 0
local timerObj local timerObj
local eventSystem = BasaltEvents() local eventSystem = BasaltEvents()
local timerIsActive = false
local object = { local object = {
name = name, name = name,
@@ -3835,15 +3905,24 @@ local function Timer(name)
end; end;
start = function(self) start = function(self)
if(timerIsActive)then
os.cancelTimer(timerObj)
end
repeats = savedRepeats repeats = savedRepeats
timerObj = os.startTimer(timer) timerObj = os.startTimer(timer)
timerIsActive = true
return self return self
end; end;
isActive = function(self)
return timerIsActive
end;
cancel = function(self) cancel = function(self)
if (timerObj ~= nil) then if (timerObj ~= nil) then
os.cancelTimer(timerObj) os.cancelTimer(timerObj)
end end
timerIsActive = false
return self return self
end; end;
@@ -3853,7 +3932,7 @@ local function Timer(name)
end; end;
eventHandler = function(self, event, tObj) eventHandler = function(self, event, tObj)
if (event == "timer") and (tObj == timerObj) then if event == "timer" and tObj == timerObj and timerIsActive then
eventSystem:sendEvent("timed_event", self) eventSystem:sendEvent("timed_event", self)
if (repeats >= 1) then if (repeats >= 1) then
repeats = repeats - 1 repeats = repeats - 1
@@ -3896,7 +3975,7 @@ local function Frame(name, parent)
if (parent ~= nil) then if (parent ~= nil) then
base.parent = parent base.parent = parent
base.width, base.height = parent.w, parent.h base.width, base.height = parent:getSize()
base.bgColor = theme.FrameBG base.bgColor = theme.FrameBG
base.fgColor = theme.FrameFG base.fgColor = theme.FrameFG
else else
@@ -4053,7 +4132,8 @@ local function Frame(name, parent)
end; end;
setFrameAsMonitor = function(self, isMon) setFrameAsMonitor = function(self, isMon)
isMonitor = isMon or true isMonitor = isMon
if(isMon==nil)then isMonitor = true end
return self return self
end; end;
@@ -4289,6 +4369,9 @@ local function Frame(name, parent)
end; end;
draw = function(self) draw = function(self)
for _,v in pairs(monitors)do
v.frame:draw()
end
if (self:getVisualChanged()) then if (self:getVisualChanged()) then
if (base.draw(self)) then if (base.draw(self)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
@@ -4302,7 +4385,7 @@ local function Frame(name, parent)
drawHelper.drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) drawHelper.drawForegroundBox(obx, oby, self.width, self.height, self.fgColor)
drawHelper.drawTextBox(obx, oby, self.width, self.height, " ") drawHelper.drawTextBox(obx, oby, self.width, self.height, " ")
end end
parentTerminal.setCursorBlink(false) termObject.setCursorBlink(false)
if (self.barActive) then if (self.barActive) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:writeText(anchx, anchy, getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor) self.parent:writeText(anchx, anchy, getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor)
@@ -4332,10 +4415,13 @@ local function Frame(name, parent)
end end
self:setVisualChanged(false) self:setVisualChanged(false)
end end
for _,v in pairs(monitors)do end
v.frame:draw() end;
end
drawHelper.update() drawUpdate = function (self)
drawHelper.update()
for k,v in pairs(monitors)do
v.frame:drawUpdate()
end end
end; end;
@@ -4359,7 +4445,6 @@ local function Frame(name, parent)
addLabel = function(self, name) addLabel = function(self, name)
local obj = Label(name) local obj = Label(name)
obj.name = name
obj.bgColor = self.bgColor obj.bgColor = self.bgColor
obj.fgColor = self.fgColor obj.fgColor = self.fgColor
return addObject(obj) return addObject(obj)
@@ -4367,103 +4452,92 @@ local function Frame(name, parent)
addCheckbox = function(self, name) addCheckbox = function(self, name)
local obj = Checkbox(name) local obj = Checkbox(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addInput = function(self, name) addInput = function(self, name)
local obj = Input(name) local obj = Input(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addProgram = function(self, name) addProgram = function(self, name)
local obj = Program(name) local obj = Program(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addTextfield = function(self, name) addTextfield = function(self, name)
local obj = Textfield(name) local obj = Textfield(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addList = function(self, name) addList = function(self, name)
local obj = List(name) local obj = List(name)
obj.name = name obj.name = nam
return addObject(obj) return addObject(obj)
end; end;
addDropdown = function(self, name) addDropdown = function(self, name)
local obj = Dropdown(name) local obj = Dropdown(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addRadio = function(self, name) addRadio = function(self, name)
local obj = Radio(name) local obj = Radio(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addTimer = function(self, name) addTimer = function(self, name)
local obj = Timer(name) local obj = Timer(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addAnimation = function(self, name) addAnimation = function(self, name)
local obj = Animation(name) local obj = Animation(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addSlider = function(self, name) addSlider = function(self, name)
local obj = Slider(name) local obj = Slider(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addScrollbar = function(self, name) addScrollbar = function(self, name)
local obj = Scrollbar(name) local obj = Scrollbar(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addMenubar = function(self, name) addMenubar = function(self, name)
local obj = Menubar(name) local obj = Menubar(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addThread = function(self, name) addThread = function(self, name)
local obj = Thread(name) local obj = Thread(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addPane = function(self, name) addPane = function(self, name)
local obj = Pane(name) local obj = Pane(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addImage = function(self, name) addImage = function(self, name)
local obj = Image(name) local obj = Image(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addProgressbar = function(self, name) addProgressbar = function(self, name)
local obj = Progressbar(name) local obj = Progressbar(name)
obj.name = name return addObject(obj)
end;
addSwitch = function(self, name)
local obj = Switch(name)
return addObject(obj) return addObject(obj)
end; end;
addFrame = function(self, name) addFrame = function(self, name)
local obj = Frame(name, self) local obj = Frame(name, self)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
} }
@@ -4489,12 +4563,21 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
activeFrame:keyHandler(event, p1) activeFrame:keyHandler(event, p1)
activeFrame:backgroundKeyHandler(event, p1) activeFrame:backgroundKeyHandler(event, p1)
end end
if(event == "key")then
keyActive[p1] = true
end
if(event == "key_up")then
keyActive[p1] = false
end
for _, value in pairs(frames) do for _, value in pairs(frames) do
value:eventHandler(event, p1, p2, p3, p4) value:eventHandler(event, p1, p2, p3, p4)
end end
if (updaterActive) then if (updaterActive) then
activeFrame:draw() activeFrame:draw()
activeFrame:drawUpdate()
end end
end end
@@ -4502,6 +4585,7 @@ function basalt.autoUpdate(isActive)
parentTerminal.clear() parentTerminal.clear()
updaterActive = isActive or true updaterActive = isActive or true
activeFrame:draw() activeFrame:draw()
activeFrame:drawUpdate()
while updaterActive do while updaterActive do
local event, p1, p2, p3, p4 = os.pullEventRaw() -- change to raw later local event, p1, p2, p3, p4 = os.pullEventRaw() -- change to raw later
basaltUpdateEvent(event, p1, p2, p3, p4) basaltUpdateEvent(event, p1, p2, p3, p4)
@@ -4509,10 +4593,11 @@ function basalt.autoUpdate(isActive)
end end
function basalt.update(event, p1, p2, p3, p4) function basalt.update(event, p1, p2, p3, p4)
if (event ~= "nil") then if (event ~= nil) then
basaltUpdateEvent(event, p1, p2, p3, p4) basaltUpdateEvent(event, p1, p2, p3, p4)
else else
activeFrame:draw() activeFrame:draw()
activeFrame:drawUpdate()
end end
end end
@@ -4520,6 +4605,11 @@ function basalt.stop()
updaterActive = false updaterActive = false
end end
function basalt.isKeyDown(key)
if(keyActive[key]==nil)then return false end
return keyActive[key];
end
function basalt.getFrame(name) function basalt.getFrame(name)
for _, value in pairs(frames) do for _, value in pairs(frames) do
if (value.name == name) then if (value.name == name) then
@@ -4579,6 +4669,9 @@ if (basalt.debugger) then
basalt.debugList:removeItem(1) basalt.debugList:removeItem(1)
end end
basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount())) basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount()))
if(basalt.debugList.getItemCount() > basalt.debugList:getHeight())then
basalt.debugList:setIndexOffset(basalt.debugList:getItemCount() - basalt.debugList:getHeight())
end
basalt.debugLabel:show() basalt.debugLabel:show()
end end
end end

File diff suppressed because one or more lines are too long

View File

@@ -1,24 +1,24 @@
# Welcome to The Basalt Wiki!<br> # Welcome to The Basalt Wiki!
_Note: The Basalt Wiki is a work in progress. Please treat Wiki errors the same as bugs and report them accordingly._ *Note: The Basalt Wiki is a work in progress. Please treat Wiki errors the same as bugs and report them accordingly.*
Here you can find information about how to use Basalt as well as examples of functional Basalt code. The aim of Basalt is to improve user interaction through visual display. Here you can find information about how to use Basalt as well as examples of functional Basalt code. The aim of Basalt is to improve user interaction through visual display.
## About Basalt ## About Basalt
Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (AKA Computer Craft: Tweaked) - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's <a href="https://tweaked.cc/">home page</a>. Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://www.curseforge.com/minecraft/mc-mods/cc-tweaked).
<br><br>
## Quick Demo ## Quick Demo
![Preview](https://media0.giphy.com/media/fvmNPshXKeU7FFA9iA/giphy.gif) ![Preview](https://media0.giphy.com/media/fvmNPshXKeU7FFA9iA/giphy.gif)
<br><br>
## Questions & Bugs ## Questions & Bugs
Obviously I've implemented some easter eggs, _some people_ call them "bugs". If you happen to discover one of these just make a new <a href="https://github.com/NoryiE/Basalt/issues">issue</a>. Obviously NyoriE has implemented some easter eggs, *some people* call them "bugs". If you happen to discover one of these just make a new <a href="https://github.com/Pyroxenium/Basalt/issues">issue</a>.
Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on <a href="https://github.com/NoryiE/Basalt/discussions">Basalt's Discussion Board</a>. Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on <a href="https://github.com/Pyroxenium/Basalt/discussions">Basalt's Discussion Board</a>, or ask in our [discord](https://discord.gg/yNNnmBVBpE).
You may also message me on Discord: NyoriE#8206 ---
Feel free to join our [discord](https://discord.gg/yNNnmBVBpE)!
<br><br> <br><br>

BIN
docs/_media/installer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -3,7 +3,7 @@
- [Quick Start](home/Quick-Start.md) - [Quick Start](home/Quick-Start.md)
- [Installer](home/installer) - [Installer](home/installer)
- Objects - Objects
- [Animation](objects/Animation.md) - [Object](objects/Object)
- [Basalt](objects/Basalt) - [Basalt](objects/Basalt)
- [Button](objects/Button) - [Button](objects/Button)
- [Checkbox](objects/Checkbox) - [Checkbox](objects/Checkbox)
@@ -14,16 +14,18 @@
- [Label](objects/Label) - [Label](objects/Label)
- [List](objects/List) - [List](objects/List)
- [Menubar](objects/Menubar) - [Menubar](objects/Menubar)
- [Object](objects/Object)
- [Pane](objects/Pane) - [Pane](objects/Pane)
- [Program](objects/Program) - [Program](objects/Program)
- [Radio](objects/Radio) - [Radio](objects/Radio)
- [Scrollbar](objects/Scrollbar) - [Scrollbar](objects/Scrollbar)
- [Slider](objects/Slider) - [Slider](objects/Slider)
- [Text Field](objects/Textfield) - [Text Field](objects/Textfield)
- [Animation](objects/Animation.md)
- [Thread](objects/Thread) - [Thread](objects/Thread)
- [Timer](objects/Timer) - [Timer](objects/Timer)
- Events
- [Mouse Events](events/mouseEvents.md)
- Tips & Tricks - Tips & Tricks
- [Component Logic](tips/logic) - [Component Logic](tips/logic)
- [Changing Button Color](tips/buttons) - [Changing Button Color](tips/buttons)
- [Advanced usage of Events](tips/events.md)

View File

@@ -0,0 +1,63 @@
Here we will talk about mouse events and how you can manipulate them. There are 2 possible mouse events you can add to almost every visual object.
# onClick
`onClick(self, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_click` and `monitor_touch`.
Any visual object can register onClick events.
Here is a example on how to add a onClick event to your button:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnClick()
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick())
```
# onClickUp
`onClickUp(self, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_up`.
Any visual object can register onClickUp events.
Here is a example on how to add a onClickUp event to your button:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnClick()
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick)
function buttonOnRelease()
basalt.debug("Button got released!")
end
button:onClickUp(buttonOnRelease)
```
# onScroll
`onScroll(self, direction, x, y)`<br>
The computercraft event which triggers this method is `mouse_scroll`.
Any visual object can register a onScroll events.
Here is a example on how to add a onScroll event to your button:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnScroll()
basalt.debug("Someone scrolls on me!")
end
button:onScroll(buttonOnScroll)
```

BIN
docs/favicon-16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
docs/favicon-32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
docs/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -1,71 +0,0 @@
# Getting Started!
Basalt aims to be a relatively small, easy to use framework.
Accordingly, we have provided an installation script.
Just use the following command in any CC:Tweaked shell:
`wget https://github.com/Pyroxenium/Basalt/raw/master/basalt.lua basalt.lua`
This will download `basalt.lua` to your local directory.
To load the framework, make use of the following snippet:
```lua
--> For those who are unfamiliar with lua, dofile executes the code in the referenced file
local basalt = dofile("basalt.lua")
```
Here is a fully functioning example of Basalt code:
```lua
local basalt = dofile("basalt.lua") --> Load the Basalt framework
--> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events
--> When Basalt#createFrame makes use of unique identifiers (commonly referred to as UIDs), meaning that the supplied value must be UNIQUE
--> If the supplied UID is ambiguous, Basalt#createFrame returns a nil value
local mainFrame = basalt.createFrame("mainFrame")
--> Show the frame to the user
mainFrame:show()
local button = mainFrame:addButton("clickableButton") --> Add a button to the mainFrame (With a unique identifier)
--> Set the position of the button, Button#setPosition follows an x, y pattern.
--> The x value is how far right the object should be from its anchor (negative values from an anchor will travel left)
--> The y value is how far down the object should be from its anchor (negative values from an anchor will travel up)
button:setPosition(4, 4)
button:setText("Click me!") --> Set the text of our button
local function buttonClick() --> This function serves as our click logic
basalt.debug("I got clicked!")
end
--> Remember! You cannot supply buttonClick(), that will only supply the result of the function
--> Make sure the button knows which function to call when it's clicked
button:onClick(buttonClick)
button:show() --> Make the button visible, so the user can click it
basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect user input
```
If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()
local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining"
:addButton("clickableButton") --> This is an example of call chaining
:setPosition(4,4)
:setText("Click me!")
:onClick(
function()
basalt.debug("I got clicked!")
end)
:show()
basalt.autoUpdate()
```

View File

@@ -1,10 +1,21 @@
# Installer # Installer
This is just a script which helps you to install basalt.lua, if it's not already on the computer. Means, you create your program (which requires basalt) and add this on the top of your program. Now, everytime you execute your program it checks if basalt.lua exists or not. This is just a script which helps you to setup your program to automatically install the Basalt UI Framework, if it doesn't exists. Means, you create your program (which requires basalt) and add this on the top of your program. Now, everytime you execute your program it checks if basalt.lua (or your custom filepath) exists or not, if not it installs it, or if you are using the advanced installer, it asks the user if the program is allowed to install basalt for you.
## Visual Installer ## Basic Installer
Here is a very basic one which just installs basalt.lua if don't exist:
```lua
--Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
if not(fs.exists(filePath))then
shell.run("pastebin run ESs1mg7P "..filePath) -- this is an alternative to the wget command
end
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
```
## Advanced Installer
This is a visual version, it asks the user if he wants to install basalt.lua (if not found)<br> This is a visual version, it asks the user if he wants to install basalt.lua (if not found)<br>
![](https://i.imgur.com/b4Ys7FB.png) ![](https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/installer.png)
```lua ```lua
--Basalt configurated installer --Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
@@ -40,12 +51,12 @@ if not(fs.exists(filePath))then
local event, p1,p2,p3,p4 = os.pullEvent() local event, p1,p2,p3,p4 = os.pullEvent()
if(event=="mouse_click")then if(event=="mouse_click")then
if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then
shell.run("pastebin run ESs1mg7P") -- this is an alternative to the wget command shell.run("pastebin run ESs1mg7P "..filePath)
_installerWindow.setVisible(false) _installerWindow.setVisible(false)
term.clear() term.clear()
break break
end end
if(p3==h/2+2)and(p2<=w/2+9)and(p2>=w/2+4)then if(p3==math.floor(h/2+2))and(p2<=w/2+9)and(p2>=w/2+4)then
_installerWindow.clear() _installerWindow.clear()
_installerWindow.setVisible(false) _installerWindow.setVisible(false)
term.setCursorPos(1,1) term.setCursorPos(1,1)
@@ -59,16 +70,5 @@ if not(fs.exists(filePath))then
end end
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
------------------------------
``` ```
## Basic Installer
Here is a very basic one which just installs basalt.lua if don't exist:
```lua
--Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
if not(fs.exists(filePath))then
shell.run("wget https://github.com/Pyroxenium/Basalt/raw/master/basalt.lua basalt.lua")
end
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
```

View File

@@ -8,6 +8,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<!-- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">--> <!-- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<style> <style>
:root { :root {
--theme-color: #16CC27; --theme-color: #16CC27;
@@ -43,7 +45,7 @@
auto2top: true auto2top: true
} }
</script> </script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-lua.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/prismjs@1.28.0/components/prism-lua.min.js"></script>
<!-- Docsify v4 --> <!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script> <script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script>

View File

@@ -68,8 +68,10 @@ Sets the frame's bar-text alignment
#### Parameters: #### Parameters:
1. `string` Can be supplied with "left", "center", or "right" 1. `string` Can be supplied with "left", "center", or "right"
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Set the title of myFrame to "My first frame!", and align it to the right. * Set the title of myFrame to "My first frame!", and align it to the right.
```lua ```lua
@@ -78,10 +80,13 @@ local mainFrame = myFrame:setBar("My first Frame!"):setBarTextAlign("right")
## showBar ## showBar
Toggles the frame's upper bar Toggles the frame's upper bar
#### Parameters: #### Parameters:
1. `boolean | nil` Whether the frame's bar is visible or if supplied `nil`, is automatically visible 1. `boolean | nil` Whether the frame's bar is visible or if supplied `nil`, is automatically visible
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Sets myFrame to have a bar titled "Hello World!" and subsequently displays it. * Sets myFrame to have a bar titled "Hello World!" and subsequently displays it.
```lua ```lua
@@ -90,10 +95,13 @@ local mainFrame = myFrame:setBar("Hello World!"):showBar()
## addMonitor ## addMonitor
adds a monitor to the active main frame. adds a monitor to the active main frame.
#### Parameters: #### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...) 1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns: #### Returns:
1. `frame` returns a frame which you can use like normal frames 1. `frame` returns a frame which you can use like normal frames
#### Usage: #### Usage:
* Adds a monitor to the mainFrame. Only as long as this frame is also the active Frame, the monitor will be shown. * Adds a monitor to the mainFrame. Only as long as this frame is also the active Frame, the monitor will be shown.
```lua ```lua
@@ -105,10 +113,13 @@ monitor1:setBar("Monitor 1"):showBar()
## setMonitorScale ## setMonitorScale
changes the monitor scale (almost the same as setTextScale()) changes the monitor scale (almost the same as setTextScale())
#### Parameters: #### Parameters:
1. `number` Possible values are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 (1 is the same as 0.5 by setTextScale, and 10 is the same as 5) 1. `number` Possible values are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 (1 is the same as 0.5 by setTextScale, and 10 is the same as 5)
#### Returns: #### Returns:
1. `monitor` The monitor being used 1. `monitor` The monitor being used
#### Usage: #### Usage:
* Changes the monitor scale to 2 * Changes the monitor scale to 2
```lua ```lua
@@ -124,8 +135,10 @@ Returns true if the user is currently holding the respective key down
#### Parameters: #### Parameters:
1. `number | string` - Any os.queueEvent("key") key, or you can use the following strings: "shift", "ctrl", "alt" 1. `number | string` - Any os.queueEvent("key") key, or you can use the following strings: "shift", "ctrl", "alt"
#### Returns: #### Returns:
1. `boolean` - Whether the user is holding the key down 1. `boolean` - Whether the user is holding the key down
#### Usage: #### Usage:
* Checks if the "shift" modifier is active on the myFrame frame * Checks if the "shift" modifier is active on the myFrame frame
```lua ```lua
@@ -150,8 +163,10 @@ Returns a child object of the frame
#### Parameters: #### Parameters:
1. `string` The name of the child object 1. `string` The name of the child object
#### Returns: #### Returns:
1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name 1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name
#### Usage: #### Usage:
* Adds a button with id "myFirstButton", then retrieves it again through the frame object * Adds a button with id "myFirstButton", then retrieves it again through the frame object
```lua ```lua
@@ -161,10 +176,13 @@ local aButton = myFrame:getObject("myFirstButton")
## removeObject ## removeObject
Removes a child object from the frame Removes a child object from the frame
#### Parameters: #### Parameters:
1. `string` The name of the child object 1. `string` The name of the child object
#### Returns: #### Returns:
1. `boolean` Whether the object with the given name was properly removed 1. `boolean` Whether the object with the given name was properly removed
#### Usage: #### Usage:
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id * Adds a button with the id "myFirstButton", then removes it with the aforementioned id
```lua ```lua
@@ -177,8 +195,10 @@ Sets the currently focused object
#### Parameters: #### Parameters:
1. `object` The child object to focus on 1. `object` The child object to focus on
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Creates button with id "myFirstButton", sets the focused object to the previously mentioned button * Creates button with id "myFirstButton", sets the focused object to the previously mentioned button
```lua ```lua
@@ -187,10 +207,13 @@ myFrame:setFocusedObject(aButton)
``` ```
## removeFocusedObject ## removeFocusedObject
Removes the focus of the supplied object Removes the focus of the supplied object
#### Parameters: #### Parameters:
1. `object` The child object to remove focus from 1. `object` The child object to remove focus from
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Creates a button with id "myFirstButton", then removes the focus from that button * Creates a button with id "myFirstButton", then removes the focus from that button
```lua ```lua
@@ -200,9 +223,9 @@ myFrame:removeFocusedObject(aButton)
## getFocusedObject ## getFocusedObject
Gets the currently focused object Gets the currently focused object
#### Parameters:
#### Returns: #### Returns:
1. `object` The currently focused object 1. `object` The currently focused object
#### Usage: #### Usage:
* Gets the currently focused object from the frame, storing it in a variable * Gets the currently focused object from the frame, storing it in a variable
```lua ```lua
@@ -213,8 +236,10 @@ local focusedObject = myFrame:getFocusedObject()
Sets whether the frame can be moved. _In order to move the frame click and drag the upper bar of the frame_ Sets whether the frame can be moved. _In order to move the frame click and drag the upper bar of the frame_
#### Parameters: #### Parameters:
1. `boolean` Whether the object is movable 1. `boolean` Whether the object is movable
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable * Creates a frame with id "myFirstFrame" and makes it movable
```lua ```lua
@@ -227,8 +252,10 @@ local myFrame = basalt.createFrame("myFirstFrame"):setMovable(true)
Sets whether the frame can be moved. _In order to move the frame use the upper bar of the frame_ Sets whether the frame can be moved. _In order to move the frame use the upper bar of the frame_
#### Parameters: #### Parameters:
1. `boolean` Whether the object is movable 1. `boolean` Whether the object is movable
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable * Creates a frame with id "myFirstFrame" and makes it movable
```lua ```lua
@@ -244,8 +271,10 @@ The function can be supplied negative offsets
#### Parameters: #### Parameters:
1. `number` The x direction offset (+/-) 1. `number` The x direction offset (+/-)
2. `number` The y direction offset (+/-) 2. `number` The y direction offset (+/-)
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Creates "myFirstFrame" with an x offset of 5 and a y offset of 3 * Creates "myFirstFrame" with an x offset of 5 and a y offset of 3
```lua ```lua

34
docs/tips/events.md Normal file
View File

@@ -0,0 +1,34 @@
## Short way of adding functions to events
Not everyone knows that a function (or in other words a method) does not need to have a name. Instead of a function name you are also able to add the function itself as a argument.
Both do the exact same thing:
```lua
local function clickButton()
basalt.debug("I got clicked!")
end
button:onClick(clickButton)
```
```lua
button:onClick(function()
basalt.debug("I got clicked!")
end)
```
## Using isKeyDown for shortcuts
there is also a function with which you can check if the user is holding a key down, it is called `basalt.isKeyDown()`. It's especially useful for click events.
Let us say you want a button to execute something, but if you are holding ctrl down, something in the execution should get changed. This is how you would
achieve that:
```lua
button:onClick(function()
if(basalt.isKeyDown(keys.leftCtrl)then
basalt.debug("Ctrl is down!")
else
basalt.debug("Ctrl is up!")
end
end)
```
Make sure to always use the available `keys` table: https://computercraft.info/wiki/Keys_(API)

View File

@@ -3,7 +3,7 @@ You question yourself how you can execute your own logic while basalt is also ac
## Method 1: ## Method 1:
Using parallel.waitForAll Using parallel.waitForAll
```lua ````lua
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame and a button without functionality local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame and a button without functionality
@@ -17,13 +17,13 @@ local function yourCustomHandler()
end end
parallel.waitForAll(basalt.autoUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalts handlers at the time parallel.waitForAll(basalt.autoUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalts handlers at the time
``` ````
You can read [here](http://www.computercraft.info/wiki/Parallel_(API)) what exactly parallel.waitForAll() does You can read [here (tweaked.cc)](https://tweaked.cc/module/parallel.html) what exactly parallel.waitForAll() does
## Method 2: ## Method 2:
Using threads Using threads
```lua ````lua
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a thread local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a thread
@@ -37,12 +37,12 @@ local function yourCustomHandler()
end end
end end
thread:start(yourCustomHandler) -- this will create a coroutine and starts the coroutine, os.sleep does the rest, so you just have to call start once. thread:start(yourCustomHandler) -- this will create a coroutine and starts the coroutine, os.sleep does the rest, so you just have to call start once.
``` ````
## Method 3: ## Method 3:
Using timers Using timers
```lua ````lua
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a timer local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a timer
@@ -53,4 +53,4 @@ local function yourCustomHandler()
-- add your logic here -- add your logic here
end end
timer:onCall(yourCustomHandler):setTime(1, -1):start() -- this will call your function every second until you :cancel() the timer timer:onCall(yourCustomHandler):setTime(1, -1):start() -- this will call your function every second until you :cancel() the timer
``` ````

View File

@@ -24,7 +24,7 @@ local function Frame(name, parent)
if (parent ~= nil) then if (parent ~= nil) then
base.parent = parent base.parent = parent
base.width, base.height = parent.w, parent.h base.width, base.height = parent:getSize()
base.bgColor = theme.FrameBG base.bgColor = theme.FrameBG
base.fgColor = theme.FrameFG base.fgColor = theme.FrameFG
else else
@@ -181,7 +181,8 @@ local function Frame(name, parent)
end; end;
setFrameAsMonitor = function(self, isMon) setFrameAsMonitor = function(self, isMon)
isMonitor = isMon or true isMonitor = isMon
if(isMon==nil)then isMonitor = true end
return self return self
end; end;
@@ -417,6 +418,9 @@ local function Frame(name, parent)
end; end;
draw = function(self) draw = function(self)
for _,v in pairs(monitors)do
v.frame:draw()
end
if (self:getVisualChanged()) then if (self:getVisualChanged()) then
if (base.draw(self)) then if (base.draw(self)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
@@ -430,7 +434,7 @@ local function Frame(name, parent)
drawHelper.drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) drawHelper.drawForegroundBox(obx, oby, self.width, self.height, self.fgColor)
drawHelper.drawTextBox(obx, oby, self.width, self.height, " ") drawHelper.drawTextBox(obx, oby, self.width, self.height, " ")
end end
parentTerminal.setCursorBlink(false) termObject.setCursorBlink(false)
if (self.barActive) then if (self.barActive) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:writeText(anchx, anchy, getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor) self.parent:writeText(anchx, anchy, getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor)
@@ -460,10 +464,13 @@ local function Frame(name, parent)
end end
self:setVisualChanged(false) self:setVisualChanged(false)
end end
for _,v in pairs(monitors)do end
v.frame:draw() end;
end
drawHelper.update() drawUpdate = function (self)
drawHelper.update()
for k,v in pairs(monitors)do
v.frame:drawUpdate()
end end
end; end;
@@ -487,7 +494,6 @@ local function Frame(name, parent)
addLabel = function(self, name) addLabel = function(self, name)
local obj = Label(name) local obj = Label(name)
obj.name = name
obj.bgColor = self.bgColor obj.bgColor = self.bgColor
obj.fgColor = self.fgColor obj.fgColor = self.fgColor
return addObject(obj) return addObject(obj)
@@ -495,103 +501,92 @@ local function Frame(name, parent)
addCheckbox = function(self, name) addCheckbox = function(self, name)
local obj = Checkbox(name) local obj = Checkbox(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addInput = function(self, name) addInput = function(self, name)
local obj = Input(name) local obj = Input(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addProgram = function(self, name) addProgram = function(self, name)
local obj = Program(name) local obj = Program(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addTextfield = function(self, name) addTextfield = function(self, name)
local obj = Textfield(name) local obj = Textfield(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addList = function(self, name) addList = function(self, name)
local obj = List(name) local obj = List(name)
obj.name = name obj.name = nam
return addObject(obj) return addObject(obj)
end; end;
addDropdown = function(self, name) addDropdown = function(self, name)
local obj = Dropdown(name) local obj = Dropdown(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addRadio = function(self, name) addRadio = function(self, name)
local obj = Radio(name) local obj = Radio(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addTimer = function(self, name) addTimer = function(self, name)
local obj = Timer(name) local obj = Timer(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addAnimation = function(self, name) addAnimation = function(self, name)
local obj = Animation(name) local obj = Animation(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addSlider = function(self, name) addSlider = function(self, name)
local obj = Slider(name) local obj = Slider(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addScrollbar = function(self, name) addScrollbar = function(self, name)
local obj = Scrollbar(name) local obj = Scrollbar(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addMenubar = function(self, name) addMenubar = function(self, name)
local obj = Menubar(name) local obj = Menubar(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addThread = function(self, name) addThread = function(self, name)
local obj = Thread(name) local obj = Thread(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addPane = function(self, name) addPane = function(self, name)
local obj = Pane(name) local obj = Pane(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addImage = function(self, name) addImage = function(self, name)
local obj = Image(name) local obj = Image(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addProgressbar = function(self, name) addProgressbar = function(self, name)
local obj = Progressbar(name) local obj = Progressbar(name)
obj.name = name return addObject(obj)
end;
addSwitch = function(self, name)
local obj = Switch(name)
return addObject(obj) return addObject(obj)
end; end;
addFrame = function(self, name) addFrame = function(self, name)
local obj = Frame(name, self) local obj = Frame(name, self)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
} }

View File

@@ -43,10 +43,6 @@ local function Object(name)
return isVisible return isVisible
end; end;
getZIndex = function(self)
return zIndex;
end;
setFocus = function(self) setFocus = function(self)
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setFocusedObject(self) self.parent:setFocusedObject(self)
@@ -63,6 +59,10 @@ local function Object(name)
return self return self
end; end;
getZIndex = function(self)
return zIndex;
end;
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -108,6 +108,7 @@ local function Object(name)
setVisualChanged = function(self, change) setVisualChanged = function(self, change)
visualsChanged = change or true visualsChanged = change or true
if(change == nil)then visualsChanged = true end
return self return self
end; end;

View File

@@ -91,12 +91,11 @@ local function generateFontSize(size,yeld)
return true return true
end end
generateFontSize(3,false)
local function makeText(nSize, sString, nFC, nBC, bBlit) local function makeText(nSize, sString, nFC, nBC, bBlit)
if not type(sString) == "string" then error("Not a String",3) end --this should never happend with expects in place. if not type(sString) == "string" then error("Not a String",3) end --this should never happend with expects in place.
local cFC = type(nFC) == "string" and nFC:sub(1, 1) or tHex[nFC] or error("Wrong Front Color",3) local cFC = type(nFC) == "string" and nFC:sub(1, 1) or tHex[nFC] or error("Wrong Front Color",3)
local cBC = type(nBC) == "string" and nBC:sub(1, 1) or tHex[nBC] or error("Wrong Back Color",3) local cBC = type(nBC) == "string" and nBC:sub(1, 1) or tHex[nBC] or error("Wrong Back Color",3)
if(fonts[nSize]==nil)then generateFontSize(3,false) end
local font = fonts[nSize] or error("Wrong font size selected",3) local font = fonts[nSize] or error("Wrong font size selected",3)
if sString == "" then return {{""}, {""}, {""}} end if sString == "" then return {{""}, {""}, {""}} end

View File

@@ -14,12 +14,21 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
activeFrame:keyHandler(event, p1) activeFrame:keyHandler(event, p1)
activeFrame:backgroundKeyHandler(event, p1) activeFrame:backgroundKeyHandler(event, p1)
end end
if(event == "key")then
keyActive[p1] = true
end
if(event == "key_up")then
keyActive[p1] = false
end
for _, value in pairs(frames) do for _, value in pairs(frames) do
value:eventHandler(event, p1, p2, p3, p4) value:eventHandler(event, p1, p2, p3, p4)
end end
if (updaterActive) then if (updaterActive) then
activeFrame:draw() activeFrame:draw()
activeFrame:drawUpdate()
end end
end end
@@ -27,6 +36,7 @@ function basalt.autoUpdate(isActive)
parentTerminal.clear() parentTerminal.clear()
updaterActive = isActive or true updaterActive = isActive or true
activeFrame:draw() activeFrame:draw()
activeFrame:drawUpdate()
while updaterActive do while updaterActive do
local event, p1, p2, p3, p4 = os.pullEventRaw() -- change to raw later local event, p1, p2, p3, p4 = os.pullEventRaw() -- change to raw later
basaltUpdateEvent(event, p1, p2, p3, p4) basaltUpdateEvent(event, p1, p2, p3, p4)
@@ -34,10 +44,11 @@ function basalt.autoUpdate(isActive)
end end
function basalt.update(event, p1, p2, p3, p4) function basalt.update(event, p1, p2, p3, p4)
if (event ~= "nil") then if (event ~= nil) then
basaltUpdateEvent(event, p1, p2, p3, p4) basaltUpdateEvent(event, p1, p2, p3, p4)
else else
activeFrame:draw() activeFrame:draw()
activeFrame:drawUpdate()
end end
end end
@@ -45,6 +56,11 @@ function basalt.stop()
updaterActive = false updaterActive = false
end end
function basalt.isKeyDown(key)
if(keyActive[key]==nil)then return false end
return keyActive[key];
end
function basalt.getFrame(name) function basalt.getFrame(name)
for _, value in pairs(frames) do for _, value in pairs(frames) do
if (value.name == name) then if (value.name == name) then
@@ -104,6 +120,9 @@ if (basalt.debugger) then
basalt.debugList:removeItem(1) basalt.debugList:removeItem(1)
end end
basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount())) basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount()))
if(basalt.debugList.getItemCount() > basalt.debugList:getHeight())then
basalt.debugList:setIndexOffset(basalt.debugList:getItemCount() - basalt.debugList:getHeight())
end
basalt.debugLabel:show() basalt.debugLabel:show()
end end
end end

View File

@@ -1,7 +1,7 @@
local basalt = { debugger = true, version = 1 } local basalt = { debugger = true, version = 1 }
local activeFrame local activeFrame
local frames = {} local frames = {}
local keyModifier = {} local keyActive = {}
local parentTerminal = term.current() local parentTerminal = term.current()
local sub = string.sub local sub = string.sub

View File

@@ -44,6 +44,7 @@ local function Button(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -48,6 +48,7 @@ local function Checkbox(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -18,7 +18,7 @@ local function Dropdown(name)
local dropdownH = 6 local dropdownH = 6
local closedSymbol = "\16" local closedSymbol = "\16"
local openedSymbol = "\31" local openedSymbol = "\31"
local state = 1 local isOpened = false
local object = { local object = {
getType = function(self) getType = function(self)
@@ -95,7 +95,7 @@ local function Dropdown(name)
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseClickHandler = function(self, event, button, x, y)
if (state == 2) then if (isOpened) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
@@ -130,9 +130,9 @@ local function Dropdown(name)
self:setVisualChanged() self:setVisualChanged()
end end
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseClickHandler(self, event, button, x, y)) then
state = 2 isOpened = true
else else
state = 1 isOpened = false
end end
end; end;
@@ -141,33 +141,27 @@ local function Dropdown(name)
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
if (#list >= 1) then local val = self:getValue()
if (self:getValue() ~= nil) then local text = getTextHorizontalAlign((val~=nil and val.text or ""), self.width, align):sub(1, self.width - 1) .. (isOpened and openedSymbol or closedSymbol)
if (self:getValue().text ~= nil) then self.parent:writeText(obx, oby, text, self.bgColor, self.fgColor)
if (state == 1) then
self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.width, align):sub(1, self.width - 1) .. closedSymbol, self.bgColor, self.fgColor) if (isOpened) then
else for n = 1, dropdownH do
self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.width, align):sub(1, self.width - 1) .. openedSymbol, self.bgColor, self.fgColor) if (list[n + yOffset] ~= nil) then
end if (list[n + yOffset] == val) then
end if (selectionColorActive) then
end self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), itemSelectedBG, itemSelectedFG)
if (state == 2) then
for n = 1, dropdownH do
if (list[n + yOffset] ~= nil) then
if (list[n + yOffset] == self:getValue()) then
if (selectionColorActive) then
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), itemSelectedBG, itemSelectedFG)
else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end
else else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol) self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end end
else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end end
end end
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -184,6 +184,7 @@ local function Image(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -233,6 +233,7 @@ local function Input(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -88,6 +88,7 @@ local function Label(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -150,6 +150,7 @@ local function List(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -15,15 +15,19 @@ local function Menubar(name)
local selectionColorActive = true local selectionColorActive = true
local align = "left" local align = "left"
local itemOffset = 0 local itemOffset = 0
local space = 2 local space = 1
local scrollable = false local scrollable = false
local function maxScroll() local function maxScroll()
local mScroll = 0 local mScroll = 0
local xPos = 1 local xPos = 0
for n = 1, #list do for n = 1, #list do
if (xPos + list[n].text:len() + space * 2 > object.w) then if (xPos + list[n].text:len() + space * 2 > object.width) then
mScroll = mScroll + list[n].text:len() + space * 2 if(xPos < object.width)then
mScroll = mScroll + (list[n].text:len() + space * 2-(object.width - xPos))
else
mScroll = mScroll + list[n].text:len() + space * 2
end
end end
xPos = xPos + list[n].text:len() + space * 2 xPos = xPos + list[n].text:len() + space * 2
@@ -68,7 +72,7 @@ local function Menubar(name)
return self return self
end; end;
setButtonOffset = function(self, offset) setPositionOffset = function(self, offset)
itemOffset = offset or 0 itemOffset = offset or 0
if (itemOffset < 0) then if (itemOffset < 0) then
itemOffset = 0 itemOffset = 0
@@ -81,8 +85,13 @@ local function Menubar(name)
return self return self
end; end;
getPositionOffset = function(self)
return itemOffset
end;
setScrollable = function(self, scroll) setScrollable = function(self, scroll)
scrollable = scroll scrollable = scroll
if(scroll==nil)then scrollable = true end
return self return self
end; end;
@@ -118,41 +127,41 @@ local function Menubar(name)
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseClickHandler = function(self, event, button, x, y)
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) if(base.mouseClickHandler(self, event, button, x, y))then
if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (self:isVisible()) then local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
if (self.parent ~= nil) then if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (self:isVisible()) then
self.parent:setFocusedObject(self) if (self.parent ~= nil) then
end self.parent:setFocusedObject(self)
if (event == "mouse_click") or (event == "monitor_touch") then end
local xPos = 1 if (event == "mouse_click") or (event == "monitor_touch") then
for n = 1 + itemOffset, #list do local xPos = 0
if (list[n] ~= nil) then for n = 1, #list do
if (xPos + list[n].text:len() + space * 2 <= self.width) then if (list[n] ~= nil) then
if (objX + (xPos - 1) <= x) and (objX + (xPos - 1) + list[n].text:len() + space * 2 > x) and (objY == y) then --if (xPos-1 + list[n].text:len() + space * 2 <= self.width) then
if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then
self:setValue(list[n]) self:setValue(list[n])
self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n]) self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
end end
xPos = xPos + list[n].text:len() + space * 2 xPos = xPos + list[n].text:len() + space * 2
else
break
end end
end end
end
end
if (event == "mouse_scroll") and (scrollable) then
itemOffset = itemOffset + button
if (itemOffset < 0) then
itemOffset = 0
end
local mScroll = maxScroll()
if (itemOffset > mScroll) then
itemOffset = mScroll
end
end
self:setVisualChanged(true)
return true
end end
if (event == "mouse_scroll") and (scrollable) then
itemOffset = itemOffset + button
if (itemOffset < 0) then
itemOffset = 0
end
local mScroll = maxScroll()
if (itemOffset > mScroll) then
itemOffset = mScroll
end
end
return true
end end
return false return false
end; end;
@@ -162,27 +171,26 @@ local function Menubar(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
local xPos = 0 local text = ""
for _, value in pairs(list) do local textBGCol = ""
if (xPos + value.text:len() + space * 2 <= self.width) then local textFGCol = ""
if (value == self:getValue()) then for _, v in pairs(list) do
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align), itemSelectedBG or value.bgCol, itemSelectedFG or value.fgCol) local newItem = (" "):rep(space) .. v.text .. (" "):rep(space)
else text = text .. newItem
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align), value.bgCol, value.fgCol) if(v == self:getValue())then
end textBGCol = textBGCol .. tHex[itemSelectedBG or v.bgCol or self.bgColor]:rep(newItem:len())
xPos = xPos + value.text:len() + space * 2 textFGCol = textFGCol .. tHex[itemSelectedFG or v.FgCol or self.fgColor]:rep(newItem:len())
else else
if (xPos < self.width + itemOffset) then textBGCol = textBGCol .. tHex[v.bgCol or self.bgColor]:rep(newItem:len())
if (value == self:getValue()) then textFGCol = textFGCol .. tHex[v.FgCol or self.fgColor]:rep(newItem:len())
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align):sub(1, self.width + itemOffset - xPos), itemSelectedBG or value.bgCol, itemSelectedFG or value.fgCol)
else
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align):sub(1, self.width + itemOffset - xPos), value.bgCol, value.fgCol)
end
xPos = xPos + value.text:len() + space * 2
end
end end
end end
self.parent:setText(obx, oby, text:sub(itemOffset+1, self.width+itemOffset))
self.parent:setBG(obx, oby, textBGCol:sub(itemOffset+1, self.width+itemOffset))
self.parent:setFG(obx, oby, textFGCol:sub(itemOffset+1, self.width+itemOffset))
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -15,6 +15,7 @@ local function Pane(name)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.bgColor)
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -633,6 +633,7 @@ local function Program(name)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
pWindow.basalt_update() pWindow.basalt_update()
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -90,6 +90,7 @@ local function Progressbar(name)
self.parent:drawTextBox(obx, oby, self.width / 100 * progress, self.height, activeBarSymbol) self.parent:drawTextBox(obx, oby, self.width / 100 * progress, self.height, activeBarSymbol)
end end
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -116,6 +116,7 @@ local function Radio(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -121,6 +121,7 @@ local function Scrollbar(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -3,6 +3,7 @@ local function Slider(name)
local objectType = "Slider" local objectType = "Slider"
base.width = 8 base.width = 8
base.height = 1
base.bgColor = colors.lightGray base.bgColor = colors.lightGray
base.fgColor = colors.gray base.fgColor = colors.gray
base:setValue(1) base:setValue(1)
@@ -13,6 +14,7 @@ local function Slider(name)
local bgSymbol = "\140" local bgSymbol = "\140"
local maxValue = base.width local maxValue = base.width
local index = 1 local index = 1
local symbolSize = 1
local object = { local object = {
getType = function(self) getType = function(self)
@@ -25,6 +27,22 @@ local function Slider(name)
return self return self
end; end;
setSymbolSize = function(self, size)
symbolSize = tonumber(size) or 1
if (barType == "vertical") then
self:setValue(index - 1 * (maxValue / (self.height - (symbolSize - 1))) - (maxValue / (self.height - (symbolSize - 1))))
elseif (barType == "horizontal") then
self:setValue(index - 1 * (maxValue / (self.width - (symbolSize - 1))) - (maxValue / (self.width - (symbolSize - 1))))
end
self:setVisualChanged()
return self
end;
setMaxValue = function(self, val)
maxValue = val
return self
end;
setBackgroundSymbol = function(self, _bgSymbol) setBackgroundSymbol = function(self, _bgSymbol)
bgSymbol = string.sub(_bgSymbol, 1, 1) bgSymbol = string.sub(_bgSymbol, 1, 1)
self:setVisualChanged() self:setVisualChanged()
@@ -45,31 +63,35 @@ local function Slider(name)
mouseClickHandler = function(self, event, button, x, y) mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (barType == "horizontal") then if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
for _index = 0, self.width - 1 do if (barType == "horizontal") then
if (obx + _index == x) and (oby <= y) and (oby + self.height > y) then for _index = 0, self.width do
index = _index + 1 if (obx + _index == x) and (oby <= y) and (oby + self.height > y) then
self:setValue(maxValue / self.width * (index)) index = math.min(_index + 1, self.width - (symbolSize - 1))
self:setVisualChanged() self:setValue(maxValue / self.width * (index))
self:setVisualChanged()
end
end
end
if (barType == "vertical") then
for _index = 0, self.height do
if (oby + _index == y) and (obx <= x) and (obx + self.width > x) then
index = math.min(_index + 1, self.height - (symbolSize - 1))
self:setValue(maxValue / self.height * (index))
self:setVisualChanged()
end
end end
end end
end end
if (barType == "vertical") then if (event == "mouse_scroll") then
for _index = 0, self.height - 1 do index = index + button
if (oby + _index == y) and (obx <= x) and (obx + self.width > x) then if (index < 1) then
index = _index + 1 index = 1
self:setValue(maxValue / self.height * (index))
self:setVisualChanged()
end
end end
index = math.min(index, (barType == "vertical" and self.height or self.width) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and self.height or self.width) * index)
end end
--[[if(event=="mouse_scroll")then return true
self:setValue(self:getValue() + (maxValue/(barType=="vertical" and self.height or self.width))*typ)
self:setVisualChanged()
end
if(self:getValue()>maxValue)then self:setValue(maxValue) end
if(self:getValue()<maxValue/(barType=="vertical" and self.height or self.width))then self:setValue(maxValue/(barType=="vertical" and self.height or self.width)) end
]]
end end
end; end;
@@ -79,23 +101,28 @@ local function Slider(name)
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
if (barType == "horizontal") then if (barType == "horizontal") then
self.parent:writeText(obx, oby, bgSymbol:rep(index - 1), self.bgColor, self.fgColor) self.parent:writeText(obx, oby, bgSymbol:rep(index - 1), self.bgColor, self.fgColor)
self.parent:writeText(obx + index - 1, oby, symbol, symbolColor, symbolColor) self.parent:writeText(obx + index - 1, oby, symbol:rep(symbolSize), symbolColor, symbolColor)
self.parent:writeText(obx + index, oby, bgSymbol:rep(self.width - (index)), self.bgColor, self.fgColor) self.parent:writeText(obx + index + symbolSize - 1, oby, bgSymbol:rep(self.width - (index + symbolSize - 1)), self.bgColor, self.fgColor)
end end
if (barType == "vertical") then if (barType == "vertical") then
for n = 0, self.height - 1 do for n = 0, self.height - 1 do
if (n + 1 == index) then
self.parent:writeText(obx, oby + n, symbol, symbolColor, symbolColor) if (index == n + 1) then
for curIndexOffset = 0, math.min(symbolSize - 1, self.height) do
self.parent:writeText(obx, oby + n + curIndexOffset, symbol, symbolColor, symbolColor)
end
else else
self.parent:writeText(obx, oby + n, bgSymbol, self.bgColor, self.fgColor) if (n + 1 < index) or (n + 1 > index - 1 + symbolSize) then
self.parent:writeText(obx, oby + n, bgSymbol, self.bgColor, self.fgColor)
end
end end
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -2,25 +2,45 @@ local function Switch(name)
local base = Object(name) local base = Object(name)
local objectType = "Switch" local objectType = "Switch"
base.width = 3 base.width = 2
base.height = 1 base.height = 1
base.bgColor = colors.lightGray base.bgColor = colors.lightGray
base.fgColor = colors.gray base.fgColor = colors.gray
base:setValue(false) base:setValue(false)
base:setZIndex(5) base:setZIndex(5)
local bgSymbol = colors.black
local inactiveBG = colors.red
local activeBG = colors.green
local object = { local object = {
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
setSymbolColor = function(self, symbolColor)
bgSymbol = symbolColor
self:setVisualChanged()
return self
end;
setActiveBackground = function(self, bgcol)
activeBG = bgcol
self:setVisualChanged()
return self
end;
setInactiveBackground = function(self, bgcol)
inactiveBG = bgcol
self:setVisualChanged()
return self
end;
mouseClickHandler = function(self, event, button, x, y) mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then if ((event == "mouse_click") and (button == 1))or(event=="monitor_touch") then
self:setValue(not self:getValue())
end end
return true return true
end end
@@ -30,8 +50,16 @@ local function Switch(name)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
if(self:getValue())then
self.parent:drawBackgroundBox(obx, oby, 1, self.height, activeBG)
self.parent:drawBackgroundBox(obx+1, oby, 1, self.height, bgSymbol)
else
self.parent:drawBackgroundBox(obx, oby, 1, self.height, bgSymbol)
self.parent:drawBackgroundBox(obx+1, oby, 1, self.height, inactiveBG)
end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -328,6 +328,7 @@ local function Textfield(name)
self.parent:setText(obx, oby + n - 1, text) self.parent:setText(obx, oby + n - 1, text)
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -6,6 +6,7 @@ local function Timer(name)
local repeats = 0 local repeats = 0
local timerObj local timerObj
local eventSystem = BasaltEvents() local eventSystem = BasaltEvents()
local timerIsActive = false
local object = { local object = {
name = name, name = name,
@@ -28,15 +29,24 @@ local function Timer(name)
end; end;
start = function(self) start = function(self)
if(timerIsActive)then
os.cancelTimer(timerObj)
end
repeats = savedRepeats repeats = savedRepeats
timerObj = os.startTimer(timer) timerObj = os.startTimer(timer)
timerIsActive = true
return self return self
end; end;
isActive = function(self)
return timerIsActive
end;
cancel = function(self) cancel = function(self)
if (timerObj ~= nil) then if (timerObj ~= nil) then
os.cancelTimer(timerObj) os.cancelTimer(timerObj)
end end
timerIsActive = false
return self return self
end; end;
@@ -46,7 +56,7 @@ local function Timer(name)
end; end;
eventHandler = function(self, event, tObj) eventHandler = function(self, event, tObj)
if (event == "timer") and (tObj == timerObj) then if event == "timer" and tObj == timerObj and timerIsActive then
eventSystem:sendEvent("timed_event", self) eventSystem:sendEvent("timed_event", self)
if (repeats >= 1) then if (repeats >= 1) then
repeats = repeats - 1 repeats = repeats - 1