42 Commits

Author SHA1 Message Date
Robert Jelic
001e8c4ef6 Small bugfix
Forgot to add a check - if it has a parent or not
2022-08-28 20:27:07 +02:00
Robert Jelic
18601d54f7 Some updates 2022-08-28 20:25:42 +02:00
Robert Jelic
4d614372a1 Updated docs
There is still stuff to do
2022-08-28 18:18:26 +02:00
Robert Jelic
53d7b9f70c smallest bugfix 2022-08-26 23:22:25 +02:00
Robert Jelic
92e91b7d6b Update Animation.lua 2022-08-26 21:18:02 +02:00
Robert Jelic
b6c5531290 example changes and cursor bugfix 2022-08-26 21:13:19 +02:00
Robert Jelic
b637e65983 Update Frame.lua 2022-08-26 19:34:23 +02:00
Robert Jelic
5d12e0db74 Merge branch 'master' of https://github.com/Pyroxenium/Basalt 2022-08-26 19:32:43 +02:00
Robert Jelic
41bbe19de1 small quick fix 2022-08-26 19:31:27 +02:00
Robert Jelic
537d37c21b Update Frame.lua
quick fix for removing events
2022-08-25 23:15:00 +02:00
Robert Jelic
de84dbf406 New example for resizeable frames 2022-08-25 22:38:04 +02:00
Robert Jelic
8ab06dbc17 1.6.0 Release
Release version of basalt 1.6.0
2022-08-25 22:22:47 +02:00
Robert Jelic
14643193b9 Update mouseEvents.md 2022-08-24 20:24:51 +02:00
Robert Jelic
9d7c7d8a85 Merge pull request #26 from Yarillo4/master
Fix nil dereferencing exception in Frames.lua
2022-08-16 20:24:22 +02:00
Yarillo4
6809f9991b Fix nil dereferencing exception 2022-08-16 15:06:36 +02:00
Robert Jelic
b64f3ef87c updated the example
people are still using :show() and supply a id but never use them, probably because the example was not up2date
2022-08-12 19:03:13 +02:00
Robert Jelic
fb227445df Update Frame.md 2022-08-10 19:59:20 +02:00
Robert Jelic
10c25e7615 Update Frame.md 2022-08-10 19:58:17 +02:00
Robert Jelic
dfed9a5512 Merge pull request #25 from toastonrye/master
Example - Controlling Redstone output with a slider
2022-08-09 03:10:08 +02:00
toastonrye
fac7e221b3 Update redstoneAnalogOutput.lua
Add comments
2022-08-08 19:44:24 -05:00
toastonrye
c775958254 Update redstoneAnalogOutput.lua
Uploaded from pastebin
2022-08-08 19:33:51 -05:00
toastonrye
1c76130086 Update redstoneAnalogOutput.lua 2022-08-08 17:09:35 -05:00
toastonrye
57b303f538 Update redstoneAnalogOutput.lua 2022-08-08 16:58:28 -05:00
toastonrye
74071cb4bd Create redstoneAnalogOutput.lua 2022-08-08 16:47:24 -05:00
toastonrye
0cbded634a Delete redstoneAnalogOutput.lua 2022-08-08 16:46:57 -05:00
toastonrye
6ae0242b00 Create redstoneAnalogOutput.lua 2022-08-08 16:45:39 -05:00
Robert Jelic
ad6bf96124 Merge pull request #24 from EmmaKnijn/master
Issues in the documentation that might've caused confusion
2022-08-08 17:27:52 +02:00
EmmaKnijn
039782ec0e Add clarification
IDs for all objects were recently changed to be optional, but this was not reflected in the example script
2022-08-08 17:12:18 +02:00
EmmaKnijn
878e45bf8c Fix require file names
The default install script offered in docs\home\installer.md would install to the file `basalt.lua` instead of `Basalt.lua`, directly following instructions would cause the example script to error because of this.
2022-08-08 17:10:13 +02:00
Robert Jelic
cf387cab5a Merge pull request #23 from Erb3/patch-1
Readme badges + readme demo
2022-08-08 17:02:03 +02:00
Erlend
bcbca630f8 Readme badges + readme demo resizing
I added some cool™ badges to the README, with the help of shields.io.
I also resized the demo so the readme works better on mobile.
2022-08-08 16:59:35 +02:00
Robert Jelic
cfa2f561e4 Merge pull request #22 from Erb3/master
Improved README + Changelog
2022-08-07 10:25:01 +02:00
Erlend
1bc6cb80d2 Improved README + Changelog 2022-08-07 10:21:38 +02:00
Robert Jelic
323b521ddc Update discordCC.lua 2022-08-06 17:26:40 +02:00
Robert Jelic
80e2ed1c33 Merge pull request #21 from toastonrye/patch-2
Patch 2
2022-08-06 17:23:36 +02:00
toastonrye
46bb1c53f2 Update basaltPreview2.lua
typo
2022-08-06 10:07:21 -05:00
toastonrye
e6717c8648 Update basaltPreview.lua
Copied from the Basalt wiki example
2022-08-06 10:04:22 -05:00
Robert Jelic
5b422905fe Fixed file handle bug
Now it should work on CraftOS PC without any errors
2022-07-29 23:56:55 +02:00
Robert Jelic
00e70c8b4e Update basaltPackager.lua 2022-07-29 23:08:16 +02:00
Robert Jelic
ca38c7d560 -fixed file handle is not closing
Never forget to close file handle guys.
2022-07-29 23:05:22 +02:00
Robert Jelic
a3c2e7a043 Delete oldVersions directory
Not necessary anymore, if you are looking for different versions go and look into the release section.
2022-07-29 14:32:52 +02:00
Robert Jelic
c36690da00 Update main.lua 2022-07-28 22:52:53 +02:00
283 changed files with 6018 additions and 19222 deletions

View File

@@ -1,12 +1,12 @@
local Object = require("Object")
local _OBJECTS = require("loadObjects")
local BasaltDraw = require("basaltDraw")
local utils = require("utils")
local layout = require("layout")
local uuid = utils.uuid
local rpairs = utils.rpairs
local xmlValue = utils.getValueFromXML
local tableCount = utils.tableCount
local sub,min,max = string.sub,math.min,math.max
@@ -17,6 +17,8 @@ return function(name, parent, pTerm, basalt)
local objects = {}
local objZIndex = {}
local object = {}
local events = {}
local eventZIndex = {}
local variables = {}
local theme = {}
local dynamicValues = {}
@@ -29,15 +31,20 @@ return function(name, parent, pTerm, basalt)
local dragXOffset = 0
local dragYOffset = 0
local isScrollable = false
local minScroll = 0
local maxScroll = 10
local scrollAmount = 0
local mirrorActive = false
local mirrorAttached = false
local mirrorSide = ""
local importantScroll = false
local isMovable = false
local isDragging =false
local focusedOBjectCache
local focusedObjectCache
local focusedObject
local autoSize = true
local autoScroll = true
local initialized = false
local activeEvents = {}
base:setZIndex(10)
@@ -70,17 +77,6 @@ return function(name, parent, pTerm, basalt)
end
end
if (parent ~= nil) then
base.parent = parent
base.width, base.height = parent:getSize()
base.bgColor = parent:getTheme("FrameBG")
base.fgColor = parent:getTheme("FrameText")
else
base.width, base.height = termObject.getSize()
base.bgColor = basalt.getTheme("BasaltBG")
base.fgColor = basalt.getTheme("BasaltText")
end
local function getObject(name)
for _, value in pairs(objects) do
for _, b in pairs(value) do
@@ -135,11 +131,29 @@ return function(name, parent, pTerm, basalt)
return obj
end
local function removeEvents(self, obj)
for a, b in pairs(events) do
for c, d in pairs(b) do
for key, value in pairs(d) do
if (value == obj) then
table.remove(events[a][c], key)
if(self.parent~=nil)then
if(tableCount(events[event])<=0)then
self.parent:removeEvent(a, self)
end
end
end
end
end
end
end
local function removeObject(obj)
for a, b in pairs(objects) do
for key, value in pairs(b) do
if (value == obj) then
table.remove(objects[a], key)
removeEvents(object, obj)
return true;
end
end
@@ -147,6 +161,73 @@ return function(name, parent, pTerm, basalt)
return false
end
local function getEvent(self, event, name)
for _, value in pairs(events[event]) do
for _, b in pairs(value) do
if (b:getName() == name) then
return b
end
end
end
end
local function addEvent(self, event, obj)
local zIndex = obj:getZIndex()
if(events[event]==nil)then events[event] = {} end
if(eventZIndex[event]==nil)then eventZIndex[event] = {} end
if (getEvent(self, event, obj.name) ~= nil) then
return nil
end
if(self.parent~=nil)then
self.parent:addEvent(event, self)
end
activeEvents[event] = true
if (events[event][zIndex] == nil) then
for x = 1, #eventZIndex[event] + 1 do
if (eventZIndex[event][x] ~= nil) then
if (zIndex == eventZIndex[event][x]) then
break
end
if (zIndex > eventZIndex[event][x]) then
table.insert(eventZIndex[event], x, zIndex)
break
end
else
table.insert(eventZIndex[event], zIndex)
end
end
if (#eventZIndex[event] <= 0) then
table.insert(eventZIndex[event], zIndex)
end
events[event][zIndex] = {}
end
table.insert(events[event][zIndex], obj)
return obj
end
local function removeEvent(self, event, obj)
if(events[event]~=nil)then
for a, b in pairs(events[event]) do
for key, value in pairs(b) do
if (value == obj) then
table.remove(events[event][a], key)
if(#events[event][a]<=0)then
events[event][a] = nil
if(self.parent~=nil)then
if(tableCount(events[event])<=0)then
activeEvents[event] = false
self.parent:removeEvent(event, self)
end
end
end
return true;
end
end
end
end
return false
end
local function stringToNumber(str)
local ok, err = pcall(load("return " .. str))
if not(ok)then error(str.." is not a valid dynamic code") end
@@ -217,7 +298,7 @@ return function(name, parent, pTerm, basalt)
end
local function recalculateDynamicValues()
local function recalculateDynamicValues(self)
if(#dynamicValues>0)then
for n=1,dynValueId do
if(dynamicValues[n]~=nil)then
@@ -225,6 +306,18 @@ 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
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.eventHandler ~= nil) then
value:eventHandler("dynamicValueEvent", self)
end
end
end
end
end
@@ -234,6 +327,31 @@ 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
if(b.getHeight~=nil)and(b.getY~=nil)then
local h, y = b:getHeight(), b:getY()
if (h + y - self:getHeight() > scrollAmount) then
scrollAmount = max(h + y - self:getHeight(), 0)
end
end
end
end
end
local function focusSystem(self)
if(focusedObject~=focusedObjectCache)then
if(focusedObject~=nil)then
focusedObject:loseFocusHandler()
end
if(focusedObjectCache~=nil)then
focusedObjectCache:getFocusHandler()
end
focusedObject = focusedObjectCache
end
end
object = {
barActive = false,
@@ -241,7 +359,11 @@ return function(name, parent, pTerm, basalt)
barTextcolor = colors.black,
barText = "New Frame",
barTextAlign = "left",
isMoveable = false,
addEvent = addEvent,
removeEvent = removeEvent,
removeEvents = removeEvents,
getEvent = getEvent,
newDynamicValue = newDynamicValue,
recalculateDynamicValues = recalculateDynamicValues,
@@ -252,7 +374,7 @@ return function(name, parent, pTerm, basalt)
end;
setFocusedObject = function(self, obj)
focusedOBjectCache = obj
focusedObjectCache = obj
return self
end;
@@ -262,20 +384,30 @@ 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(termObject)
end
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.eventHandler ~= nil) then
value:sendEvent("basalt_resize", value, self)
value:eventHandler("basalt_resize", value, self)
end
end
end
end
self:recalculateDynamicValues()
autoSize = false
return self
end;
setTheme = function(self, _theme)
theme = _theme
setTheme = function(self, _theme, col)
if(type(_theme)=="table")then
theme = _theme
elseif(type(_theme)=="string")then
theme[_theme] = col
end
self:updateDraw()
return self
end,
@@ -289,11 +421,12 @@ return function(name, parent, pTerm, basalt)
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.eventHandler ~= nil) then
value:sendEvent("basalt_reposition", value, self)
value:eventHandler("basalt_reposition", value, self)
end
end
end
end
self:recalculateDynamicValues()
return self
end;
@@ -304,6 +437,7 @@ return function(name, parent, pTerm, basalt)
setOffset = function(self, xO, yO)
xOffset = xO ~= nil and math.floor(xO < 0 and math.abs(xO) or -xO) or xOffset
yOffset = yO ~= nil and math.floor(yO < 0 and math.abs(yO) or -yO) or yOffset
self:updateDraw()
return self
end;
@@ -311,12 +445,12 @@ return function(name, parent, pTerm, basalt)
return xOffset, yOffset
end;
getOffset = function(self) -- internal
getOffset = function(self)
return xOffset < 0 and math.abs(xOffset) or -xOffset, yOffset < 0 and math.abs(yOffset) or -yOffset
end;
removeFocusedObject = function(self)
focusedOBjectCache = nil
focusedObjectCache = nil
return self
end;
@@ -338,43 +472,48 @@ return function(name, parent, pTerm, basalt)
yCursor = oby + _yCursor - 1
end
cursorColor = color or cursorColor
self:setVisualChanged()
if (cursorBlink) then
termObject.setTextColor(cursorColor)
termObject.setCursorPos(xCursor, yCursor)
termObject.setCursorBlink(cursorBlink)
else
termObject.setCursorBlink(false)
end
end
return self
end;
setMoveable = function(self, moveable)
self.isMoveable = moveable or not self.isMoveable
self:setVisualChanged()
setMovable = function(self, movable)
if(self.parent~=nil)then
isMovable = movable or not isMovable
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
self.parent:addEvent("mouse_drag", self)
activeEvents["mouse_drag"] = true
end
return self;
end;
setScrollable = function(self, scrollable)
isScrollable = scrollable and true or false
isScrollable = (scrollable or scrollable==nil) and true or false
if(self.parent~=nil)then
self.parent:addEvent("mouse_scroll", self)
end
activeEvents["mouse_scroll"] = true
return self
end,
setImportantScroll = function(self, imp)
importantScroll = imp and true or false
setScrollAmount = function(self, max)
scrollAmount = max or scrollAmount
autoScroll = false
return self
end,
setMaxScroll = function(self, max)
maxScroll = max or maxScroll
return self
end,
setMinScroll = function(self, min)
minScroll = min or minScroll
return self
end,
getMaxScroll = function(self)
return maxScroll
end,
getMinScroll = function(self)
return minScroll
getScrollAmount = function(self)
return autoScroll and scrollAmount or calculateMaxScroll(self)
end,
show = function(self)
@@ -434,7 +573,7 @@ return function(name, parent, pTerm, basalt)
setValuesByXMLData = function(self, data)
base.setValuesByXMLData(self, data)
if(xmlValue("moveable", data)~=nil)then if(xmlValue("moveable", data))then self:setMoveable(true) end end
if(xmlValue("movable", data)~=nil)then if(xmlValue("movable", data))then self:setMovable(true) end end
if(xmlValue("scrollable", data)~=nil)then if(xmlValue("scrollable", data))then self:setScrollable(true) end end
if(xmlValue("monitor", data)~=nil)then self:setMonitor(xmlValue("monitor", data)):show() end
if(xmlValue("mirror", data)~=nil)then self:setMirror(xmlValue("mirror", data)) end
@@ -446,9 +585,7 @@ return function(name, parent, pTerm, basalt)
if(xmlValue("layout", data)~=nil)then self:addLayout(xmlValue("layout", data)) end
if(xmlValue("xOffset", data)~=nil)then self:setOffset(xmlValue("xOffset", data), yOffset) end
if(xmlValue("yOffset", data)~=nil)then self:setOffset(yOffset, xmlValue("yOffset", data)) end
if(xmlValue("maxScroll", data)~=nil)then self:setMaxScroll(xmlValue("maxScroll", data)) end
if(xmlValue("minScroll", data)~=nil)then self:setMaxScroll(xmlValue("minScroll", data)) end
if(xmlValue("importantScroll", data)~=nil)then self:setImportantScroll(xmlValue("importantScroll", data)) end
if(xmlValue("scrollAmount", data)~=nil)then self:setScrollAmount(xmlValue("scrollAmount", data)) end
local objectList = data:children()
@@ -466,27 +603,28 @@ return function(name, parent, pTerm, basalt)
return self
end,
showBar = function(self, showIt)
showBar = function(self, showIt) -- deprecated
self.barActive = showIt or not self.barActive
self:setVisualChanged()
self:updateDraw()
return self
end;
setBar = function(self, text, bgCol, fgCol)
setBar = function(self, text, bgCol, fgCol) -- deprecated
self.barText = text or ""
self.barBackground = bgCol or self.barBackground
self.barTextcolor = fgCol or self.barTextcolor
self:setVisualChanged()
self:updateDraw()
return self
end;
setBarTextAlign = function(self, align)
setBarTextAlign = function(self, align) -- deprecated
self.barTextAlign = align or "left"
self:setVisualChanged()
self:updateDraw()
return self
end;
setMirror = function(self, side)
if(self.parent~=nil)then error("Frame has to be a base frame in order to attach a mirror.") end
mirrorSide = side
if(mirror~=nil)then
basaltDraw.setMirror(mirror)
@@ -507,11 +645,13 @@ return function(name, parent, pTerm, basalt)
if(peripheral.getType(side)=="monitor")then
termObject = peripheral.wrap(side)
monitorAttached = true
end
if(self.parent~=nil)then
self.parent:removeObject(self)
end
isMonitor = true
basalt.setMonitorFrame(side, self)
else
termObject = parentTerminal
isMonitor = false
@@ -520,85 +660,73 @@ return function(name, parent, pTerm, basalt)
end
end
basaltDraw = BasaltDraw(termObject)
self:setSize(termObject.getSize())
autoSize = true
monSide = side or nil
self:updateDraw()
return self;
end;
getVisualChanged = function(self)
local changed = base.getVisualChanged(self)
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.getVisualChanged ~= nil and value:getVisualChanged()) then
changed = true
end
end
end
end
return changed
end;
loseFocusHandler = function(self)
base.loseFocusHandler(self)
if(focusedOBjectCache~=nil)then
focusedOBjectCache:loseFocusHandler()
focusedOBjectCache = nil
end
if(focusedObject~=nil)then focusedObject:loseFocusHandler() focusedObject = nil end
end;
getFocusHandler = function(self)
base.getFocusHandler(self)
if (self.parent ~= nil) then
self.parent:removeObject(self)
self.parent:addObject(self)
end
end;
keyHandler = function(self, event, key)
if (focusedObject ~= nil) then
if(focusedObject~=self)then
if (focusedObject.keyHandler ~= nil) then
if (focusedObject:keyHandler(event, key)) then
return true
end
end
else
base.keyHandler(self, event, key)
end
end
return false
end;
backgroundKeyHandler = function(self, event, key)
base.backgroundKeyHandler(self, event, key)
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.backgroundKeyHandler ~= nil) then
value:backgroundKeyHandler(event, key)
if(isMovable)then
self.parent:removeEvents(self)
self.parent:removeObject(self)
self.parent:addObject(self)
for k,v in pairs(activeEvents)do
if(v)then
self.parent:addEvent(k, self)
end
end
self:updateDraw()
end
end
if(focusedObject~=nil)then focusedObject:getFocusHandler() end
end;
eventHandler = function(self, event, p1, p2, p3, p4)
base.eventHandler(self, event, p1, p2, p3, p4)
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.eventHandler ~= nil) then
value:eventHandler(event, p1, p2, p3, p4)
if(events["other_event"]~=nil)then
for _, index in ipairs(eventZIndex["other_event"]) do
if (events["other_event"][index] ~= nil) then
for _, value in rpairs(events["other_event"][index]) do
if (value.eventHandler ~= nil) then
if (value:eventHandler(event, p1, p2, p3, p4)) then
return true
end
end
end
end
end
end
if(autoSize)and not(isMonitor)then
if(self.parent==nil)then
if(event=="term_resize")then
self:setSize(termObject.getSize())
autoSize = true
end
end
end
if(isMonitor)then
if(autoSize)then
if(event=="monitor_resize")and(p1==monSide)then
self:setSize(termObject.getSize())
autoSize = true
self:updateDraw()
end
end
if(event == "peripheral")and(p1==monSide)then
if(peripheral.getType(monSide)=="monitor")then
monitorAttached = true
termObject = peripheral.wrap(monSide)
basaltDraw = BasaltDraw(termObject)
self:updateDraw()
end
end
if(event == "peripheral_detach")and(p1==monSide)then
@@ -613,82 +741,199 @@ return function(name, parent, pTerm, basalt)
if(event == "peripheral_detach")and(p1==mirrorSide)then
monitorAttached = false
end
if(event=="monitor_touch")then
self:mouseHandler(event, p1, p2, p3, p4)
if(event=="monitor_touch")and(mirrorSide==p1)then
self:mouseHandler(1, p2, p3, true)
end
end
if (event == "terminate") then
termObject.setCursorPos(1, 1)
termObject.clear()
if (event == "terminate")and(self.parent==nil)then
basalt.stop()
end
end;
end,
mouseHandler = function(self, event, button, x, y)
if (self.drag) then
local xO, yO = self.parent:getOffsetInternal()
xO = xO < 0 and math.abs(xO) or -xO
yO = yO < 0 and math.abs(yO) or -yO
if (event == "mouse_drag") then
local parentX = 1
local parentY = 1
if (self.parent ~= nil) then
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end
self:setPosition(x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO)
end
if (event == "mouse_up") then
self.drag = false
end
return true
end
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
local yOff = false
if(fy-1 == y)and(self:getBorder("top"))then
y = y+1
yOff = true
end
if (base.mouseHandler(self, event, button, x, y)) then
fx = fx + xOffset;fy = fy + yOffset;
if(isScrollable)and(importantScroll)then
if(event=="mouse_scroll")then
if(button>0)or(button<0)then
yOffset = max(min(yOffset-button, -minScroll),-maxScroll)
end
end
end
for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in rpairs(objects[index]) do
mouseHandler = function(self, button, x, y)
if(base.mouseHandler(self, button, x, y))then
if(events["mouse_click"]~=nil)then
self:setCursor(false)
for _, index in ipairs(eventZIndex["mouse_click"]) do
if (events["mouse_click"][index] ~= nil) then
for _, value in rpairs(events["mouse_click"][index]) do
if (value.mouseHandler ~= nil) then
if (value:mouseHandler(event, button, x, y)) then
if (value:mouseHandler(button, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
self:removeFocusedObject()
if (self.isMoveable) then
if (x >= fx) and (x <= fx + self:getWidth() - 1) and (y == fy) and (event == "mouse_click") then
self.drag = true
dragXOffset = fx - x
dragYOffset = yOff and 1 or 0
end
end
if(isScrollable)and(not importantScroll)then
if(event=="mouse_scroll")then
if(button>0)or(button<0)then
yOffset = max(min(yOffset-button, -minScroll),-maxScroll)
end
end
end
if (isMovable) then
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
if (x >= fx) and (x <= fx + self:getWidth() - 1) and (y == fy)then
isDragging = true
dragXOffset = fx - x
dragYOffset = yOff and 1 or 0
end
end
self:removeFocusedObject()
focusSystem(self)
return true
end
return false
end;
end,
mouseUpHandler = function(self, button, x, y)
if (isDragging) then
isDragging = false
end
if(base.mouseUpHandler(self, button, x, y))then
if(events["mouse_up"]~=nil)then
for _, index in ipairs(eventZIndex["mouse_up"]) do
if (events["mouse_up"][index] ~= nil) then
for _, value in rpairs(events["mouse_up"][index]) do
if (value.mouseUpHandler ~= nil) then
if (value:mouseUpHandler(button, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
end
focusSystem(self)
return true
end
return false
end,
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
if(events["mouse_scroll"]~=nil)then
for _, index in pairs(eventZIndex["mouse_scroll"]) do
if (events["mouse_scroll"][index] ~= nil) then
for _, value in rpairs(events["mouse_scroll"][index]) do
if (value.scrollHandler ~= nil) then
if (value:scrollHandler(dir, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
end
local cache = yOffset
if(isScrollable)then
calculateMaxScroll(self)
if(dir>0)or(dir<0)then
yOffset = max(min(yOffset-dir, 0),-scrollAmount)
self:updateDraw()
end
end
self:removeFocusedObject()
focusSystem(self)
if(yOffset==cache)then return false end
return true
end
return false
end,
dragHandler = function(self, button, x, y)
if (isDragging) then
local xO, yO = self.parent:getOffsetInternal()
xO = xO < 0 and math.abs(xO) or -xO
yO = yO < 0 and math.abs(yO) or -yO
local parentX = 1
local parentY = 1
if (self.parent ~= nil) then
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end
self:setPosition(x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO)
self:updateDraw()
return true
end
if(events["mouse_drag"]~=nil)then
for _, index in ipairs(eventZIndex["mouse_drag"]) do
if (events["mouse_drag"][index] ~= nil) then
for _, value in rpairs(events["mouse_drag"][index]) do
if (value.dragHandler ~= nil) then
if (value:dragHandler(button, x, y)) then
focusSystem(self)
return true
end
end
end
end
end
end
focusSystem(self)
base.dragHandler(self, button, x, y)
return false
end,
keyHandler = function(self, key, isHolding)
if (self:isFocused())or(self.parent==nil)then
local val = self:getEventSystem():sendEvent("key", self, "key", key)
if(val==false)then return false end
if(events["key"]~=nil)then
for _, index in pairs(eventZIndex["key"]) do
if (events["key"][index] ~= nil) then
for _, value in rpairs(events["key"][index]) do
if (value.keyHandler ~= nil) then
if (value:keyHandler(key, isHolding)) then
return true
end
end
end
end
end
end
end
return false
end,
keyUpHandler = function(self, key)
if (self:isFocused())or(self.parent==nil)then
local val = self:getEventSystem():sendEvent("key_up", self, "key_up", key)
if(val==false)then return false end
if(events["key_up"]~=nil)then
for _, index in pairs(eventZIndex["key_up"]) do
if (events["key_up"][index] ~= nil) then
for _, value in rpairs(events["key_up"][index]) do
if (value.keyUpHandler ~= nil) then
if (value:keyUpHandler(key)) then
return true
end
end
end
end
end
end
end
return false
end,
charHandler = function(self, char)
if (self:isFocused())or(self.parent==nil)then
local val = self:getEventSystem():sendEvent("char", self, "char", char)
if(val==false)then return false end
if(events["char"]~=nil)then
for _, index in pairs(eventZIndex["char"]) do
if (events["char"][index] ~= nil) then
for _, value in rpairs(events["char"][index]) do
if (value.charHandler ~= nil) then
if (value:charHandler(char)) then
return true
end
end
end
end
end
end
end
return false
end,
setText = function(self, x, y, text)
local obx, oby = self:getAnchorPosition()
@@ -768,84 +1013,54 @@ return function(name, parent, pTerm, basalt)
end
end;
draw = function(self)
draw = function(self, force)
if(isMonitor)and not(monitorAttached)then return false end;
if (self:getVisualChanged()) then
if (base.draw(self)) then
if(focusedObject~=focusedOBjectCache)then
if(focusedOBjectCache~=nil)then
focusedOBjectCache:getFocusHandler()
end
if(focusedObject~=nil)then
focusedObject:loseFocusHandler()
end
focusedObject = focusedOBjectCache
if(self.parent==nil)then if(self:getDraw()==false)then return false end end
if (base.draw(self))then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
local w,h = self:getSize()
if (self.parent == nil) then
if(self.bgColor~=false)then
basaltDraw.drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
basaltDraw.drawTextBox(anchx, anchy, w, h, " ")
end
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
local w,h = self:getSize()
if(self.fgColor~=false)then basaltDraw.drawForegroundBox(anchx, anchy, w, h, self.fgColor) end
end
if (self.barActive) then
if (self.parent ~= nil) then
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
self.parent:drawTextBox(anchx, anchy, w, h, " ")
end
if(self.bgColor~=false)then self.parent:drawForegroundBox(anchx, anchy, w, h, self.fgColor) end
self.parent:writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
else
if(self.bgColor~=false)then
basaltDraw.drawBackgroundBox(anchx, anchy, w, h, self.bgColor)
basaltDraw.drawTextBox(anchx, anchy, w, h, " ")
end
if(self.fgColor~=false)then basaltDraw.drawForegroundBox(anchx, anchy, w, h, self.fgColor) end
basaltDraw.writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
end
termObject.setCursorBlink(false)
if (self.barActive) then
if(self:getBorder("left"))then
if (self.parent ~= nil) then
self.parent:writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
else
basaltDraw.writeText(anchx, anchy, utils.getTextHorizontalAlign(self.barText, w, self.barTextAlign), self.barBackground, self.barTextcolor)
end
if(self:getBorder("left"))then
if (self.parent ~= nil) then
self.parent:drawBackgroundBox(anchx-1, anchy, 1, 1, self.barBackground)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(anchx-1, anchy+1, 1, h-1, self.bgColor)
end
end
end
if(self:getBorder("top"))then
if (self.parent ~= nil) then
self.parent:drawBackgroundBox(anchx-1, anchy-1, w+1, 1, self.barBackground)
self.parent:drawBackgroundBox(anchx-1, anchy, 1, 1, self.barBackground)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(anchx-1, anchy+1, 1, h-1, self.bgColor)
end
end
end
for _, index in rpairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.draw ~= nil) then
value:draw()
end
end
end
end
if (cursorBlink) then
termObject.setTextColor(cursorColor)
termObject.setCursorPos(xCursor, yCursor)
if(self:getBorder("top"))then
if (self.parent ~= nil) then
termObject.setCursorBlink(self:isFocused())
else
termObject.setCursorBlink(cursorBlink)
self.parent:drawBackgroundBox(anchx-1, anchy-1, w+1, 1, self.barBackground)
end
end
end
for _, index in rpairs(objZIndex) do
if (objects[index] ~= nil) then
for _, value in pairs(objects[index]) do
if (value.draw ~= nil) then
value:draw()
end
end
end
self:setVisualChanged(false)
end
end
end;
drawUpdate = function(self)
updateTerm = function(self)
if(isMonitor)and not(monitorAttached)then return false end;
basaltDraw.update()
end;
@@ -868,7 +1083,22 @@ return function(name, parent, pTerm, basalt)
addFrame = function(self, name)
local obj = basalt.newFrame(name or uuid(), self, nil, basalt)
return addObject(obj)
end;
end,
init = function(self)
if not(initialized)then
if (parent ~= nil) then
base.width, base.height = parent:getSize()
self:setBackground(parent:getTheme("FrameBG"))
self:setForeground(parent:getTheme("FrameText"))
else
base.width, base.height = termObject.getSize()
self:setBackground(basalt.getTheme("BasaltBG"))
self:setForeground(basalt.getTheme("BasaltText"))
end
initialized = true
end
end,
}
for k,v in pairs(_OBJECTS)do
object["add"..k] = function(self, name)
@@ -877,4 +1107,4 @@ return function(name, parent, pTerm, basalt)
end
setmetatable(object, base)
return object
end
end

View File

@@ -13,20 +13,23 @@ return function(name)
local anchor = "topLeft"
local ignOffset = false
local isVisible = true
local initialized = false
local shadow = false
local borderLeft = false
local borderTop = false
local borderRight = false
local borderBottom = false
local borderColors = {
left = false,
right = false,
top = false,
bottom = false
}
local shadowColor = colors.black
local borderColor = colors.black
local isEnabled = true
local isDragging = false
local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0
local visualsChanged = true
local draw = true
local activeEvents = {}
local eventSystem = basaltEvent()
@@ -36,19 +39,22 @@ return function(name)
width = 1,
height = 1,
bgColor = colors.black,
bgSymbol = " ",
bgSymbolColor = colors.black,
fgColor = colors.white,
transparentColor = false,
name = name or "Object",
parent = nil,
show = function(self)
isVisible = true
visualsChanged = true
self:updateDraw()
return self
end;
hide = function(self)
isVisible = false
visualsChanged = true
self:updateDraw()
return self
end;
@@ -96,13 +102,12 @@ return function(name)
if(xmlValue("enabled", data)~=nil)then if(xmlValue("enabled", data))then self:enable() else self:disable() end end
if(xmlValue("zIndex", data)~=nil)then self:setZIndex(xmlValue("zIndex", data)) end
if(xmlValue("anchor", data)~=nil)then self:setAnchor(xmlValue("anchor", data)) end
if(xmlValue("shadow", data)~=nil)then if(xmlValue("shadow", data))then self:showShadow(true) end end
if(xmlValue("shadowColor", data)~=nil)then self:setShadow(colors[xmlValue("shadowColor", data)]) end
if(xmlValue("border", data)~=nil)then if(xmlValue("border", data))then borderLeft,borderTop,borderRight,borderBottom = true,true,true,true end end
if(xmlValue("borderLeft", data)~=nil)then if(xmlValue("borderLeft", data))then borderLeft = true else borderLeft = false end end
if(xmlValue("borderTop", data)~=nil)then if(xmlValue("borderTop", data))then borderTop = true else borderTop = false end end
if(xmlValue("borderRight", data)~=nil)then if(xmlValue("borderRight", data))then borderRight = true else borderRight = false end end
if(xmlValue("borderBottom", data)~=nil)then if(xmlValue("borderBottom", data))then borderBottom = true else borderBottom = false end end
if(xmlValue("border", data)~=nil)then self:setBorder(colors[xmlValue("border", data)]) end
if(xmlValue("borderLeft", data)~=nil)then borderColors["left"] = xmlValue("borderLeft", data) end
if(xmlValue("borderTop", data)~=nil)then borderColors["top"] = xmlValue("borderTop", data) end
if(xmlValue("borderRight", data)~=nil)then borderColors["right"] = xmlValue("borderRight", data) end
if(xmlValue("borderBottom", data)~=nil)then borderColors["bottom"] = xmlValue("borderBottom", data) end
if(xmlValue("borderColor", data)~=nil)then self:setBorder(colors[xmlValue("borderColor", data)]) end
if(xmlValue("ignoreOffset", data)~=nil)then if(xmlValue("ignoreOffset", data))then self:ignoreOffset(true) end end
if(xmlValue("onClick", data)~=nil)then self:generateXMLEventFunction(self.onClick, xmlValue("onClick", data)) end
@@ -117,9 +122,7 @@ return function(name)
if(xmlValue("onEvent", data)~=nil)then self:generateXMLEventFunction(self.onEvent, xmlValue("onEvent", data)) end
if(xmlValue("onGetFocus", data)~=nil)then self:generateXMLEventFunction(self.onGetFocus, xmlValue("onGetFocus", data)) end
if(xmlValue("onLoseFocus", data)~=nil)then self:generateXMLEventFunction(self.onLoseFocus, xmlValue("onLoseFocus", data)) end
if(xmlValue("onBackgroundKey", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKey, xmlValue("onBackgroundKey", data)) end
if(xmlValue("onBackgroundKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKeyUp, xmlValue("onBackgroundKeyUp", data)) end
self:updateDraw()
return self
end,
@@ -139,9 +142,19 @@ return function(name)
if (self.parent ~= nil) then
self.parent:removeObject(self)
self.parent:addObject(self)
self:updateEventHandlers()
end
return self
end;
end,
updateEventHandlers = function(self)
for k,v in pairs(activeEvents)do
if(v)then
self.parent:addEvent(k, self)
end
end
end,
getZIndex = function(self)
return zIndex;
@@ -159,6 +172,7 @@ return function(name)
if (self.parent ~= nil) then
self.parent:removeObject(self)
end
self:updateDraw()
return self
end;
@@ -176,7 +190,7 @@ return function(name)
setValue = function(self, _value)
if (value ~= _value) then
value = _value
visualsChanged = true
self:updateDraw()
self:valueChangedHandler()
end
return self
@@ -186,13 +200,14 @@ return function(name)
return value
end;
getVisualChanged = function(self)
return visualsChanged
getDraw = function(self)
return draw
end;
setVisualChanged = function(self, change)
visualsChanged = change or true
if(change == nil)then visualsChanged = true end
updateDraw = function(self, change)
draw = change
if(change == nil)then draw = true end
if(draw)then if(self.parent~=nil)then self.parent:updateDraw() end end
return self
end;
@@ -206,10 +221,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
@@ -227,7 +238,7 @@ return function(name)
self.parent:recalculateDynamicValues()
end
eventSystem:sendEvent("basalt_reposition", self)
visualsChanged = true
self:updateDraw()
return self
end;
@@ -249,7 +260,7 @@ return function(name)
setVisibility = function(self, _isVisible)
isVisible = _isVisible or not isVisible
visualsChanged = true
self:updateDraw()
return self
end;
@@ -270,7 +281,7 @@ return function(name)
self.parent:recalculateDynamicValues()
end
eventSystem:sendEvent("basalt_resize", self)
visualsChanged = true
self:updateDraw()
return self
end;
@@ -291,12 +302,23 @@ return function(name)
if(type(self.height)=="table")then self.height:calculate() end
if(type(self.x)=="table")then self.x:calculate() end
if(type(self.y)=="table")then self.y:calculate() end
self:updateDraw()
return self
end,
setBackground = function(self, color)
setBackground = function(self, color, symbol, symbolCol)
self.bgColor = color or false
visualsChanged = true
self.bgSymbol = symbol or (self.bgColor~=false and self.bgSymbol or false)
self.bgSymbolColor = symbolCol or self.bgSymbolColor
self:updateDraw()
return self
end;
setTransparent = function(self, color)
self.transparentColor = color or false
self.bgSymbol = false
self.bgSymbolColor = false
self:updateDraw()
return self
end;
@@ -306,7 +328,7 @@ return function(name)
setForeground = function(self, color)
self.fgColor = color or false
visualsChanged = true
self:updateDraw()
return self
end;
@@ -314,13 +336,14 @@ return function(name)
return self.fgColor
end;
showShadow = function(self, show)
shadow = show or (not shadow)
return self
end;
setShadow = function(self, color)
shadowColor = color
if(color==false)then
shadow = false
else
shadowColor = color
shadow = true
end
self:updateDraw()
return self
end;
@@ -328,26 +351,25 @@ return function(name)
return shadow;
end;
showBorder = function(self, ...)
for _,v in pairs(table.pack(...))do
if(v=="left")then
borderLeft = true
end
if(v=="top")then
borderTop = true
end
if(v=="right")then
borderRight = true
end
if(v=="bottom")then
borderBottom = true
setBorder = function(self, ...)
if(...~=nil)then
local t = {...}
for k,v in pairs(t)do
if(v=="left")or(#t==1)then
borderColors["left"] = t[1]
end
if(v=="top")or(#t==1)then
borderColors["top"] = t[1]
end
if(v=="right")or(#t==1)then
borderColors["right"] = t[1]
end
if(v=="bottom")or(#t==1)then
borderColors["bottom"] = t[1]
end
end
end
return self
end;
setBorder = function(self, color)
borderColor = color
self:updateDraw()
return self
end;
@@ -367,52 +389,68 @@ return function(name)
end;
draw = function(self)
if (isVisible) then
if (isVisible)then
if(self.parent~=nil)then
local x, y = self:getAnchorPosition()
local w,h = self:getSize()
local wP,hP = self.parent:getSize()
if(x+w<1)or(x>wP)or(y+h<1)or(y>hP)then return false end
if(self.transparentColor~=false)then
self.parent:drawForegroundBox(x, y, w, h, self.transparentColor)
end
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(x, y, w, h, self.bgColor)
end
if(self.bgSymbol~=false)then
self.parent:drawTextBox(x, y, w, h, self.bgSymbol)
if(self.bgSymbol~=" ")then
self.parent:drawForegroundBox(x, y, w, h, self.bgSymbolColor)
end
end
if(shadow)then
self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor)
self.parent:drawBackgroundBox(x+w, y+1, 1, h, shadowColor)
self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor)
self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor)
end
if(borderLeft)then
if(borderColors["left"]~=false)then
self.parent:drawTextBox(x-1, y, 1, h, "\149")
self.parent:drawForegroundBox(x-1, y, 1, h, borderColor)
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y, 1, h, self.bgColor) end
self.parent:drawBackgroundBox(x-1, y, 1, h, borderColors["left"])
self.parent:drawForegroundBox(x-1, y, 1, h, self.parent.bgColor)
end
if(borderLeft)and(borderTop)then
if(borderColors["left"]~=false)and(borderColors["top"]~=false)then
self.parent:drawTextBox(x-1, y-1, 1, 1, "\151")
self.parent:drawForegroundBox(x-1, y-1, 1, 1, borderColor)
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor) end
self.parent:drawBackgroundBox(x-1, y-1, 1, 1, borderColors["left"])
self.parent:drawForegroundBox(x-1, y-1, 1, 1, self.parent.bgColor)
end
if(borderTop)then
if(borderColors["top"]~=false)then
self.parent:drawTextBox(x, y-1, w, 1, "\131")
self.parent:drawForegroundBox(x, y-1, w, 1, borderColor)
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x, y-1, w, 1, self.bgColor) end
self.parent:drawBackgroundBox(x, y-1, w, 1, borderColors["top"])
self.parent:drawForegroundBox(x, y-1, w, 1, self.parent.bgColor)
end
if(borderTop)and(borderRight)then
self.parent:drawTextBox(x+w, y-1, 1, 1, "\149")
self.parent:drawForegroundBox(x+w, y-1, 1, 1, borderColor)
if(borderColors["top"]~=false)and(borderColors["right"]~=false)then
self.parent:drawTextBox(x+w, y-1, 1, 1, "\148")
self.parent:drawForegroundBox(x+w, y-1, 1, 1, borderColors["right"])
end
if(borderRight)then
if(borderColors["right"]~=false)then
self.parent:drawTextBox(x+w, y, 1, h, "\149")
self.parent:drawForegroundBox(x+w, y, 1, h, borderColor)
self.parent:drawForegroundBox(x+w, y, 1, h, borderColors["right"])
end
if(borderRight)and(borderBottom)then
if(borderColors["right"]~=false)and(borderColors["bottom"]~=false)then
self.parent:drawTextBox(x+w, y+h, 1, 1, "\129")
self.parent:drawForegroundBox(x+w, y+h, 1, 1, borderColor)
self.parent:drawForegroundBox(x+w, y+h, 1, 1, borderColors["right"])
end
if(borderBottom)then
if(borderColors["bottom"]~=false)then
self.parent:drawTextBox(x, y+h, w, 1, "\131")
self.parent:drawForegroundBox(x, y+h, w, 1, borderColor)
self.parent:drawForegroundBox(x, y+h, w, 1, borderColors["bottom"])
end
if(borderBottom)and(borderLeft)then
self.parent:drawTextBox(x-1, y+h, 1, 1, "\131")
self.parent:drawForegroundBox(x-1, y+h, 1, 1, borderColor)
if(borderColors["bottom"]~=false)and(borderColors["left"]~=false)then
self.parent:drawTextBox(x-1, y+h, 1, 1, "\130")
self.parent:drawForegroundBox(x-1, y+h, 1, 1, borderColors["left"])
end
end
draw = false
return true
end
return false
@@ -487,7 +525,7 @@ return function(name)
setAnchor = function(self, newAnchor)
anchor = newAnchor
visualsChanged = true
self:updateDraw()
return self
end;
@@ -505,59 +543,88 @@ return function(name)
end;
onClick = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_click", v)
self:registerEvent("monitor_touch", v)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_click", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
end
end
return self
end;
onClickUp = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_up", v)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_up", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
end
end
return self
end;
onScroll = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_scroll", v)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_scroll", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_scroll", self)
activeEvents["mouse_scroll"] = true
end
end
return self
end;
onDrag = function(self, ...)
if(isEnabled)then
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_drag", v)
end
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_drag", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_drag", self)
activeEvents["mouse_drag"] = true
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
self.parent:addEvent("mouse_up", self)
activeEvents["mouse_up"] = true
end
return self
end;
onEvent = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("custom_event_handler", v)
self:registerEvent("other_event", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("other_event", self)
activeEvents["other_event"] = true
end
return self
end;
onKey = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("key", v)
self:registerEvent("char", v)
if(isEnabled)then
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("key", v)
self:registerEvent("char", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("key", self)
self.parent:addEvent("char", self)
activeEvents["key"] = true
activeEvents["char"] = true
end
end
return self
@@ -582,30 +649,15 @@ return function(name)
end;
onKeyUp = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("key_up", v)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("key_up", v)
end
end
end
return self
end;
onBackgroundKey = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("background_key", v)
self:registerEvent("background_char", v)
if(self.parent~=nil)then
self.parent:addEvent("key_up", self)
activeEvents["key_up"] = true
end
end
return self
end;
onBackgroundKeyUp = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("background_key_up", v)
end
end
return self
end;
@@ -622,6 +674,10 @@ return function(name)
self:registerEvent("get_focus", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
end
return self
end;
@@ -631,6 +687,10 @@ return function(name)
self:registerEvent("lose_focus", v)
end
end
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
activeEvents["mouse_click"] = true
end
return self
end;
@@ -646,79 +706,122 @@ return function(name)
return eventSystem:sendEvent(event, self, ...)
end;
mouseHandler = function(self, event, button, x, y)
if(isEnabled)and(isVisible)then
isCoordsInObject = function(self, x, y)
if(isVisible)and(isEnabled)then
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
local w, h = self:getSize()
local yOff = false
if(objY-1 == y)and(self:getBorder("top"))then
y = y+1
yOff = true
end
if(event=="mouse_up")then
isDragging = false
end
if(isDragging)and(event=="mouse_drag")then
local xO, yO, parentX, parentY = 0, 0, 1, 1
if (self.parent ~= nil) then
xO, yO = self.parent:getOffsetInternal()
xO = xO < 0 and math.abs(xO) or -xO
yO = yO < 0 and math.abs(yO) or -yO
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end
local dX, dY = x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO
local val = eventSystem:sendEvent(event, self, event, button, dX, dY, dragStartX, dragStartY, x, y)
end
local w, h = self:getSize()
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) then
if(event=="mouse_click")then
isDragging = true
dragStartX, dragStartY = x, y
dragXOffset, dragYOffset = objX - x, objY - y
end
if(event~="mouse_drag")then
if(event~="mouse_up")then
if (self.parent ~= nil) then
self.parent:setFocusedObject(self)
end
end
local val = eventSystem:sendEvent(event, self, event, button, x, y)
if(val~=nil)then return val end
end
return true
end
end
return false
end;
end,
keyHandler = function(self, event, key)
if(isEnabled)then
if (self:isFocused()) then
local val = eventSystem:sendEvent(event, self, event, key)
if(val~=nil)then return val end
return true
mouseHandler = function(self, button, x, y, isMon)
if(self:isCoordsInObject(x, y))then
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x, y, isMon)
if(val==false)then return false end
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
isDragging = true
dragStartX, dragStartY = x, y
return true
end
return false
end;
end,
backgroundKeyHandler = function(self, event, key)
if(isEnabled)then
local val = eventSystem:sendEvent("background_"..event, self, event, key)
mouseUpHandler = function(self, button, x, y)
isDragging = false
if(self:isCoordsInObject(x, y))then
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x, y)
if(val==false)then return false end
return true
end
return false
end,
dragHandler = function(self, button, x, y)
if(isDragging)then
local xO, yO, parentX, parentY = 0, 0, 1, 1
if (self.parent ~= nil) then
xO, yO = self.parent:getOffsetInternal()
xO = xO < 0 and math.abs(xO) or -xO
yO = yO < 0 and math.abs(yO) or -yO
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end
local dX, dY = x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO
local val = eventSystem:sendEvent("mouse_drag", self, button, dX, dY, dragStartX-x, dragStartY-y, x, y)
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
dragStartX, dragStartY = x, y
if(val~=nil)then return val end
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
return true
end
return true
if(self:isCoordsInObject(x, y))then
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
dragStartX, dragStartY = x, y
dragXOffset, dragYOffset = objX - x, objY - y
end
return false
end,
scrollHandler = function(self, dir, x, y)
if(self:isCoordsInObject(x, y))then
local val = eventSystem:sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y)
if(val==false)then return false end
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
return true
end
return false
end,
keyHandler = function(self, key, isHolding)
if(isEnabled)and(isVisible)then
if (self:isFocused()) then
local val = eventSystem:sendEvent("key", self, "key", key, isHolding)
if(val==false)then return false end
return true
end
end
return false
end;
keyUpHandler = function(self, key)
if(isEnabled)and(isVisible)then
if (self:isFocused()) then
local val = eventSystem:sendEvent("key_up", self, "key_up", key)
if(val==false)then return false end
return true
end
end
return false
end;
charHandler = function(self, char)
if(isEnabled)and(isVisible)then
if (self:isFocused()) then
local val = eventSystem:sendEvent("char", self, "char", char)
if(val==false)then return false end
return true
end
end
return false
end,
valueChangedHandler = function(self)
eventSystem:sendEvent("value_changed", self)
eventSystem:sendEvent("value_changed", self, value)
end;
eventHandler = function(self, event, p1, p2, p3, p4)
eventSystem:sendEvent("custom_event_handler", self, event, p1, p2, p3, p4)
local val = eventSystem:sendEvent("other_event", self, event, p1, p2, p3, p4)
if(val~=nil)then return val end
return true
end;
getFocusHandler = function(self)
@@ -728,11 +831,25 @@ return function(name)
end;
loseFocusHandler = function(self)
isDragging = false
local val = eventSystem:sendEvent("lose_focus", self)
if(val~=nil)then return val end
return true
end;
init = function(self)
if(self.parent~=nil)then
for k,v in pairs(activeEvents)do
if(v)then
self.parent:addEvent(k, self)
end
end
end
if not(initialized)then
initialized = true
return true
end
end
}

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,
@@ -157,11 +163,15 @@ return function(drawTerm)
end
end;
writeText = function(x, y, text, bgCol, fgCol)
bgCol = bgCol or terminal.getBackgroundColor()
fgCol = fgCol or terminal.getTextColor()
setText(x, y, text)
setBG(x, y, rep(tHex[bgCol], text:len()))
setFG(x, y, rep(tHex[fgCol], text:len()))
if(text~=nil)then
setText(x, y, text)
if(bgCol~=nil)and(bgCol~=false)then
setBG(x, y, rep(tHex[bgCol], text:len()))
end
if(fgCol~=nil)and(fgCol~=false)then
setFG(x, y, rep(tHex[fgCol], text:len()))
end
end
end;
update = function()

View File

@@ -0,0 +1,20 @@
local logDir = ""
local logFileName = "basaltLog.txt"
local defaultLogType = "Debug"
fs.delete(logDir~="" and logDir.."/"..logFileName or logFileName)
local mt = {
__call = function(_,text, typ)
if(text==nil)then return end
local dirStr = logDir~="" and logDir.."/"..logFileName or logFileName
local handle = fs.open(dirStr, fs.exists(dirStr) and "a" or "w")
handle.writeLine("[Basalt]["..(typ and typ or defaultLogType).."]: "..tostring(text))
handle.close()
end,
}
return setmetatable({}, mt)
--Work in progress

View File

@@ -3,12 +3,12 @@ local process = {}
local processId = 0
function process:new(path, window, ...)
local args = table.pack(...)
local args = {...}
local newP = setmetatable({ path = path }, { __index = self })
newP.window = window
newP.processId = processId
newP.coroutine = coroutine.create(function()
os.run({ }, path, table.unpack(args))
shell.execute(path, table.unpack(args))
end)
processes[processId] = newP
processId = processId + 1
@@ -17,12 +17,16 @@ end
function process:resume(event, ...)
term.redirect(self.window)
if(self.filter~=nil)then
if(event~=self.filter)then return end
self.filter=nil
end
local ok, result = coroutine.resume(self.coroutine, event, ...)
self.window = term.current()
if ok then
self.filter = result
else
basalt.debug(result)
error(result)
end
end

View File

@@ -48,6 +48,16 @@ rpairs = function(t)
end, t, #t + 1
end,
tableCount = function(t)
local n = 0
if(t~=nil)then
for k,v in pairs(t)do
n = n + 1
end
end
return n
end,
splitString = splitString,
createText = function(str, width)

View File

@@ -2,11 +2,13 @@ local basaltEvent = require("basaltEvent")()
local Frame = require("Frame")
local theme = require("theme")
local utils = require("utils")
local log = require("basaltLogs")
local uuid = utils.uuid
local createText = utils.createText
local baseTerm = term.current()
local version = 5
local version = "1.6.0"
local debugger = true
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
@@ -14,12 +16,16 @@ local projectDirectory = fs.getDir(table.pack(...)[2] or "")
local activeKey, frames, monFrames, variables, schedules = {}, {}, {}, {}, {}
local mainFrame, activeFrame, focusedObject, updaterActive
local basalt = {}
if not term.isColor or not term.isColor() then
error('Basalt requires an advanced (golden) computer to run.', 0)
end
local function stop()
updaterActive = false
updaterActive = false
baseTerm.clear()
baseTerm.setCursorPos(1, 1)
end
local setVariable = function(name, var)
@@ -72,6 +78,7 @@ local bInstance = {
end,
setMonitorFrame = function(name, frame)
if(mainFrame == frame)then mainFrame = nil end
monFrames[name] = frame
end,
@@ -92,34 +99,19 @@ local basaltError = function(errMsg)
baseTerm.setBackgroundColor(colors.black)
baseTerm.setTextColor(colors.red)
local w,h = baseTerm.getSize()
local splitString = function(str, sep)
if sep == nil then
sep = "%s"
end
local t={}
for v in string.gmatch(str, "([^"..sep.."]+)") do
table.insert(t, v)
end
return t
end
local words = splitString(errMsg, " ")
local line = "Basalt error: "
local yPos = 1
for n=1,#words do
baseTerm.setCursorPos(1,yPos)
if(#line+#words[n]<w)then
line = line.." "..words[n]
else
baseTerm.write(line)
line = words[n]
yPos = yPos + 1
end
if(n==#words)then
baseTerm.write(line)
end
if(basalt.logging)then
log(errMsg, "Error")
end
local text = createText("Basalt error: "..errMsg, w)
local yPos = 1
for k,v in pairs(text)do
baseTerm.setCursorPos(1,yPos)
baseTerm.write(v)
yPos = yPos + 1
end
baseTerm.setCursorPos(1,yPos+1)
updaterActive = false
end
local function handleSchedules(event, p1, p2, p3, p4)
@@ -144,15 +136,14 @@ local function handleSchedules(event, p1, p2, p3, p4)
end
local function drawFrames()
if(updaterActive)then
if(mainFrame~=nil)then
mainFrame:draw()
mainFrame:drawUpdate()
end
for _,v in pairs(monFrames)do
v:draw()
v:drawUpdate()
end
if(updaterActive==false)then return end
if(mainFrame~=nil)then
mainFrame:draw()
mainFrame:updateTerm()
end
for _,v in pairs(monFrames)do
v:draw()
v:updateTerm()
end
end
@@ -160,51 +151,63 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end
if(mainFrame~=nil)then
if (event == "mouse_click") then
mainFrame:mouseHandler(event, p1, p2, p3, p4)
mainFrame:mouseHandler(p1, p2, p3, false)
activeFrame = mainFrame
elseif (event == "mouse_drag") then
mainFrame:mouseHandler(event, p1, p2, p3, p4)
mainFrame:dragHandler(p1, p2, p3, p4)
activeFrame = mainFrame
elseif (event == "mouse_up") then
mainFrame:mouseHandler(event, p1, p2, p3, p4)
mainFrame:mouseUpHandler(p1, p2, p3, p4)
activeFrame = mainFrame
elseif (event == "mouse_scroll") then
mainFrame:mouseHandler(event, p1, p2, p3, p4)
mainFrame:scrollHandler(p1, p2, p3, p4)
activeFrame = mainFrame
elseif (event == "monitor_touch") then
if(monFrames[p1]~=nil)then
monFrames[p1]:mouseHandler(event, p1, p2, p3, p4)
activeFrame = monFrames[p1]
end
end
end
if(event == "monitor_touch") then
if(monFrames[p1]~=nil)then
monFrames[p1]:mouseHandler(1, p2, p3, true)
activeFrame = monFrames[p1]
end
end
if(event == "key") or (event == "char") then
if(event == "char")then
if(activeFrame~=nil)then
activeFrame:keyHandler(event, p1)
activeFrame:backgroundKeyHandler(event, p1)
activeFrame:charHandler(p1)
end
end
if(event == "key")then
activeKey[p1] = true
end
if(event == "key_up")then
if(activeFrame~=nil)then
activeFrame:keyUpHandler(p1)
end
activeKey[p1] = false
end
for _, v in pairs(frames) do
v:eventHandler(event, p1, p2, p3, p4)
if(event == "key")then
if(activeFrame~=nil)then
activeFrame:keyHandler(p1, p2)
end
activeKey[p1] = true
end
if(event == "terminate")then
if(activeFrame~=nil)then
activeFrame:eventHandler(event)
if(updaterActive==false)then return end
end
end
if(event~="mouse_click")and(event~="mouse_up")and(event~="mouse_scroll")and(event~="mouse_drag")and(event~="key")and(event~="key_up")and(event~="char")and(event~="terminate")then
for k, v in pairs(frames) do
v:eventHandler(event, p1, p2, p3, p4)
end
end
handleSchedules(event, p1, p2, p3, p4)
drawFrames()
end
local basalt = {}
basalt = {
logging = false,
setTheme = setTheme,
getTheme = getTheme,
drawFrames = drawFrames,
getVersion = function()
return version
end,
@@ -216,14 +219,29 @@ basalt = {
baseTerm = _baseTerm
end,
log = function(...)
log(...)
end,
autoUpdate = function(isActive)
local pCall = pcall
updaterActive = isActive
if(isActive==nil)then updaterActive = true end
drawFrames()
while updaterActive do
local event, p1, p2, p3, p4 = os.pullEventRaw()
local ok, err = pCall(basaltUpdateEvent, event, p1, p2, p3, p4)
local function f()
drawFrames()
while updaterActive do
basaltUpdateEvent(os.pullEventRaw())
end
end
local ok, err = xpcall(f, debug.traceback)
if not(ok)then
basaltError(err)
return
end
end,
update = function(event, p1, p2, p3, p4)
if (event ~= nil) then
local ok, err = xpcall(basaltUpdateEvent, debug.traceback, event, p1, p2, p3, p4)
if not(ok)then
basaltError(err)
return
@@ -231,13 +249,8 @@ basalt = {
end
end,
update = function(event, p1, p2, p3, p4)
if (event ~= nil) then
basaltUpdateEvent(event, p1, p2, p3, p4)
end
end,
stop = stop,
stopUpdate = stop,
isKeyDown = function(key)
if(activeKey[key]==nil)then return false end
@@ -293,6 +306,7 @@ basalt = {
end
end
local newFrame = Frame(name,nil,nil,bInstance)
newFrame:init()
table.insert(frames, newFrame)
if(mainFrame==nil)and(newFrame:getName()~="basaltDebuggingFrame")then
newFrame:show()
@@ -310,6 +324,7 @@ basalt = {
debug = function(...)
local args = { ... }
if(mainFrame==nil)then print(...) return end
if (mainFrame.name ~= "basaltDebuggingFrame") then
if (mainFrame ~= basalt.debugFrame) then
basalt.debugLabel:setParent(mainFrame)
@@ -336,7 +351,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

View File

@@ -1,8 +1,7 @@
local xmlValue = require("utils").getValueFromXML
local basaltEvent = require("basaltEvent")
local floor = math.floor
local floor,sin,cos,pi = math.floor,math.sin,math.cos,math.pi
local lerp = function(s, e, pct)
return s + (e - s) * pct
@@ -12,8 +11,8 @@ local linear = function (t)
return t
end
local flip = function (x)
return 1 - x
local flip = function (t)
return 1 - t
end
local easeIn = function (t)
@@ -28,6 +27,18 @@ local easeInOut = function(t)
return lerp(easeIn(t), easeOut(t), t)
end
local easeOutSine = function(t)
return sin((t * pi) / 2);
end
local easeInSine = function(t)
return flip(cos((t * pi) / 2))
end
local easeInOutSine = function(t)
return -(cos(pi * x) - 1) / 2
end
local lerp = {
linear = linear,
lerp = lerp,
@@ -35,8 +46,13 @@ local lerp = {
easeIn=easeIn,
easeOut=easeOut,
easeInOut=easeInOut,
easeOutSine = easeOutSine,
easeInSine = easeInSine,
easeInOutSine = easeInOutSine,
}
local activeAnimations = {}
return function(name)
local object = {}
local objectType = "Animation"
@@ -117,16 +133,36 @@ return function(name)
end
local function predefinedLerp(v1,v2,d,t,get,set)
local function predefinedLerp(v1,v2,d,t,get,set,typ,self)
local obj = _OBJ
local x,y
local name = ""
if(obj.parent~=nil)then name = obj.parent:getName() end
name = name..obj:getName()
addAnimationPart(t+0.05, function()
x,y = get(_OBJ)
if(typ~=nil)then
if(activeAnimations[typ]==nil)then activeAnimations[typ] = {} end
if(activeAnimations[typ][name]~=nil)then
if(activeAnimations[typ][name]~=self)then
activeAnimations[typ][name]:cancel()
end
end
activeAnimations[typ][name] = self
end
x,y = get(obj)
end)
for n=0.05,d,0.05 do
for n=0.05,d+0.01,0.05 do
addAnimationPart(t+n, function()
local _x = math.floor(lerp.lerp(x, v1, lerp[mode](n / d))+0.5)
local _y = math.floor(lerp.lerp(y, v2, lerp[mode](n / d))+0.5)
set(_OBJ, _x,_y)
set(obj, _x,_y)
if(typ~=nil)then
if(n>=d-0.01)then
if(activeAnimations[typ][name]==self)then
activeAnimations[typ][name] = nil
end
end
end
end)
end
end;
@@ -274,19 +310,19 @@ return function(name)
move = function(self, x, y, duration, timer, obj)
_OBJ = obj or _OBJ
predefinedLerp(x,y,duration,timer or 0,_OBJ.getPosition,_OBJ.setPosition)
predefinedLerp(x,y,duration,timer or 0,_OBJ.getPosition,_OBJ.setPosition, "position", self)
return self
end,
offset = function(self, x, y, duration, timer, obj)
_OBJ = obj or _OBJ
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset)
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset, "offset", self)
return self
end,
size = function(self, w, h, duration, timer, obj)
_OBJ = obj or _OBJ
predefinedLerp(w,h,duration,timer or 0,_OBJ.getSize,_OBJ.setSize)
predefinedLerp(w,h,duration,timer or 0,_OBJ.getSize,_OBJ.setSize, "size", self)
return self
end,
@@ -363,6 +399,7 @@ return function(name)
animationDoneHandler = function(self)
eventSystem:sendEvent("animation_done", self)
self.parent:removeEvent("other_event", self)
if(autoDestroy)then
self.parent:removeObject(self)
self = nil
@@ -393,11 +430,12 @@ return function(name)
if (animations[index].t > 0) then
timerObj = os.startTimer(animations[index].t)
else
onPlay()
onPlay(self)
end
else
self:animationDoneHandler()
end
self.parent:addEvent("other_event", self)
return self
end;
@@ -407,6 +445,7 @@ return function(name)
infinitePlay = false
end
animationActive = false
self.parent:removeEvent("other_event", self)
return self
end;

View File

@@ -1,6 +1,7 @@
local Object = require("Object")
local utils = require("utils")
local xmlValue = utils.getValueFromXML
local tHex = require("tHex")
return function(name)
-- Button
@@ -24,14 +25,19 @@ return function(name)
end;
setHorizontalAlign = function(self, pos)
textHorizontalAlign = pos
self:updateDraw()
return self
end;
setVerticalAlign = function(self, pos)
textVerticalAlign = pos
self:updateDraw()
return self
end;
setText = function(self, text)
base:setValue(text)
self:updateDraw()
return self
end;
@@ -50,20 +56,15 @@ return function(name)
local w,h = self:getSize()
local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
self.parent:drawTextBox(obx, oby, w, h, " ")
end
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end
for n = 1, h do
if (n == verticalAlign) then
self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign))
self.parent:setFG(obx, oby + (n - 1), utils.getTextHorizontalAlign(tHex[self.fgColor]:rep(self:getValue():len()), w, textHorizontalAlign))
end
end
end
self:setVisualChanged(false)
end
end;
end,
}
return setmetatable(object, base)

View File

@@ -12,31 +12,38 @@ return function(name)
base.width = 1
base.height = 1
local object = {
symbol = "\42",
local symbol = "\42"
init = function(self)
self.bgColor = self.parent:getTheme("CheckboxBG")
self.fgColor = self.parent:getTheme("CheckboxText")
end,
local object = {
getType = function(self)
return objectType
end;
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
setSymbol = function(self, sym)
symbol = sym
self:updateDraw()
return self
end,
mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, button, x, y)) then
if(button == 1)then
if (self:getValue() ~= true) and (self:getValue() ~= false) then
self:setValue(false)
else
self:setValue(not self:getValue())
end
end
self:updateDraw()
return true
end
end
return false
end;
end,
touchHandler = function(self, x, y)
return self:mouseHandler(1, x, y)
end,
setValuesByXMLData = function(self, data)
base.setValuesByXMLData(self, data)
@@ -54,17 +61,22 @@ return function(name)
for n = 1, h do
if (n == verticalAlign) then
if (self:getValue() == true) then
self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self.symbol, w, "center"), self.bgColor, self.fgColor)
self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(symbol, w, "center"), self.bgColor, self.fgColor)
else
self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(" ", w, "center"), self.bgColor, self.fgColor)
end
end
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
base.init(self)
self.bgColor = self.parent:getTheme("CheckboxBG")
self.fgColor = self.parent:getTheme("CheckboxText")
self.parent:addEvent("mouse_click", self)
end,
}
return setmetatable(object, base)

View File

@@ -26,12 +26,6 @@ return function(name)
getType = function(self)
return objectType
end;
init = function(self)
self.bgColor = self.parent:getTheme("DropdownBG")
self.fgColor = self.parent:getTheme("DropdownText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end,
setValuesByXMLData = function(self, data)
base.setValuesByXMLData(self, data)
@@ -51,6 +45,7 @@ return function(name)
setOffset = function(self, yOff)
yOffset = yOff
self:updateDraw()
return self
end;
@@ -60,6 +55,7 @@ return function(name)
addItem = function(self, text, bgCol, fgCol, ...)
table.insert(list, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self
end;
@@ -69,6 +65,7 @@ return function(name)
removeItem = function(self, index)
table.remove(list, index)
self:updateDraw()
return self
end;
@@ -88,6 +85,7 @@ return function(name)
clear = function(self)
list = {}
self:setValue({})
self:updateDraw()
return self
end;
@@ -98,11 +96,13 @@ return function(name)
editItem = function(self, index, text, bgCol, fgCol, ...)
table.remove(list, index)
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self
end;
selectItem = function(self, index)
self:setValue(list[index] or {})
self:updateDraw()
return self
end;
@@ -110,55 +110,90 @@ return function(name)
itemSelectedBG = bgCol or self.bgColor
itemSelectedFG = fgCol or self.fgColor
selectionColorActive = active
self:updateDraw()
return self
end;
setDropdownSize = function(self, width, height)
dropdownW, dropdownH = width, height
self:updateDraw()
return self
end;
end,
mouseHandler = function(self, event, button, x, y)
mouseHandler = function(self, button, x, y)
if (isOpened) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
if(button==1)then
if (#list > 0) then
for n = 1, dropdownH do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then
self:setValue(list[n + yOffset])
self:updateDraw()
local val = self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", dir, x, y)
if(val==false)then return val end
return true
end
end
end
end
end
end
if (base.mouseHandler(self, button, x, y)) then
isOpened = (not isOpened)
self:updateDraw()
return true
else
if(isOpened)then
self:updateDraw()
isOpened = false
end
return false
end
end,
if (event == "mouse_scroll") then
yOffset = yOffset + button
if (yOffset < 0) then
yOffset = 0
end
if (button == 1) then
if (#list > dropdownH) then
if (yOffset > #list - dropdownH) then
yOffset = #list - dropdownH
mouseUpHandler = function(self, button, x, y)
if (isOpened) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if(button==1)then
if (#list > 0) then
for n = 1, dropdownH do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then
isOpened = false
self:updateDraw()
local val = self:getEventSystem():sendEvent("mouse_up", self, "mouse_up", dir, x, y)
if(val==false)then return val end
return true
end
end
else
yOffset = math.min(#list - 1, 0)
end
end
return true
end
self:setVisualChanged()
end
if (base.mouseHandler(self, event, button, x, y)) then
isOpened = true
else
isOpened = false
end,
scrollHandler = function(self, dir, x, y)
if (isOpened)and(self:isFocused()) then
yOffset = yOffset + dir
if (yOffset < 0) then
yOffset = 0
end
if (dir == 1) then
if (#list > dropdownH) then
if (yOffset > #list - dropdownH) then
yOffset = #list - dropdownH
end
else
yOffset = math.min(#list - 1, 0)
end
end
local val = self:getEventSystem():sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y)
if(val==false)then return val end
self:updateDraw()
return true
end
end;
end,
draw = function(self)
if (base.draw(self)) then
@@ -186,9 +221,20 @@ return function(name)
end
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("DropdownBG")
self.fgColor = self.parent:getTheme("DropdownText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_up", self)
self.parent:addEvent("mouse_scroll", self)
end
end,
}
return setmetatable(object, base)

View File

@@ -142,6 +142,7 @@ return function(name)
loadImage = function(self, path)
image = paintutils.loadImage(path)
imageGotShrinked = false
self:updateDraw()
return self
end;
@@ -149,6 +150,7 @@ return function(name)
shrink = function(self)
shrink()
imageGotShrinked = true
self:updateDraw()
return self
end;
@@ -192,9 +194,8 @@ return function(name)
end
end
end
self:setVisualChanged(false)
end
end;
end,
}
return setmetatable(object, base)

View File

@@ -1,5 +1,6 @@
local Object = require("Object")
local utils = require("utils")
local log = require("basaltLogs")
local xmlValue = utils.getValueFromXML
return function(name)
@@ -24,10 +25,6 @@ return function(name)
local internalValueChange = false
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("InputBG")
self.fgColor = self.parent:getTheme("InputFG")
end,
getType = function(self)
return objectType
end;
@@ -36,6 +33,7 @@ return function(name)
if (iType == "password") or (iType == "number") or (iType == "text") then
inputType = iType
end
self:updateDraw()
return self
end;
@@ -48,6 +46,7 @@ return function(name)
else
showingText = defaultText
end
self:updateDraw()
return self
end;
@@ -58,8 +57,14 @@ return function(name)
setValue = function(self, val)
base.setValue(self, tostring(val))
if not (internalValueChange) then
textX = tostring(val):len() + 1
if(self:isFocused())then
textX = tostring(val):len() + 1
wIndex = math.max(1, textX-self:getWidth()+1)
local obx, oby = self:getAnchorPosition()
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self.height/2), self.fgColor)
end
end
self:updateDraw()
return self
end;
@@ -70,6 +75,7 @@ return function(name)
setInputLimit = function(self, limit)
inputLimit = tonumber(limit) or inputLimit
self:updateDraw()
return self
end;
@@ -93,25 +99,28 @@ return function(name)
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
showingText = ""
if (self.parent ~= nil) then
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self.height/2), self.fgColor)
if(defaultText~="")then
self:updateDraw()
end
self.parent:setCursor(true, obx + textX - wIndex, oby+math.max(math.ceil(self:getHeight()/2-1, 1)), self.fgColor)
end
end;
loseFocusHandler = function(self)
base.loseFocusHandler(self)
if (self.parent ~= nil) then
self.parent:setCursor(false)
showingText = defaultText
if(defaultText~="")then
self:updateDraw()
end
self.parent:setCursor(false)
end
end;
keyHandler = function(self, event, key)
if (base.keyHandler(self, event, key)) then
keyHandler = function(self, key)
if (base.keyHandler(self, key)) then
local w,h = self:getSize()
internalValueChange = true
if (event == "key") then
if (key == keys.backspace) then
-- on backspace
local text = tostring(base.getValue())
@@ -167,29 +176,6 @@ return function(name)
wIndex = 1
end
end
end
if (event == "char") then
local text = base.getValue()
if (text:len() < inputLimit or inputLimit <= 0) then
if (inputType == "number") then
local cache = text
if (key == ".") or (tonumber(key) ~= nil) then
self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len()))
textX = textX + 1
end
if (tonumber(base.getValue()) == nil) then
self:setValue(cache)
end
else
self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len()))
textX = textX + 1
end
if (textX >= w + wIndex) then
wIndex = wIndex + 1
end
end
end
local obx, oby = self:getAnchorPosition()
local val = tostring(base.getValue())
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
@@ -198,21 +184,117 @@ return function(name)
cursorX = self.x + w - 1
end
if (self.parent ~= nil) then
self.parent:setCursor(true, obx + cursorX, oby+math.floor(h/2), self.fgColor)
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
end
internalValueChange = false
end
end;
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
if (event == "mouse_click") and (button == 1) then
end
return true
end
return false
end;
end,
charHandler = function(self, char)
if (base.charHandler(self, char)) then
internalValueChange = true
local w,h = self:getSize()
local text = base.getValue()
if (text:len() < inputLimit or inputLimit <= 0) then
if (inputType == "number") then
local cache = text
if (char == ".") or (tonumber(char) ~= nil) then
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
textX = textX + 1
end
if (tonumber(base.getValue()) == nil) then
self:setValue(cache)
end
else
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
textX = textX + 1
end
if (textX >= w + wIndex) then
wIndex = wIndex + 1
end
end
local obx, oby = self:getAnchorPosition()
local val = tostring(base.getValue())
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
local x = self:getX()
if (cursorX > x + w - 1) then
cursorX = x + w - 1
end
if (self.parent ~= nil) then
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
end
internalValueChange = false
self:updateDraw()
return true
end
return false
end,
mouseHandler = function(self, button, x, y)
if(base.mouseHandler(self, button, x, y))then
local ax, ay = self:getAnchorPosition()
local obx, oby = self:getAbsolutePosition(ax, ay)
local w, h = self:getSize()
textX = x - obx + wIndex
local text = base.getValue()
if (textX > text:len()) then
textX = text:len() + 1
end
if (textX < wIndex) then
wIndex = textX - 1
if (wIndex < 1) then
wIndex = 1
end
end
self.parent:setCursor(true, obx + textX-1, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
return true
end
end,
eventHandler = function(self, event, paste, p2, p3, p4)
if(base.eventHandler(self, event, paste, p2, p3, p4))then
if(event=="paste")then
if(self:isFocused())then
local text = base.getValue()
local w, h = self:getSize()
internalValueChange = true
if (inputType == "number") then
local cache = text
if (paste == ".") or (tonumber(paste) ~= nil) then
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
textX = textX + paste:len()
end
if (tonumber(base.getValue()) == nil) then
self:setValue(cache)
end
else
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
textX = textX + paste:len()
end
if (textX >= w + wIndex) then
wIndex = (textX+1)-w
end
local obx, oby = self:getAnchorPosition()
local val = tostring(base.getValue())
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
local x = self:getX()
if (cursorX > x + w - 1) then
cursorX = x + w - 1
end
if (self.parent ~= nil) then
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
end
self:updateDraw()
internalValueChange = false
end
end
end
end,
draw = function(self)
if (base.draw(self)) then
@@ -246,14 +328,27 @@ return function(name)
if (inputType == "password") and (val ~= "") then
text = string.rep("*", text:len())
end
text = text .. string.rep(" ", space)
text = text .. string.rep(self.bgSymbol, space)
self.parent:writeText(obx, oby + (n - 1), text, bCol, fCol)
end
end
if(self:isFocused())then
self.parent:setCursor(true, obx + textX - wIndex, oby+math.max(math.ceil(self:getHeight()/2-1, 1)), self.fgColor)
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("InputBG")
self.fgColor = self.parent:getTheme("InputText")
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("key", self)
self.parent:addEvent("char", self)
self.parent:addEvent("other_event", self)
end
end,
}
return setmetatable(object, base)

View File

@@ -33,27 +33,28 @@ return function(name)
if (autoSize) then
self.width = text:len()
end
if not(fgColChanged)then self.fgColor = self.parent:getForeground() or colors.white end
if not(bgColChanged)then self.bgColor = self.parent:getBackground() or colors.black end
self:updateDraw()
return self
end;
setBackground = function(self, col)
base.setBackground(self, col)
bgColChanged = true
self:updateDraw()
return self
end,
setForeground = function(self, col)
base.setForeground(self, col)
fgColChanged = true
self:updateDraw()
return self
end,
setTextAlign = function(self, hor, vert)
textHorizontalAlign = hor or textHorizontalAlign
textVerticalAlign = vert or textVerticalAlign
self:setVisualChanged()
self:updateDraw()
return self
end;
@@ -61,6 +62,7 @@ return function(name)
if(size>0)and(size<=4)then
fontsize = size-1 or 0
end
self:updateDraw()
return self
end;
@@ -77,10 +79,10 @@ return function(name)
return self
end,
setSize = function(self, width, height)
base.setSize(self, width, height)
setSize = function(self, width, height, rel)
base.setSize(self, width, height, rel)
autoSize = false
self:setVisualChanged()
self:updateDraw()
return self
end;
@@ -90,47 +92,43 @@ return function(name)
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
self.parent:drawTextBox(obx, oby, w, h, " ") end
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end
if(fontsize==0)then
if not(autoSize)then
local text = createText(self:getValue(), self:getWidth())
for k,v in pairs(text)do
self.parent:setText(obx, oby+k-1, v)
self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor)
end
else
for n = 1, h do
if (n == verticalAlign) then
self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign))
end
end
self.parent:writeText(obx, oby, self:getValue(), self.bgColor, self.fgColor)
end
else
local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.black)
local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.lightGray)
if(autoSize)then
self:setSize(#tData[1][1], #tData[1]-1)
end
for n = 1, h do
if (n == verticalAlign) then
local oX, oY = self.parent:getSize()
local cX, cY = #tData[1][1], #tData[1]
obx = obx or math.floor((oX - cX) / 2) + 1
oby = oby or math.floor((oY - cY) / 2) + 1
for i = 1, cY do
self.parent:setFG(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[2][i], w, textHorizontalAlign))
self.parent:setBG(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[3][i], w, textHorizontalAlign, tHex[self.bgColor or colors.black]))
self.parent:setText(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[1][i], w, textHorizontalAlign))
end
local oX, oY = self.parent:getSize()
local cX, cY = #tData[1][1], #tData[1]
obx = obx or math.floor((oX - cX) / 2) + 1
oby = oby or math.floor((oY - cY) / 2) + 1
for i = 1, cY do
self.parent:setFG(obx, oby + i - 2, tData[2][i])
self.parent:setBG(obx, oby + i - 2, tData[3][i])
self.parent:setText(obx, oby + i - 2, tData[1][i])
end
end
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("LabelBG")
self.fgColor = self.parent:getTheme("LabelText")
if(self.parent.bgColor==colors.black)and(self.fgColor==colors.black)then
self.fgColor = colors.lightGray
end
end
end
}

View File

@@ -18,12 +18,6 @@ return function(name)
local scrollable = true
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("ListBG")
self.fgColor = self.parent:getTheme("ListText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end,
getType = function(self)
return objectType
end;
@@ -33,11 +27,13 @@ return function(name)
if (#list == 1) then
self:setValue(list[1])
end
self:updateDraw()
return self
end;
setOffset = function(self, yOff)
yOffset = yOff
self:updateDraw()
return self
end;
@@ -47,6 +43,7 @@ return function(name)
removeItem = function(self, index)
table.remove(list, index)
self:updateDraw()
return self
end;
@@ -70,6 +67,7 @@ return function(name)
clear = function(self)
list = {}
self:setValue({})
self:updateDraw()
return self
end;
@@ -80,23 +78,28 @@ return function(name)
editItem = function(self, index, text, bgCol, fgCol, ...)
table.remove(list, index)
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self
end;
selectItem = function(self, index)
self:setValue(list[index] or {})
self:updateDraw()
return self
end;
setSelectedItem = function(self, bgCol, fgCol, active)
itemSelectedBG = bgCol or self.bgColor
itemSelectedFG = fgCol or self.fgColor
selectionColorActive = active
selectionColorActive = active~=nil and active or true
self:updateDraw()
return self
end;
setScrollable = function(self, scroll)
scrollable = scroll
if(scroll==nil)then scrollable = true end
self:updateDraw()
return self
end;
@@ -116,29 +119,15 @@ return function(name)
return self
end,
mouseHandler = function(self, event, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (obx <= x) and (obx + w > x) and (oby <= y) and (oby + h > y) and (self:isVisible()) then
if (((event == "mouse_click") or (event == "mouse_drag"))and(button==1))or(event=="monitor_touch") then
if (#list > 0) then
for n = 1, h do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + w > x) and (oby + n - 1 == y) then
self:setValue(list[n + yOffset])
self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n + yOffset])
end
end
end
end
end
if (event == "mouse_scroll") and (scrollable) then
yOffset = yOffset + button
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
if(scrollable)then
local w,h = self:getSize()
yOffset = yOffset + dir
if (yOffset < 0) then
yOffset = 0
end
if (button >= 1) then
if (dir >= 1) then
if (#list > h) then
if (yOffset > #list - h) then
yOffset = #list - h
@@ -150,11 +139,39 @@ return function(name)
yOffset = yOffset - 1
end
end
self:updateDraw()
end
self:setVisualChanged()
return true
end
end;
return false
end,
mouseHandler = function(self, button, x, y)
if(base.mouseHandler(self, button, x, y))then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (#list > 0) then
for n = 1, h do
if (list[n + yOffset] ~= nil) then
if (obx <= x) and (obx + w > x) and (oby + n - 1 == y) then
self:setValue(list[n + yOffset])
self:updateDraw()
end
end
end
end
return true
end
return false
end,
dragHandler = function(self, button, x, y)
return self:mouseHandler(button, x, y)
end,
touchHandler = function(self, x, y)
return self:mouseHandler(1, x, y)
end,
draw = function(self)
if (base.draw(self)) then
@@ -178,9 +195,18 @@ return function(name)
end
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("ListBG")
self.fgColor = self.parent:getTheme("ListText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("mouse_scroll", self)
end,
}
return setmetatable(object, base)

View File

@@ -40,13 +40,6 @@ return function(name)
end
object = {
init = function(self)
self.bgColor = self.parent:getTheme("MenubarBG")
self.fgColor = self.parent:getTheme("MenubarText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
end,
getType = function(self)
return objectType
end;
@@ -56,6 +49,7 @@ return function(name)
if (#list == 1) then
self:setValue(list[1])
end
self:updateDraw()
return self
end;
@@ -75,11 +69,13 @@ return function(name)
clear = function(self)
list = {}
self:setValue({})
self:updateDraw()
return self
end;
setSpace = function(self, _space)
space = _space or space
self:updateDraw()
return self
end;
@@ -93,6 +89,7 @@ return function(name)
if (itemOffset > mScroll) then
itemOffset = mScroll
end
self:updateDraw()
return self
end;
@@ -125,6 +122,7 @@ return function(name)
removeItem = function(self, index)
table.remove(list, index)
self:updateDraw()
return self
end;
@@ -139,11 +137,13 @@ return function(name)
editItem = function(self, index, text, bgCol, fgCol, ...)
table.remove(list, index)
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self
end;
selectItem = function(self, index)
self:setValue(list[index] or {})
self:updateDraw()
return self
end;
@@ -151,48 +151,49 @@ return function(name)
itemSelectedBG = bgCol or self.bgColor
itemSelectedFG = fgCol or self.fgColor
selectionColorActive = active
self:updateDraw()
return self
end;
mouseHandler = function(self, event, button, x, y)
if(base.mouseHandler(self, event, button, x, y))then
mouseHandler = function(self, button, x, y)
if(base.mouseHandler(self, button, x, y))then
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) and (self:isVisible()) then
if (self.parent ~= nil) then
self.parent:setFocusedObject(self)
end
if (event == "mouse_click") or (event == "monitor_touch") then
local xPos = 0
for n = 1, #list do
if (list[n] ~= nil) 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:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
end
xPos = xPos + list[n].text:len() + space * 2
local xPos = 0
for n = 1, #list do
if (list[n] ~= nil) 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:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
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
xPos = xPos + list[n].text:len() + space * 2
end
end
self:setVisualChanged(true)
return true
end
self:updateDraw()
return true
end
return false
end;
end,
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
if(scrollable)then
itemOffset = itemOffset + dir
if (itemOffset < 0) then
itemOffset = 0
end
local mScroll = maxScroll()
if (itemOffset > mScroll) then
itemOffset = mScroll
end
self:updateDraw()
end
return true
end
return false
end,
draw = function(self)
if (base.draw(self)) then
@@ -221,9 +222,19 @@ return function(name)
self.parent:setBG(obx, oby, textBGCol:sub(itemOffset+1, w+itemOffset))
self.parent:setFG(obx, oby, textFGCol:sub(itemOffset+1, w+itemOffset))
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("MenubarBG")
self.fgColor = self.parent:getTheme("MenubarText")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_scroll", self)
end,
}
return setmetatable(object, base)

View File

@@ -1,4 +1,5 @@
local Object = require("Object")
local log = require("basaltLogs")
return function(name)
-- Pane
@@ -6,26 +7,21 @@ return function(name)
local objectType = "Pane"
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("PaneBG")
self.fgColor = self.parent:getTheme("PaneBG")
end,
getType = function(self)
return objectType
end;
draw = function(self)
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor)
end
self:setVisualChanged(false)
end
end;
setBackground = function(self, col, sym, symC)
base.setBackground(self, col, sym, symC)
return self
end,
init = function(self)
if(base.init(self))then
self.bgColor = self.parent:getTheme("PaneBG")
self.fgColor = self.parent:getTheme("PaneBG")
end
end,
}
return setmetatable(object, base)

View File

@@ -2,6 +2,7 @@ local Object = require("Object")
local tHex = require("tHex")
local process = require("process")
local xmlValue = require("utils").getValueFromXML
local log = require("basaltLogs")
local sub = string.sub
@@ -12,7 +13,7 @@ return function(name, parent)
local object
local cachedPath
local function createBasaltWindow(x, y, width, height)
local function createBasaltWindow(x, y, width, height, self)
local xCursor, yCursor = 1, 1
local bgColor, fgColor = colors.black, colors.white
local cursorBlink = false
@@ -51,6 +52,7 @@ return function(name, parent)
cacheFG[n] = sub(cacheFG[n] == nil and emptyFG or cacheFG[n] .. emptyFG:sub(1, width - cacheFG[n]:len()), 1, width)
cacheBG[n] = sub(cacheBG[n] == nil and emptyBG or cacheBG[n] .. emptyBG:sub(1, width - cacheBG[n]:len()), 1, width)
end
base.updateDraw(base)
end
recreateWindowArray()
@@ -118,6 +120,7 @@ return function(name, parent)
cacheFG[yCursor] = sNewTextColor
cacheBG[yCursor] = sNewBackgroundColor
end
object:updateDraw()
end
xCursor = nEnd + 1
if (visible) then
@@ -133,6 +136,7 @@ return function(name, parent)
cacheT[_y] = sub(gText:sub(1, _x - 1) .. text .. gText:sub(_x + (text:len()), width), 1, width)
end
end
object:updateDraw()
end
local function setBG(_x, _y, colorStr)
@@ -142,6 +146,7 @@ return function(name, parent)
cacheBG[_y] = sub(gBG:sub(1, _x - 1) .. colorStr .. gBG:sub(_x + (colorStr:len()), width), 1, width)
end
end
object:updateDraw()
end
local function setFG(_x, _y, colorStr)
@@ -151,6 +156,7 @@ return function(name, parent)
cacheFG[_y] = sub(gFG:sub(1, _x - 1) .. colorStr .. gFG:sub(_x + (colorStr:len()), width), 1, width)
end
end
object:updateDraw()
end
local setTextColor = function(color)
@@ -417,10 +423,43 @@ return function(name, parent)
local paused = false
local queuedEvent = {}
local function updateCursor(self)
local xCur, yCur = pWindow.getCursorPos()
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
end
end
local function mouseEvent(self, event, p1, x, y)
if (curProcess == nil) then
return false
end
if not (curProcess:isDead()) then
if not (paused) then
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
curProcess:resume(event, p1, x-absX+1, y-absY+1)
updateCursor(self)
end
end
end
local function keyEvent(self, event, key, isHolding)
if (curProcess == nil) then
return false
end
if not (curProcess:isDead()) then
if not (paused) then
if (self.draw) then
curProcess:resume(event, key, isHolding)
updateCursor(self)
end
end
end
end
object = {
init = function(self)
self.bgColor = self.parent:getTheme("ProgramBG")
end,
getType = function(self)
return objectType
end;
@@ -461,7 +500,7 @@ return function(name, parent)
setSize = function(self, width, height, rel)
base.setSize(self, width, height, rel)
pWindow.basalt_resize(self:getSize())
pWindow.basalt_resize(self:getWidth(), self:getHeight())
return self
end;
@@ -484,6 +523,16 @@ return function(name, parent)
pWindow.basalt_setVisible(true)
curProcess:resume()
paused = false
if(self.parent~=nil)then
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_up", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("mouse_scroll", self)
self.parent:addEvent("key", self)
self.parent:addEvent("key_up", self)
self.parent:addEvent("char", self)
self.parent:addEvent("other_event", self)
end
return self
end;
@@ -498,6 +547,7 @@ return function(name, parent)
end
end
end
self.parent:removeEvents(self)
return self
end;
@@ -551,36 +601,61 @@ return function(name, parent)
return self
end;
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
if (curProcess == nil) then
return false
end
if not (curProcess:isDead()) then
if not (paused) then
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
curProcess:resume(event, button, x-absX+1, y-absY+1)
end
end
mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, button, x, y)) then
mouseEvent(self, "mouse_click", button, x, y)
return true
end
end;
return false
end,
keyHandler = function(self, event, key)
base.keyHandler(self, event, key)
if (self:isFocused()) then
if (curProcess == nil) then
return false
end
if not (curProcess:isDead()) then
if not (paused) then
if (self.draw) then
curProcess:resume(event, key)
end
end
end
mouseUpHandler = function(self, button, x, y)
if (base.mouseUpHandler(self, button, x, y)) then
mouseEvent(self, "mouse_up", button, x, y)
return true
end
end;
return false
end,
scrollHandler = function(self, dir, x, y)
if (base.scrollHandler(self, dir, x, y)) then
mouseEvent(self, "mouse_scroll", dir, x, y)
return true
end
return false
end,
dragHandler = function(self, button, x, y)
if (base.dragHandler(self, button, x, y)) then
mouseEvent(self, "mouse_drag", button, x, y)
return true
end
return false
end,
keyHandler = function(self, key, isHolding)
if(base.keyHandler(self, key, isHolding))then
keyEvent(self, "key", key, isHolding)
return true
end
return false
end,
keyUpHandler = function(self, key)
if(base.keyUpHandler(self, key))then
keyEvent(self, "key_up", key)
return true
end
return false
end,
charHandler = function(self, char)
if(base.charHandler(self, char))then
keyEvent(self, "char", char)
return true
end
return false
end,
getFocusHandler = function(self)
base.getFocusHandler(self)
@@ -600,7 +675,7 @@ return function(name, parent)
end
end
end
end;
end,
loseFocusHandler = function(self)
base.loseFocusHandler(self)
@@ -611,38 +686,54 @@ return function(name, parent)
end
end
end
end;
end,
eventHandler = function(self, event, p1, p2, p3, p4)
if (curProcess == nil) then
return
end
if not (curProcess:isDead()) then
if not (paused) then
if (event ~= "mouse_click") and (event ~= "monitor_touch") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then
curProcess:resume(event, p1, p2, p3, p4)
if(base.eventHandler(self, event, p1, p2, p3, p4))then
if (curProcess == nil) then
return
end
if(event=="dynamicValueEvent")then
local w, h = pWindow.getSize()
local pW, pH = self:getSize()
if(w~=pW)or(h~=pH)then
pWindow.basalt_resize(pW, pH)
if not (curProcess:isDead()) then
curProcess:resume("term_resize")
end
end
if (self:isFocused()) then
local obx, oby = self:getAnchorPosition()
local xCur, yCur = pWindow.getCursorPos()
if (self.parent ~= nil) then
local w,h = self:getSize()
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
pWindow.basalt_reposition(self:getAnchorPosition())
end
if not (curProcess:isDead()) then
if not (paused) then
if(event ~= "terminate") then
curProcess:resume(event, p1, p2, p3, p4)
end
if (self:isFocused()) then
local obx, oby = self:getAnchorPosition()
local xCur, yCur = pWindow.getCursorPos()
if (self.parent ~= nil) then
local w,h = self:getSize()
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
end
end
if (event == "terminate") then
log(self:isFocused())
curProcess:resume(event)
self.parent:setCursor(false)
return true
end
end
if (event == "terminate") and (self:isFocused()) then
self:stop()
end
end
else
if (event ~= "mouse_click") and (event ~= "monitor_touch") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then
else
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
end
end
return false
end
end;
end,
draw = function(self)
if (base.draw(self)) then
@@ -650,14 +741,14 @@ return function(name, parent)
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
pWindow.basalt_reposition(obx, oby)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
end
pWindow.basalt_update()
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("ProgramBG")
end,
}

View File

@@ -42,6 +42,7 @@ return function(name)
setDirection = function(self, dir)
direction = dir
self:updateDraw()
return self
end;
@@ -49,11 +50,13 @@ return function(name)
activeBarColor = color or activeBarColor
activeBarSymbol = symbol or activeBarSymbol
activeBarSymbolCol = symbolcolor or activeBarSymbolCol
self:updateDraw()
return self
end;
setBackgroundSymbol = function(self, symbol)
bgBarSymbol = symbol:sub(1, 1)
self:updateDraw()
return self
end;
@@ -65,6 +68,7 @@ return function(name)
self:progressDoneHandler()
end
end
self:updateDraw()
return self
end;
@@ -107,9 +111,8 @@ return function(name)
self.parent:drawTextBox(obx, oby, w / 100 * progress, h, activeBarSymbol)
end
end
self:setVisualChanged(false)
end
end;
end,
}

View File

@@ -20,16 +20,6 @@ return function(name)
local align = "left"
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("MenubarBG")
self.fgColor = self.parent:getTheme("MenubarFG")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
boxSelectedBG = self.parent:getTheme("MenubarBG")
boxSelectedFG = self.parent:getTheme("MenubarText")
end,
getType = function(self)
return objectType
end;
@@ -58,6 +48,7 @@ return function(name)
if (#list == 1) then
self:setValue(list[1])
end
self:updateDraw()
return self
end;
@@ -67,6 +58,7 @@ return function(name)
removeItem = function(self, index)
table.remove(list, index)
self:updateDraw()
return self
end;
@@ -86,6 +78,7 @@ return function(name)
clear = function(self)
list = {}
self:setValue({})
self:updateDraw()
return self
end;
@@ -96,16 +89,19 @@ return function(name)
editItem = function(self, index, text, x, y, bgCol, fgCol, ...)
table.remove(list, index)
table.insert(list, index, { x = x or 1, y = y or 1, text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
self:updateDraw()
return self
end;
selectItem = function(self, index)
self:setValue(list[index] or {})
self:updateDraw()
return self
end;
setActiveSymbol = function(self, sym)
symbol = sym:sub(1,1)
self:updateDraw()
return self
end,
@@ -115,23 +111,23 @@ return function(name)
boxSelectedBG = boxBG or boxSelectedBG
boxSelectedFG = boxFG or boxSelectedFG
selectionColorActive = active~=nil and active or true
self:updateDraw()
return self
end;
mouseHandler = function(self, event, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click")and(button==1))or(event=="monitor_touch") then
if (#list > 0) then
for _, value in pairs(list) do
if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 2 >= x) and (oby + value.y - 1 == y) then
self:setValue(value)
if (self.parent ~= nil) then
self.parent:setFocusedObject(self)
end
self:getEventSystem():sendEvent(event, self, event, button, x, y)
self:setVisualChanged()
return true
mouseHandler = function(self, button, x, y)
if (#list > 0) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
for _, value in pairs(list) do
if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 1 >= x) and (oby + value.y - 1 == y) then
self:setValue(value)
local val = self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", button, x, y)
if(val==false)then return val end
if(self.parent~=nil)then
self.parent:setFocusedObject(self)
end
self:updateDraw()
return true
end
end
end
@@ -139,24 +135,32 @@ return function(name)
end;
draw = function(self)
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
for _, value in pairs(list) do
if (value == self:getValue()) then
if (align == "left") then
self.parent:writeText(value.x + obx - 1, value.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG)
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG)
end
else
self.parent:drawBackgroundBox(value.x + obx - 1, value.y + oby - 1, 1, 1, boxNotSelectedBG or self.bgColor)
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, value.bgCol, value.fgCol)
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
for _, value in pairs(list) do
if (value == self:getValue()) then
if (align == "left") then
self.parent:writeText(value.x + obx - 1, value.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG)
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG)
end
else
self.parent:drawBackgroundBox(value.x + obx - 1, value.y + oby - 1, 1, 1, boxNotSelectedBG or self.bgColor)
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, value.bgCol, value.fgCol)
end
end
self:setVisualChanged(false)
return true
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("MenubarBG")
self.fgColor = self.parent:getTheme("MenubarFG")
itemSelectedBG = self.parent:getTheme("SelectionBG")
itemSelectedFG = self.parent:getTheme("SelectionText")
boxSelectedBG = self.parent:getTheme("MenubarBG")
boxSelectedFG = self.parent:getTheme("MenubarText")
self.parent:addEvent("mouse_click", self)
end,
}
return setmetatable(object, base)

View File

@@ -18,19 +18,37 @@ return function(name)
local index = 1
local symbolSize = 1
local function mouseEvent(self, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (barType == "horizontal") then
for _index = 0, w do
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
index = math.min(_index + 1, w - (symbolSize - 1))
self:setValue(maxValue / w * (index))
self:updateDraw()
end
end
end
if (barType == "vertical") then
for _index = 0, h do
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
index = math.min(_index + 1, h - (symbolSize - 1))
self:setValue(maxValue / h * (index))
self:updateDraw()
end
end
end
end
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("ScrollbarBG")
self.fgColor = self.parent:getTheme("ScrollbarText")
symbolColor = self.parent:getTheme("ScrollbarSymbolColor")
end,
getType = function(self)
return objectType
end;
setSymbol = function(self, _symbol)
symbol = _symbol:sub(1, 1)
self:setVisualChanged()
self:updateDraw()
return self
end;
@@ -53,6 +71,7 @@ return function(name)
local w,h = self:getSize()
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
self:updateDraw()
return self
end,
@@ -68,67 +87,62 @@ return function(name)
elseif (barType == "horizontal") then
self:setValue(index - 1 * (maxValue / (w - (symbolSize - 1))) - (maxValue / (w - (symbolSize - 1))))
end
self:setVisualChanged()
self:updateDraw()
return self
end;
setMaxValue = function(self, val)
maxValue = val
self:updateDraw()
return self
end;
setBackgroundSymbol = function(self, _bgSymbol)
bgSymbol = string.sub(_bgSymbol, 1, 1)
self:setVisualChanged()
self:updateDraw()
return self
end;
setSymbolColor = function(self, col)
symbolColor = col
self:setVisualChanged()
self:updateDraw()
return self
end;
setBarType = function(self, _typ)
barType = _typ:lower()
self:updateDraw()
return self
end;
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
if (barType == "horizontal") then
for _index = 0, w do
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
index = math.min(_index + 1, w - (symbolSize - 1))
self:setValue(maxValue / w * (index))
self:setVisualChanged()
end
end
end
if (barType == "vertical") then
for _index = 0, h do
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
index = math.min(_index + 1, h - (symbolSize - 1))
self:setValue(maxValue / h * (index))
self:setVisualChanged()
end
end
end
end
if (event == "mouse_scroll") then
index = index + button
if (index < 1) then
index = 1
end
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
end
mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, button, x, y)) then
mouseEvent(self, button, x, y)
return true
end
end;
return false
end,
dragHandler = function(self, button, x, y)
if (base.dragHandler(self, button, x, y)) then
mouseEvent(self, button, x, y)
return true
end
return false
end,
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
local w,h = self:getSize()
index = index + dir
if (index < 1) then
index = 1
end
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
self:updateDraw()
end
end,
draw = function(self)
if (base.draw(self)) then
@@ -155,9 +169,17 @@ return function(name)
end
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("ScrollbarBG")
self.fgColor = self.parent:getTheme("ScrollbarText")
symbolColor = self.parent:getTheme("ScrollbarSymbolColor")
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("mouse_scroll", self)
end,
}
return setmetatable(object, base)

View File

@@ -1,4 +1,5 @@
local Object = require("Object")
local log = require("basaltLogs")
local xmlValue = require("utils").getValueFromXML
return function(name)
@@ -17,19 +18,37 @@ return function(name)
local index = 1
local symbolSize = 1
local function mouseEvent(self, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (barType == "horizontal") then
for _index = 0, w do
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
index = math.min(_index + 1, w - (symbolSize - 1))
self:setValue(maxValue / w * (index))
self:updateDraw()
end
end
end
if (barType == "vertical") then
for _index = 0, h do
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
index = math.min(_index + 1, h - (symbolSize - 1))
self:setValue(maxValue / h * (index))
self:updateDraw()
end
end
end
end
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("SliderBG")
self.fgColor = self.parent:getTheme("SliderText")
symbolColor = self.parent:getTheme("SliderSymbolColor")
end,
getType = function(self)
return objectType
end;
setSymbol = function(self, _symbol)
symbol = _symbol:sub(1, 1)
self:setVisualChanged()
self:updateDraw()
return self
end;
@@ -52,6 +71,7 @@ return function(name)
local w,h = self:getSize()
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
self:updateDraw()
return self
end,
@@ -66,7 +86,7 @@ return function(name)
elseif (barType == "horizontal") then
self:setValue(index - 1 * (maxValue / (w - (symbolSize - 1))) - (maxValue / (w - (symbolSize - 1))))
end
self:setVisualChanged()
self:updateDraw()
return self
end;
@@ -77,56 +97,52 @@ return function(name)
setBackgroundSymbol = function(self, _bgSymbol)
bgSymbol = string.sub(_bgSymbol, 1, 1)
self:setVisualChanged()
self:updateDraw()
return self
end;
setSymbolColor = function(self, col)
symbolColor = col
self:setVisualChanged()
self:updateDraw()
return self
end;
setBarType = function(self, _typ)
barType = _typ:lower()
self:updateDraw()
return self
end;
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local w,h = self:getSize()
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
if (barType == "horizontal") then
for _index = 0, w do
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
index = math.min(_index + 1, w - (symbolSize - 1))
self:setValue(maxValue / w * (index))
self:setVisualChanged()
end
end
end
if (barType == "vertical") then
for _index = 0, h do
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
index = math.min(_index + 1, h - (symbolSize - 1))
self:setValue(maxValue / h * (index))
self:setVisualChanged()
end
end
end
end
if (event == "mouse_scroll") then
index = index + button
if (index < 1) then
index = 1
end
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
end
mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, button, x, y)) then
mouseEvent(self, button, x, y)
return true
end
end;
return false
end,
dragHandler = function(self, button, x, y)
if (base.dragHandler(self, button, x, y)) then
mouseEvent(self, button, x, y)
return true
end
return false
end,
scrollHandler = function(self, dir, x, y)
if(base.scrollHandler(self, dir, x, y))then
local w,h = self:getSize()
index = index + dir
if (index < 1) then
index = 1
end
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
self:updateDraw()
return true
end
return false
end,
draw = function(self)
if (base.draw(self)) then
@@ -141,7 +157,6 @@ return function(name)
if (barType == "vertical") then
for n = 0, h - 1 do
if (index == n + 1) then
for curIndexOffset = 0, math.min(symbolSize - 1, h) do
self.parent:writeText(obx, oby + n + curIndexOffset, symbol, symbolColor, symbolColor)
@@ -154,9 +169,17 @@ return function(name)
end
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("SliderBG")
self.fgColor = self.parent:getTheme("SliderText")
symbolColor = self.parent:getTheme("SliderSymbolColor")
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("mouse_scroll", self)
end,
}
return setmetatable(object, base)

View File

@@ -17,32 +17,25 @@ return function(name)
local activeBG = colors.green
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("SwitchBG")
self.fgColor = self.parent:getTheme("SwitchText")
bgSymbol = self.parent:getTheme("SwitchBGSymbol")
inactiveBG = self.parent:getTheme("SwitchInactive")
activeBG = self.parent:getTheme("SwitchActive")
end,
getType = function(self)
return objectType
end;
setSymbolColor = function(self, symbolColor)
bgSymbol = symbolColor
self:setVisualChanged()
self:updateDraw()
return self
end;
setActiveBackground = function(self, bgcol)
activeBG = bgcol
self:setVisualChanged()
self:updateDraw()
return self
end;
setInactiveBackground = function(self, bgcol)
inactiveBG = bgcol
self:setVisualChanged()
self:updateDraw()
return self
end;
@@ -54,12 +47,11 @@ return function(name)
end,
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, 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
self:setValue(not self:getValue())
self:updateDraw()
return true
end
end;
@@ -78,9 +70,17 @@ return function(name)
self.parent:drawBackgroundBox(obx+1, oby, 1, h, inactiveBG)
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("SwitchBG")
self.fgColor = self.parent:getTheme("SwitchText")
bgSymbol = self.parent:getTheme("SwitchBGSymbol")
inactiveBG = self.parent:getTheme("SwitchInactive")
activeBG = self.parent:getTheme("SwitchActive")
self.parent:addEvent("mouse_click", self)
end,
}
return setmetatable(object, base)

View File

@@ -1,7 +1,10 @@
local Object = require("Object")
local tHex = require("tHex")
local log = require("basaltLogs")
local xmlValue = require("utils").getValueFromXML
local rep = string.rep
return function(name)
local base = Object(name)
local objectType = "Textfield"
@@ -65,6 +68,7 @@ return function(name)
end
fgLines[l] = fgLine
bgLines[l] = bgLine
self:updateDraw()
end
local function updateAllColors(self)
@@ -74,10 +78,6 @@ return function(name)
end
local object = {
init = function(self)
self.bgColor = self.parent:getTheme("TextfieldBG")
self.fgColor = self.parent:getTheme("TextfieldText")
end,
getType = function(self)
return objectType
end;
@@ -144,6 +144,7 @@ return function(name)
editLine = function(self, index, text)
lines[index] = text or lines[index]
self:updateDraw()
return self
end;
@@ -152,6 +153,7 @@ return function(name)
bgLines = {""}
fgLines = {""}
hIndex, wIndex, textX, textY = 1, 1, 1, 1
self:updateDraw()
return self
end,
@@ -173,6 +175,7 @@ return function(name)
table.insert(fgLines, tHex[self.fgColor]:rep(text:len()))
end
end
self:updateDraw()
return self
end;
@@ -183,11 +186,13 @@ return function(name)
for k,v in pairs(tab)do
table.insert(keyWords[color], v)
end
self:updateDraw()
return self
end;
addRule = function(self, rule, fg, bg)
table.insert(rules, {rule, fg, bg})
self:updateDraw()
return self
end;
@@ -198,6 +203,7 @@ return function(name)
rules[k][3] = bg
end
end
self:updateDraw()
return self
end;
@@ -207,11 +213,13 @@ return function(name)
table.remove(rules, k)
end
end
self:updateDraw()
return self
end;
setKeywords = function(self, color, tab)
keyWords[color] = tab
self:updateDraw()
return self
end;
@@ -220,6 +228,7 @@ return function(name)
if (#lines <= 0) then
table.insert(lines, "")
end
self:updateDraw()
return self
end;
@@ -244,11 +253,10 @@ return function(name)
end
end;
keyHandler = function(self, event, key)
keyHandler = function(self, key)
if (base.keyHandler(self, event, key)) then
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
if (event == "key") then
if (key == keys.backspace) then
-- on backspace
if (lines[textY] == "") then
@@ -361,7 +369,14 @@ return function(name)
if (textX > lines[textY]:len() + 1) then
textX = lines[textY]:len() + 1
end
if (wIndex > 1) then
if (textX < wIndex) then
wIndex = textX - w + 1
if (wIndex < 1) then
wIndex = 1
end
end
end
if (textY >= hIndex + h) then
hIndex = hIndex + 1
end
@@ -411,19 +426,6 @@ return function(name)
wIndex = 1
end
end
end
if (event == "char") then
lines[textY] = lines[textY]:sub(1, textX - 1) .. key .. lines[textY]:sub(textX, lines[textY]:len())
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor] .. fgLines[textY]:sub(textX, fgLines[textY]:len())
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor] .. bgLines[textY]:sub(textX, bgLines[textY]:len())
textX = textX + 1
if (textX >= w + wIndex) then
wIndex = wIndex + 1
end
updateColors(self)
self:setValue("")
end
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
if (cursorX > self.x + w - 1) then
@@ -434,17 +436,46 @@ return function(name)
cursorX = 0
end
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
self:updateDraw()
return true
end
end;
end,
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
charHandler = function(self, char)
if(base.charHandler(self, char))then
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
lines[textY] = lines[textY]:sub(1, textX - 1) .. char .. lines[textY]:sub(textX, lines[textY]:len())
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor] .. fgLines[textY]:sub(textX, fgLines[textY]:len())
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor] .. bgLines[textY]:sub(textX, bgLines[textY]:len())
textX = textX + 1
if (textX >= w + wIndex) then
wIndex = wIndex + 1
end
updateColors(self)
self:setValue("")
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
if (cursorX > self.x + w - 1) then
cursorX = self.x + w - 1
end
local cursorY = (textY - hIndex < h and textY - hIndex or textY - hIndex - 1)
if (cursorX < 1) then
cursorX = 0
end
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
self:updateDraw()
return true
end
end,
dragHandler = function(self, button, x, y)
if (base.dragHandler(self, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
local w,h = self:getSize()
if (event == "mouse_click")or(event=="monitor_touch") then
if (lines[y - oby + hIndex] ~= nil) then
if (lines[y - oby + hIndex] ~= nil) then
if(anchx+w > anchx + x - (obx+1)+ wIndex)and(anchx < anchx + x - obx+ wIndex)then
textX = x - obx + wIndex
textY = y - oby + hIndex
if (textX > lines[textY]:len()) then
@@ -459,61 +490,89 @@ return function(name)
if (self.parent ~= nil) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end
self:updateDraw()
end
end
if (event == "mouse_drag") then
if (lines[y - oby + hIndex] ~= nil) then
textX = x - obx + wIndex
textY = y - oby + hIndex
if (textX > lines[textY]:len()) then
textX = lines[textY]:len() + 1
end
if (textX < wIndex) then
wIndex = textX - 1
if (wIndex < 1) then
wIndex = 1
end
end
if (self.parent ~= nil) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end
end
end
if (event == "mouse_scroll") then
hIndex = hIndex + button
if (hIndex > #lines - (h - 1)) then
hIndex = #lines - (h - 1)
end
if (hIndex < 1) then
hIndex = 1
end
if (self.parent ~= nil) then
if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
else
self.parent:setCursor(false)
end
end
end
self:setVisualChanged()
return true
end
end;
end,
scrollHandler = function(self, dir, x, y)
if (base.scrollHandler(self, dir, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
local w,h = self:getSize()
hIndex = hIndex + dir
if (hIndex > #lines - (h - 1)) then
hIndex = #lines - (h - 1)
end
if (hIndex < 1) then
hIndex = 1
end
if (self.parent ~= nil) then
if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
else
self.parent:setCursor(false)
end
end
self:updateDraw()
return true
end
end,
mouseHandler = function(self, button, x, y)
if (base.mouseHandler(self, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition()
if (lines[y - oby + hIndex] ~= nil) then
textX = x - obx + wIndex
textY = y - oby + hIndex
if (textX > lines[textY]:len()) then
textX = lines[textY]:len() + 1
end
if (textX < wIndex) then
wIndex = textX - 1
if (wIndex < 1) then
wIndex = 1
end
end
end
if (self.parent ~= nil) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end
return true
end
end,
eventHandler = function(self, event, paste, p2, p3, p4)
if(base.eventHandler(self, event, paste, p2, p3, p4))then
if(event=="paste")then
if(self:isFocused())then
local w, h = self:getSize()
lines[textY] = lines[textY]:sub(1, textX - 1) .. paste .. lines[textY]:sub(textX, lines[textY]:len())
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor]:rep(paste:len()) .. fgLines[textY]:sub(textX, fgLines[textY]:len())
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor]:rep(paste:len()) .. bgLines[textY]:sub(textX, bgLines[textY]:len())
textX = textX + paste:len()
if (textX >= w + wIndex) then
wIndex = (textX+1)-w
end
local anchx, anchy = self:getAnchorPosition()
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
updateColors(self)
self:updateDraw()
end
end
end
end,
draw = function(self)
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
local w,h = self:getSize()
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
end
if(self.fgColor~=false)then
self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor)
end
for n = 1, h do
local text = ""
local bg = ""
@@ -530,17 +589,31 @@ return function(name)
if (space < 0) then
space = 0
end
text = text .. string.rep(" ", space)
bg = bg .. string.rep(tHex[self.bgColor], space)
fg = fg .. string.rep(tHex[self.fgColor], space)
text = text .. rep(self.bgSymbol, space)
bg = bg .. rep(tHex[self.bgColor], space)
fg = fg .. rep(tHex[self.fgColor], space)
self.parent:setText(obx, oby + n - 1, text)
self.parent:setBG(obx, oby + n - 1, bg)
self.parent:setFG(obx, oby + n - 1, fg)
end
if(self:isFocused())then
local anchx, anchy = self:getAnchorPosition()
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end
end
self:setVisualChanged(false)
end
end;
end,
init = function(self)
self.bgColor = self.parent:getTheme("TextfieldBG")
self.fgColor = self.parent:getTheme("TextfieldText")
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_scroll", self)
self.parent:addEvent("mouse_drag", self)
self.parent:addEvent("key", self)
self.parent:addEvent("char", self)
self.parent:addEvent("other_event", self)
end,
}
return setmetatable(object, base)

View File

@@ -59,6 +59,7 @@ return function(name)
error("Thread Error Occurred - " .. result)
end
end
self.parent:addEvent("other_event", self)
return self
end;
@@ -71,6 +72,7 @@ return function(name)
stop = function(self, f)
isActive = false
self.parent:removeEvent("other_event", self)
return self
end;

View File

@@ -74,6 +74,7 @@ return function(name)
repeats = savedRepeats
timerObj = os.startTimer(timer)
timerIsActive = true
self.parent:addEvent("other_event", self)
return self
end;
@@ -86,6 +87,7 @@ return function(name)
os.cancelTimer(timerObj)
end
timerIsActive = false
self.parent:removeEvent("other_event", self)
return self
end;

View File

@@ -31,7 +31,7 @@ return { -- The default main theme for basalt!
ScrollbarBG = colors.lightGray,
ScrollbarText = colors.gray,
ScrollbarSymbolColor = colors.black,
SliderBG = colors.lightGray,
SliderBG = false,
SliderText = colors.gray,
SliderSymbolColor = colors.black,
SwitchBG = colors.lightGray,
@@ -39,5 +39,7 @@ return { -- The default main theme for basalt!
SwitchBGSymbol = colors.black,
SwitchInactive = colors.red,
SwitchActive = colors.green,
LabelBG = false,
LabelText = colors.black
}

23
CHANGELOG.md Normal file
View File

@@ -0,0 +1,23 @@
# Changelog
#### v. 1.5:
- You can now mirror a frame to a monitor by using :setMirror(side)
- with dynamic values you are able to use percentage values and even functions which get called everytime we need the size of that object
- XML got added to make design and logic seperate (you don't have to) - you are now able to use xml to create your UI design.
- Animations are now more advanced and provide many features to do cool stuff. They are also very easy to use now!
- Also some smaller bugfixes
- new bugs to explore
- fixed monitor support
- added :setIndex() for scrollbars
- added dynamic value system (not fully done)
- reworked the filesystem, now we use require instead of loadfile
- from now on the single file will be complied on the end users computer
- prepared everything for an advanced installer
#### v. 1:
- created Basalt
- added many objects (buttons, checkbox, labels, programs, switch, radio, lists, dropdowns, input, textfields, images, menubar, animations, threads, timers, progressbar, scrollbar, slider, pane)
- added bigfont
- added blittle
- added coroutine management
- added advanced event system

View File

@@ -1,39 +1,15 @@
# Basalt - A UI Framework for CC:Tweaked
![GitHub Repo stars](https://img.shields.io/github/stars/Pyroxenium/Basalt?style=for-the-badge)
![GitHub commit activity](https://img.shields.io/github/commit-activity/y/Pyroxenium/Basalt?style=for-the-badge)
![GitHub Repo stars](https://img.shields.io/badge/Made%20for-CC%3AT-orange?style=for-the-badge)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/Pyroxenium/Basalt?style=for-the-badge)
[![Discord](https://img.shields.io/discord/976905222251233320?label=Discord&style=for-the-badge)](https://discord.gg/yNNnmBVBpE)
Basalt is still under developement and you may find bugs!
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>
**Note:** Basalt is still under developement and you may find bugs!
## Information
Check out the [wiki](https://basalt.madefor.cc/) for information<br>
If you have questions, feel free to join the discord server: [https://discord.gg/yM7kndJdJJ](https://discord.gg/yM7kndJdJJ)
## Changelogs
From now on we will add changes:
#### Version 4:
- You can now mirror a frame to a monitor by using :setMirror(side)
- with dynamic values you are able to use percentage values and even functions which get called everytime we need the size of that object
- XML got added to make design and logic seperate (you don't have to) - you are now able to use xml to create your UI design.
- Animations are now more advanced and provide many features to do cool stuff. They are also very easy to use now!
- Also some smaller bugfixes
- new bugs to explore
#### Version 3:
- fixed monitor support
- added :setIndex() for scrollbars
- added dynamic value system (not fully done)
#### Version 2:
Note: You won't get any changes for now, so don't redownload the project! (:
- reworked the filesystem, now we use require instead of loadfile
- from now on the single file will be complied on the end users computer
- prepared everything for an advanced installer
#### Version 1:
- created Basalt
- added many objects (buttons, checkbox, labels, programs, switch, radio, lists, dropdowns, input, textfields, images, menubar, animations, threads, timers, progressbar, scrollbar, slider, pane)
- added bigfont
- added blittle
- added coroutine management
- added advanced event system
Check out the [wiki](https://basalt.madefor.cc/) for more information.<br>
If you have questions, feel free to join the discord server: [https://discord.gg/yNNnmBVBpE](https://discord.gg/yNNnmBVBpE).
## Demo
<img src="https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/basaltPreview2.gif" width="300">

View File

@@ -464,7 +464,8 @@ outputFile:write("project['default'] = {}")
local function writeNewPackage(subdir, name, path)
if not(fs.isDir(path))then
outputFile:write("project['"..subdir.."']['"..name.."'] = ".."function(...)")
local fileData = io.open(path, "r"):read("*all")
local file = io.open(path, "r")
local fileData = file:read("*all")
if(minifyProject)then
local success, data = minify(fileData)
if(success)then
@@ -475,6 +476,7 @@ local function writeNewPackage(subdir, name, path)
else
outputFile:write(fileData:gsub("]]", "] ]"):gsub("]]", "] ]").."\n")
end
file:close()
outputFile:write("end; \n")
end
end
@@ -489,16 +491,17 @@ for _,v in pairs(projectFiles)do
end
end
local main = io.open(fs.combine(projectPath, mainFile), "r"):read("*all")
local main = io.open(fs.combine(projectPath, mainFile), "r")
local mainData = main:read("*all")
if(minifyProject)then
local success,data = minify(main)
local success,data = minify(mainData)
if(success)then
outputFile:write(data)
else
print("Error: Can't minify "..fs.combine(projectPath, mainFile))
print("Error: Can't minify "..fs.combine(projectPath, mainFile).." "..data)
end
else
outputFile:write(main)
outputFile:write(mainData)
end
outputFile:close()
main:close()
outputFile:close()

View File

@@ -3,33 +3,29 @@
- [Quick Start](home/Quick-Start.md)
- [Installer](home/installer)
- Objects
- [Basalt](objects/Basalt)
- [Object](objects/Object)
- [Button](objects/Button)
- [Checkbox](objects/Checkbox)
- [Dropdown](objects/Dropdown)
- [Frame](objects/Frame)
- [Image](objects/Image)
- [Input](objects/Input)
- [Label](objects/Label)
- [List](objects/List)
- [Menubar](objects/Menubar)
- [Pane](objects/Pane)
- [Program](objects/Program)
- [Progressbar](objects/Progressbar)
- [Radio](objects/Radio)
- [Scrollbar](objects/Scrollbar)
- [Slider](objects/Slider)
- [Textfield](objects/Textfield)
- [Basalt](objects/Basalt.md)
- [Object](objects/Object.md)
- [Button](objects/Button.md)
- [Checkbox](objects/Checkbox.md)
- [Dropdown](objects/Dropdown.md)
- [Frame](objects/Frame.md)
- [Image](objects/Image.md)
- [Input](objects/Input.md)
- [Label](objects/Label.md)
- [List](objects/List.md)
- [Menubar](objects/Menubar.md)
- [Pane](objects/Pane.md)
- [Program](objects/Program.md)
- [Progressbar](objects/Progressbar.md)
- [Radio](objects/Radio.md)
- [Scrollbar](objects/Scrollbar.md)
- [Slider](objects/Slider.md)
- [Textfield](objects/Textfield.md)
- [Animation](objects/Animation.md)
- [Thread](objects/Thread)
- [Timer](objects/Timer)
- Events
- [Mouse Events](events/mouseEvents.md)
- [Keyboard Events](events/keyEvents.md)
- [Other Events](events/otherEvents.md)
- [Thread](objects/Thread.md)
- [Timer](objects/Timer.md)
- Tips & Tricks
- [Component Logic](tips/logic)
- [Changing Button Color](tips/buttons)
- [Advanced usage of Events](tips/events.md)
- [Example Designs](tips/design.md)
- [Your Logic](tips/logic.md)
- [Button coloring](tips/buttonColoring.md)
- [Designing/Animating](tips/design.md)
- [Dynamic Values](tips/dynamicvalues.md)

View File

@@ -1,39 +0,0 @@
Here we will talk about keyboard events and how you can manipulate them. There are 2 possible key events you can add to almost every visual object.
# onKey
`onKey(self, event, key)`<br>
The computercraft event which triggers this method is `key`.
Any visual object can register onKey events.
Here is a example on how to add a onKey event to your frame:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local subFrame = mainFrame:addFrame("subFrame"):setPosition(3,3):setSize(18,6):setBar("Sub Frame",colors.black):showBar():show()
function openSubFrame()
subFrame:show()
end
mainFrame:onKey(openSubFrame)
```
# onKeyUp
`onKeyUp(self, event, key)`<br>
The computercraft event which triggers this method is `key_up`.
Any visual object can register onKeyUp events.
Here is a example on how to add a onKeyUp event to your frame:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local subFrame = mainFrame:addFrame("subFrame"):setPosition(3,3):setSize(18,6):setBar("Sub Frame",colors.black):showBar():show()
function openSubFrame()
subFrame:show()
end
mainFrame:onKeyUp(openSubFrame)
```

View File

@@ -1,82 +0,0 @@
Here we will talk about mouse events and how you can use them. You can register custom mouse events to all visual objects
# onClick
`onClick(self, event, 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 = require("Basalt")
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, event, 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 = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnClick(self, button, x, y)
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick)
function buttonOnRelease(self, button, x, y)
basalt.debug("Button got released!")
end
button:onClickUp(buttonOnRelease)
```
# onScroll
`onScroll(self, event, direction, x, y)`<br>
The computercraft event which triggers this method is `mouse_scroll`.
Any visual object can register onScroll events.
Here is a example on how to add a onScroll event to your button:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnScroll(self, direction, x, y)
basalt.debug("Someone scrolls on me!")
end
button:onScroll(buttonOnScroll)
```
# onDrag
`onDrag(self, event, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_drag`.
Any visual object can register onDrag events.
Here is a example on how to add a onDrag event to your button:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnDrag(self, button, x, y)
basalt.debug("Someone drags me (i know i wont reposition myself)!")
end
button:onDrag(buttonOnDrag)
```

View File

@@ -1,79 +0,0 @@
There are also other useful events you can listen to:
# onChange
`onChange(self)`<br>
This is a custom event which gets triggered as soon as the function :setValue() is called. This function is also called by basalt, for example if you change the input, textfield or checkbox (or all the different types of lists) objects.
Here is a example on how to add a onChange event to your input, and also another example for your checkbox:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local aInput = mainFrame:addInput("specialInput"):setPosition(3,3):show()
local aCheckbox = mainFrame:addCheckbox("specialCheckbox"):setPosition(3,5):show()
local function checkInput(input)
if(string.lower(input:getValue())=="hello")then
basalt.debug("Hello back!")
end
end
local function checkCheckbox(checkbox)
if(checkbox:getValue()==true)then -- or if(checkbox:getValue())then
basalt.debug("Checkbox is active, let us do something!")
end
end
aInput:onChange(checkInput)
aCheckbox:onChange(checkCheckbox)
```
# onResize
`onResize(self)`<br>
This is a custom event which gets triggered as soon as the parent frame gets resized.
Here is a example on how to add a onResize event to your button:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local aButton = mainFrame:addButton("myButton"):setPosition(3,3):show()
local function onButtonResize(button)
local width = mainFrame:getWidth()
button:setSize()
end
aButton:onResize(onButtonResize)
```
# onLoseFocus
`onLoseFocus(self)`<br>
This event gets triggered as soon as the object loses its focus.
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("exampleButton"):setPosition(3,3):onLoseFocus(
function(self)
basalt.debug("Please come back... :(")
end
):show()
```
# onGetFocus
`onGetFocus(self)`<br>
This event gets triggered as soon as the object is the currently focused object.
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("exampleButton"):setPosition(3,3):onGetFocus(
function(self)
basalt.debug("Welcome back!")
end
):show()
```

View File

@@ -2,7 +2,7 @@
To load the framework into your project, make use of the following code on top of your code.
```lua
local basalt = require("Basalt")
local basalt = require("basalt")
```
It does not matter if you have installed the single file version or the full folder project. <br>
@@ -43,11 +43,10 @@ The true keyword in the end is optional and would simply start BPM immediately.
Here is a fully functioning example of Basalt code
```lua
local basalt = require("Basalt") --> Load the Basalt framework
local basalt = require("basalt") --> 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
@@ -76,7 +75,7 @@ basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect us
```
If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above:
```lua
local basalt = require("Basalt")
local basalt = require("basalt")
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"

View File

@@ -1,303 +1,21 @@
With animations, you can create a beautiful experience for users while interacting with objects.<br>
For now the animation class is very basic, it will be expanded in the future, but we have to say you can already do almost everything you can imagine!
With animations, you can create a beautiful experience for users while interacting with your program.<br>
Right now animation is a class which makes use of the timer event.<br>
You can find more information below:
`The animation object is still a WIP and the way you use it right now could change in the future!`
## add
Adds a new function to an animation
#### Parameters:
1. `function` The function containing animation logic
#### Returns:
1. `animation` Animation in use
#### Usage:
* This will set the button position to 3,3, waits 1 second, then sets position to 4,4, waits 2 seconds, and then sets the position to 5,5
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
aAnimation:play()
```
## wait
Sets a wait timer for the next function after the previous function got executed, no wait timer calls the next function immediately
#### Parameters:
1. `number` The length of delay between the functions _(in seconds)_
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
aAnimation:play()
```
## play
Plays the animation
#### Parameters:
1. `boolean` Whether it will loop forever, will most likely be replaced with a count in the future
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() testButton:setBackground(colors.gray) end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
aAnimation:play() -- changes the background color of that button from black to gray and then to lightGray
```
## cancel
Cancels the animation
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() aAnimation:cancel() end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
aAnimation:play()
```
## setObject
Sets the object which the animation should reposition/resize
#### Parameters:
1. `table` object
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():setObject(testButton)
```
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
```
```xml
<animation object="buttonToAnimate" />
```
## move
Moves the object which got defined by setObject
#### Parameters:
1. `number` x coordinate
2. `number` y coordinate
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
* Takes 2 seconds to move the object from its current position to x15 y3
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):move(15,3,2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<move><x>15</x><y>6</y><duration>2</duration></move>
</animation>
```
## offset
Changes the offset on the object which got defined by setObject
#### Parameters:
1. `number` x offset
2. `number` y offset
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame("frameToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(subFrame):offset(1,12,1):play()
```
```xml
<animation object="frameToAnimate" play="true">
<offset><x>1</x><y>12</y><duration>1</duration></offset>
</animation>
```
## size
Changes the size on the object which got defined by setObject
#### Parameters:
1. `number` width
2. `number` height
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):size(15,3,1):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<offset><w>15</w><h>3</h><duration>1</duration></offset>
</animation>
```
## changeText
Changes the text while animation is running
#### Parameters:
1. `table` multiple text strings - example: {"i", "am", "groot"}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText({"i", "am", "groot"}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<text>
<text>i</text>
<text>am</text>
<text>groot</text>
<duration>2</duration>
</text>
</animation>
```
## changeTextColor
Changes the text color while the animation is running
#### Parameters:
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
```
## changeBackground
Changes the background color while the animation is running
#### Parameters:
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```
| | |
|---|---|
|[add](objects/Animation/add.md)|Adds a new custom function to call at the current time
|[wait](objects/Animation/wait.md)|Adds a amount to the animation time
|[play](objects/Animation/play.md)|Plays the animation
|[cancel](objects/Animation/cancel.md)|Cancels the animation
|[setObject](objects/Animation/setObject.md)|Sets an object on which predefined animations should work on
|[move](objects/Animation/move.md)|Predefined animation: moves the object to a new position
|[offset](objects/Animation/offset.md)|Predefined animation: Changes the offset of that object
|[size](objects/Animation/size.md)|Predefined animation: Changes the size on a object
|[changeText](objects/Animation/changeText.md)|Predefined animation: Changes the text (object needs a setText method)
|[changeTextColor](objects/Animation/changeTextColor.md)|Predefined animation: changes the foreground/textcolor on a object
|[changeBackground](objects/Animation/changeBackground.md)|Predefined animation: changes the background on a object
# Events
## onDone
`onDone(self)`<br>
This is a event which gets fired as soon as the animation has finished.
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
aAnimation:onDone(function()
basalt.debug("The animation is done")
end)
```
In XML you are also able to queue multiple animations, like this:
```xml
<animation id="anim2" object="buttonToAnimate">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
<animation onDone="#anim2" object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```
| | |
|---|---|
|[onDone](objects/Animation/onDone.md)|Gets called as soon as the animation has finished

View File

@@ -0,0 +1,17 @@
## add
Adds a new function to an animation
#### Parameters:
1. `function` The function containing animation logic
#### Returns:
1. `animation` Animation in use
#### Usage:
* This will set the button position to 3,3, waits 1 second, then sets position to 4,4, waits 2 seconds, and then sets the position to 5,5
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
aAnimation:play()
```

View File

@@ -0,0 +1,15 @@
## cancel
Cancels the animation
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() aAnimation:cancel() end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
aAnimation:play()
```

View File

@@ -0,0 +1,28 @@
## changeBackground
Changes the background color while the animation is running
#### Parameters:
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```

View File

@@ -0,0 +1,28 @@
## changeText
Changes the text while animation is running
#### Parameters:
1. `table` multiple text strings - example: {"i", "am", "groot"}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText({"i", "am", "groot"}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<text>
<text>i</text>
<text>am</text>
<text>groot</text>
<duration>2</duration>
</text>
</animation>
```

View File

@@ -0,0 +1,28 @@
## changeTextColor
Changes the text color while the animation is running
#### Parameters:
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
```

View File

@@ -0,0 +1,25 @@
## move
Moves the object which got defined by setObject
#### Parameters:
1. `number` x coordinate
2. `number` y coordinate
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
* Takes 2 seconds to move the object from its current position to x15 y3
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):move(15,3,2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<move><x>15</x><y>6</y><duration>2</duration></move>
</animation>
```

View File

@@ -0,0 +1,25 @@
## offset
Changes the offset on the object which got defined by setObject
#### Parameters:
1. `number` x offset
2. `number` y offset
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame("frameToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(subFrame):offset(1,12,1):play()
```
```xml
<animation object="frameToAnimate" play="true">
<offset><x>1</x><y>12</y><duration>1</duration></offset>
</animation>
```

View File

@@ -0,0 +1,35 @@
## onDone
`onDone(self)`<br>
This is a event which gets fired as soon as the animation has finished.
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
aAnimation:onDone(function()
basalt.debug("The animation is done")
end)
```
In XML you are also able to queue multiple animations, like this:
```xml
<animation id="anim2" object="buttonToAnimate">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
<animation onDone="#anim2" object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```

View File

@@ -0,0 +1,16 @@
## play
Plays the animation
#### Parameters:
1. `boolean` Whether it will loop forever, will most likely be replaced with a count in the future
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() testButton:setBackground(colors.gray) end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
aAnimation:play() -- changes the background color of that button from black to gray and then to lightGray
```

View File

@@ -0,0 +1,24 @@
## setObject
Sets the object which the animation should reposition/resize
#### Parameters:
1. `table` object
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():setObject(testButton)
```
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
```
```xml
<animation object="buttonToAnimate" />
```

View File

@@ -0,0 +1,24 @@
## size
Changes the size on the object which got defined by setObject
#### Parameters:
1. `number` width
2. `number` height
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):size(15,3,1):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<offset><w>15</w><h>3</h><duration>1</duration></offset>
</animation>
```

View File

@@ -0,0 +1,16 @@
## wait
Sets a wait timer for the next function after the previous function got executed, no wait timer calls the next function immediately
#### Parameters:
1. `number` The length of delay between the functions _(in seconds)_
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
aAnimation:play()
```

View File

@@ -1,201 +1,37 @@
This is the UI Manager and the first thing you want to access.
Before you can access Basalt, you need to add the following code on top of your file:
`local basalt = require("Basalt")`
`local basalt = require("basalt")`
Now you are able to access the following methods:
require loads the UI Framework into your project.
## basalt.createFrame
Create a base-frame (main frame)
#### Parameters:
1. `string` name
Now you are able to access the following list of methods:
#### Returns:
1. `frame` object
| | |
|---|---|
|[createFrame](objects/Basalt/createFrame.md)|Creates a new base frame
|[removeFrame](objects/Basalt/removeFrame.md)|Removes a previously created base frame
|[getFrame](objects/Basalt/getFrame.md)|Returns a frame object by it's id
|[getActiveFrame](objects/Basalt/getActiveFrame.md)|Returns the currently active base frame
|[autoUpdate](objects/Basalt/autoUpdate.md)|Starts the event and draw listener
|[update](objects/Basalt/update.md)|Starts the event and draw listener once
|[stopUpdate](objects/Basalt/stopUpdate.md)|Stops the currently active event and draw listener
|[isKeyDown](objects/Basalt/isKeyDown.md)|Returns if the key is held down
|[debug](objects/Basalt/debug.md)|Writes something into the debug console
|[log](objects/Basalt/log.md)|Writes something into the log file
|[setTheme](objects/Basalt/setTheme.md)|Changes the base theme of basalt
|[setVariable](objects/Basalt/setVariable.md)|Sets a variable which you can access via XML
|[schedule](objects/Basalt/schedule.md)|Schedules a new task
#### Usage:
* Create and show a frame with id "myFirstFrame"
# Examples
Here is a lua example on how to create a empty base frame and start basalt's listener.
```lua
local mainFrame = basalt.createFrame("myFirstFrame")
```
local basalt = require("basalt") -- we load the UI Framework into our project
## basalt.removeFrame
Removes a base frame
local main = basalt.createFrame() -- we create a base frame - on that frame we are able to add object's
#### Parameters:
1. `string` name
-- here we would add additional object's
#### Usage:
* Removes the previously created frame with id "myFirstFrame"
```lua
local mainFrame = basalt.createFrame("myFirstFrame")
basalt.removeFrame("myFirstFrame")
```
## basalt.getFrame
Returns a base frame with the given name
#### Parameters:
1. `string` name
#### Returns:
1. `frame` object
#### Usage:
* Creates, fetches and shows the "myFirstFrame" object
```lua
basalt.createFrame("myFirstFrame"):hide()
basalt.getFrame("myFirstFrame"):show()
```
## basalt.getActiveFrame
Returns the currently active base frame
#### Returns:
1. `frame` The current frame
#### Usage:
* Displays the active frame name in the debug console
```lua
basalt.createFrame()
basalt.debug(basalt.getActiveFrame():getName()) -- returns the uuid
```
## basalt.autoUpdate
Starts the draw and event handler until basalt.stopUpdate() is called
#### Usage:
* Enable the basalt updates, otherwise the screen will not continue to update
```lua
local mainFrame = basalt.createFrame()
basalt.autoUpdate()
```
## basalt.update
Calls the draw and event handler once - this gives more flexibility about which events basalt should process. For example you could filter the terminate event.
#### Parameters:
1. `string` The event to be received
2. `...` Additional event variables to capture
#### Usage:
* Creates and starts a custom update cycle
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2)
while true do
basalt.update(os.pullEventRaw())
end
```
## basalt.stopUpdate
Stops the automatic draw and event handler which got started by basalt.autoUpdate()
#### Usage:
* When the quit button is clicked, the button stops basalt auto updates
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2):setText("Stop Basalt!")
aButton:onClick(function()
basalt.stopUpdate()
end)
basalt.autoUpdate()
```
## basalt.isKeyDown
Checks if the user is currently holding a key
#### Parameters:
1. `number` key code (use the keys table for that)
#### Returns:
1. `boolean` true or false
#### Usage:
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2):setText("Check Ctrl")
aButton:onClick(function()
basalt.debug(basalt.isKeyDown(keys.leftCtrl))
end)
basalt.autoUpdate()
```
## basalt.debug
creates a label with some information on the main frame on the bottom left, if you click on that label it will open a log view for you. See it as the new print for debugging
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable basalt.debugLabel
which returns the debug Label.
Also basalt.debugFrame and basalt.debugList are available.
#### Parameters:
1. `...` (multiple parameters are possible, like print does)
#### Usage:
* Prints "Hello! ^-^" to the debug console
```lua
basalt.debug("Hello! ", "^-^")
```
## basalt.setTheme
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua)
#### Parameters:
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
#### Usage:
* Sets the default theme of basalt.
```lua
basalt.setTheme({
ButtonBG = colors.yellow,
ButtonText = colors.red,
...,
})
```
## basalt.setVariable
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
#### Parameters:
1. `string` a key name
1. `any` any variable
#### Usage:
* Adds a function to basalt.
```lua
basalt.setVariable("clickMe", function()
basalt.debug("I got clicked")
end)
```
```xml
<button onClick="clickMe" text="Click me" />
```
## basalt.schedule
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
#### Parameters:
1. `function` a function which should get executed
#### Returns:
1. `function` it returns the function which you have to execute in order to start the coroutine
#### Usage:
* Creates a schedule which switches the color between red and gray
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click me")
aButton:onClick(basalt.schedule(function(self)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
end))
```
basalt.autoUpdate() -- we start listening to incoming events and draw stuff on the screen
```

View File

@@ -0,0 +1,12 @@
## basalt.autoUpdate
This starts the event and draw handler for you. The listeners will run until you stop them.
#### Parameters:
1. `boolean` optional - if you use false as the first parameter it would stop the listeners.
#### Usage:
* Enable the basalt listeners, otherwise the screen will not continue to update
```lua
local main = basalt.createFrame()
basalt.autoUpdate()
```

View File

@@ -0,0 +1,27 @@
## basalt.createFrame
Creates a new base-frame, you can have as many base-frames as you want, but only 1 can be active (visible) at the same time.
You can always switch between your base frames.
Only the currently active base-frame listens to incoming events (except for some events like time-events and peripheral-events)
#### Parameters:
1. `string` id - optional (if you dont set a id it will automatically create a uuid for you)
#### Returns:
1. `frame` object
#### Usage:
* How to use multiple base frames:
```lua
local main1 = basalt.createFrame() -- Visible base frame on program start
local main2 = basalt.createFrame()
local main3 = basalt.createFrame()
main1:addButton()
:setPosition(2,2)
:setText("Switch")
:onClick(function()
main2:show() -- this function automatically "hides" the first one and shows the second one
end)
main2:addLabel()
:setText("We are currently on main2")
```

View File

@@ -0,0 +1,22 @@
## basalt.debug
Creates a label with some information on the main frame on the bottom left. When you click on that label it will open a log view for you. See it as the new print for debugging
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable basalt.debugLabel
which returns the debug Label.
Also basalt.debugFrame and basalt.debugList are available.
#### Parameters:
1. `...` (multiple parameters are possible, like print does)
#### Usage:
* Prints "Hello! ^-^" to the debug console
```lua
basalt.debug("Hello! ", "^-^")
```
* Changes the debug label's anchor
```lua
basalt.debugLabel:setAnchor("topLeft") -- default anchor is bottomLeft
basalt.debug("Hello!")
```

View File

@@ -0,0 +1,12 @@
## basalt.getActiveFrame
Returns the currently active/visible base frame
#### Returns:
1. `frame` The current frame
#### Usage:
* Displays the active frame name in the debug console
```lua
local main = basalt.createFrame()
basalt.debug(basalt.getActiveFrame():getName()) -- returns the id
```

View File

@@ -0,0 +1,23 @@
## basalt.getFrame
Returns a base frame by the given id
#### Parameters:
1. `string` id
#### Returns:
1. `frame` object
#### Usage:
* Creates, fetches and shows the "myFirstFrame" object
```lua
local main = basalt.createFrame("firstBaseFrame")
local main2 = basalt.createFrame("secondBaseFrame")
main:addButton()
:setText("Show")
:onClick(function()
local frame2 = basalt.getFrame("secondBaseFrame")
if(frame2~=nil)then
frame2:show()
end
end)
```

View File

@@ -0,0 +1,21 @@
## basalt.isKeyDown
Checks if the user is currently holding a key
#### Parameters:
1. `number` key code (use the keys table for that)
#### Returns:
1. `boolean` true or false
#### Usage:
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
```lua
local main = basalt.createFrame()
local aButton = mainFrame:addButton()
:setPosition(2,2)
:setText("Check Ctrl")
:onClick(function()
basalt.debug(basalt.isKeyDown(keys.leftCtrl))
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,15 @@
## basalt.log
This writes something into a file. The main goal is to make debugging errors easier. Lets say you'r program is crashing and
you don't know why, you could use basalt.log
The log files will automatically removed after you start your program again
#### Parameters:
1. `string` The text to write into the log file
2. `string` - optional (default: "Debug") - the type to write
#### Usage:
* Writes "Hello!" into the log file
```lua
basalt.log("Hello!")
```

View File

@@ -0,0 +1,17 @@
## basalt.removeFrame
Removes the base frame by it's id. This only works for base-frames.
#### Parameters:
1. `string` id
#### Usage:
* Removes the previously created frame with id "myFirstFrame"
```lua
local main = basalt.createFrame("firstBaseFrame")
local main2 = basalt.createFrame("secondBaseFrame")
main:addButton()
:setText("Remove")
:onClick(function()
basalt.removeFrame(main2:getName()) -- you can use main2:getName() to find out the id or just use "secondBaseFrame"
end)
```

View File

@@ -0,0 +1,28 @@
## basalt.schedule
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
#### Parameters:
1. `function` a function which should get executed
#### Returns:
1. `function` it returns the function which you have to execute in order to start the coroutine
#### Usage:
* Creates a schedule which switches the color between red and gray
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click me")
aButton:onClick(basalt.schedule(function(self)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
end))
```

View File

@@ -0,0 +1,15 @@
## basalt.setTheme
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua)
#### Parameters:
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
#### Usage:
* Sets the default theme of basalt.
```lua
basalt.setTheme({
ButtonBG = colors.yellow,
ButtonText = colors.red,
...,
})
```

View File

@@ -0,0 +1,17 @@
## basalt.setVariable
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
#### Parameters:
1. `string` a key name
1. `any` any variable
#### Usage:
* Adds a function to basalt.
```lua
basalt.setVariable("clickMe", function()
basalt.debug("I got clicked")
end)
```
```xml
<button onClick="clickMe" text="Click me" />
```

View File

@@ -0,0 +1,15 @@
## basalt.stopUpdate or basalt.stop
Stops the automatic draw and event handler which got started by basalt.autoUpdate()
#### Usage:
* When the quit button is clicked, the button stops basalt's event listeners and draw handlers
```lua
local main = basalt.createFrame()
local aButton = main:addButton()
:setPosition(2,2)
:setText("Stop Basalt!")
:onClick(function()
basalt.stopUpdate()
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,18 @@
## basalt.update
Calls the draw and event handler once - this gives more flexibility about which events basalt should process. For example you could filter the terminate event.
Which means you have to pass the events into basalt.update.
#### Parameters:
1. `string` The event to be received
2. `...` Additional event variables to capture
#### Usage:
* Creates and starts a custom update cycle
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2)
while true do
local ev = table.pack(os.pullEventRaw())
basalt.update(table.unpack(ev))
end
```

View File

@@ -1,73 +1,19 @@
Buttons are objects, which execute something by clicking on them.<br>
The button object is for creating buttons If you click on them, they should execute something. You decide what should happen when clicking on them.
Remember button also inherits from [Object](objects/Object.md)
[Object](objects/Object.md) methods also apply for buttons.
## setText
Sets the displayed button text
#### Parameters:
1. `string` the text the button should show
| | |
|---|---|
|[setText](objects/Button/setText.md)|Changes the button text
|[setHorizontalAlign](objects/Button/setHorizontalAlign.md)|Changes the horizontal text position
|[setVerticalAlign](objects/Button/setVerticalAlign.md)|Changes the vertical text position
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a button with "Click me!" as text.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Click me!")
```
```xml
<button text="Click me!" />
```
## setHorizontalAlign
Sets the horizontal align of the button text
#### Parameters:
1. `string` the position as string ("left", "center", "right") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
```
```xml
<button text="Click me!" horizontalAlign="right" />
```
## setVerticalAlign
Sets the vertical align of the button text
#### Parameters:
1. `string` the position as string ("top", "center", "bottom") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right and the vertical text align to bottom.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
:setVerticalAlign("bottom")
```
```xml
<button text="Click me!" horizontalAlign="right" verticalAlign="bottom" />
```
# Example
This is a example on how you would create a fully working button:
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click")
local main = basalt.createFrame()
local aButton = main:addButton():setText("Click")
aButton:onClick(function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then
@@ -76,9 +22,9 @@ aButton:onClick(function(self,event,button,x,y)
end)
```
and this would be the xml way to do it:
and this would be the xml way:
```lua
local mainFrame = basalt.createFrame():addLayout("example.xml")
local main = basalt.createFrame():addLayout("example.xml")
basalt.setVariable("buttonClick", function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then

View File

@@ -0,0 +1,20 @@
## setHorizontalAlign
Sets the horizontal align of the button text
#### Parameters:
1. `string` the position as string ("left", "center", "right") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
```
```xml
<button text="Click me!" horizontalAlign="right" />
```

View File

@@ -0,0 +1,17 @@
## setText
Sets the displayed button text
#### Parameters:
1. `string` the text the button should show
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a button with "Click me!" as text.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Click me!")
```
```xml
<button text="Click me!" />
```

View File

@@ -0,0 +1,21 @@
## setVerticalAlign
Sets the vertical align of the button text
#### Parameters:
1. `string` the position as string ("top", "center", "bottom") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right and the vertical text align to bottom.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
:setVerticalAlign("bottom")
```
```xml
<button text="Click me!" horizontalAlign="right" verticalAlign="bottom" />
```

View File

@@ -1,14 +1,17 @@
With checkbox objects the user can set a bool to true or false
With checkboxes the user can set a boolean to true or false by clicking on them.
Remember checkbox also inherits from [Object](objects/Object.md)
[Object](objects/Object.md) methods also apply for checkboxes.
| | |
|---|---|
|[setSymbol](objects/Checkbox/setSymbol.md)|Changes the symbol when checkbox is checked
A checkbox does not have any custom methods. All required methods are provided by the base [object](objects/Object.md) class.
# Example
This is how you would create a event which gets fired as soon as the value gets changed:
```lua
local mainFrame = basalt.createFrame()
local aCheckbox = mainFrame:addCheckbox()
local main = basalt.createFrame()
local aCheckbox = main:addCheckbox()
local function checkboxChange(self)
local checked = self:getValue()
@@ -19,7 +22,7 @@ aCheckbox:onChange(checkboxChange)
also possible via xml:
```lua
local mainFrame = basalt.createFrame():addLayout("example.xml")
local main = basalt.createFrame():addLayout("example.xml")
basalt.setVariable("checkboxChange", function(self)
local checked = self:getValue()

View File

View File

@@ -1,307 +1,31 @@
Dropdowns are objects where the user can click on a button, this will open a list where the user can choose from.
If you want to access values inside items this is how the table for single items is made (just a example):
[Object](objects/Object.md) methods also apply for dropdowns.
| | |
|---|---|
|[addItem](objects/Dropdown/addItem.md)|Adds a new item into the list
|[removeItem](objects/Dropdown/removeItem.md)|Removes a item from the list
|[editItem](objects/Dropdown/editItem.md)|Changes a already existing item in the list
|[getItem](objects/Dropdown/getItem.md)|Returns a item by its index
|[getItemCount](objects/Dropdown/getItemCount.md)|Returns the item count
|[getAll](objects/Dropdown/getAll.md)|Returns the entire list as a table
|[selectItem](objects/Dropdown/selectItem.md)|Selects a item
|[clear](objects/Dropdown/clear.md)|Makes the entire list empty
|[getItemIndex](objects/Dropdown/getItemIndex.md)|Returns the currently active item index
|[setSelectedItem](objects/Dropdown/setSelectedItem.md)|Changes the default bg and fg, when the user selects a item
|[setOffset](objects/Dropdown/setOffset.md)|Changes the list offset
|[getOffset](objects/Dropdown/getOffset.md)|Returns the current offset
|[setDropdownSize](objects/Dropdown/setDropdownSize.md)|Changes the dropdown size
A item-table in dropdowns looks like the following example:
```lua
item = {
text="1. Entry",
bgCol=colors.black,
fgCol=colors.white
args = {}
text="1. Entry", -- the text its showing
bgCol=colors.black, -- the background color
fgCol=colors.white -- the foreground color
args = {} -- custom args you want to pass, which you will be able to access in for example onChange events
}
```
Remember Dropdown also inherits from [Object](objects/Object.md)
## addItem
Adds a item into the dropdown
#### Parameters:
1. `string` The entry name
2. `number|color` unique default background color - optional
3. `number|color` unique default text color - optional
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
```
```xml
<dropdown>
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```
## removeItem
Removes a item from the dropdown
#### Parameters:
1. `number` The index which should get removed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:removeItem(2)
```
## editItem
Edits a item from the dropdown
#### Parameters:
1. `number` The index which should be edited
2. `string` The new item name
3. `number` the new item background color - optional
4. `number` The new item text color - optional
5. `any` New additional information - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:editItem(2, "Still 2. Entry", colors.red)
```
## getItem
Returns a item by index
#### Parameters:
1. `number` The index which should be returned
#### Returns:
1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItem(2).text)
```
## getItemCount
Returns the current item count
#### Returns:
1. `number` The item list count
#### Usage:
* Creates a default dropdown with 3 entries and prints the current item count.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItemCount())
```
## getAll
Returns all items as table
#### Returns:
1. `table` All items
#### Usage:
* Creates a default menubar with 3 entries and prints a table.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getAll())
```
## selectItem
selects a item in the dropdown (same as a player would click on a item)
#### Parameters:
1. `number` The index which should get selected
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and selects the second entry.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
```
## clear
Removes all items.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes them immediatley. Which makes no sense.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:clear()
```
## getItemIndex
returns the item index of the currently selected item
#### Returns:
1. `number` The current index
#### Usage:
* Creates a default dropdown with 3 entries selects the second entry and prints the currently selected index.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
basalt.debug(aDropdown:getItemIndex())
```
## setSelectedItem
Sets the background and the foreground of the item which is currently selected
#### Parameters:
1. `number|color` The background color which should be used
2. `number|color` The text color which should be used
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 4 entries and sets the selection background color to green.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:addItem("4. Entry")
aDropdown:setSelectedItem(colors.green, colors.red)
```
```xml
<dropdown selectionBG="green" selectionFG="red">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>2. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```
## setOffset
Sets the offset of the dropdown (the same as you would scroll) - default is 0
#### Parameters:
1. `number` The offset value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
```
```xml
<dropdown offset="3">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
<item><text>4. Entry</text></item>
<item><text>5. Entry</text></item>
<item><text>6. Entry</text></item>
</dropdown>
```
## getOffset
Returns the current index offset
#### Returns:
1. `number` offset value
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3, also prints the current offset.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
basalt.debug(aDropdown:getOffset())
```
## setDropdownSize
Sets the size of the opened dropdown
#### Parameters:
1. `number` The width value
2. `number` The height value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown, adds 3 entries and sets the dropdown size to 15w, 8h
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown():setDropdownSize(15,8)
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry")
aDropdown:addItem("3. Entry")
```
```xml
<dropdown dropdownWidth="15" dropdownHeight="8">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
</dropdown>
```
```

View File

@@ -0,0 +1,28 @@
## addItem
Adds a item into the dropdown
#### Parameters:
1. `string` The entry name
2. `number|color` unique default background color - optional
3. `number|color` unique default text color - optional
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
```
```xml
<dropdown>
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```

View File

@@ -0,0 +1,16 @@
## clear
Removes all items.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes them immediatley. Which makes no sense.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:clear()
```

View File

@@ -0,0 +1,23 @@
## editItem
Edits a item from the dropdown
#### Parameters:
1. `number` The index which should be edited
2. `string` The new item name
3. `number` the new item background color - optional
4. `number` The new item text color - optional
5. `any` New additional information - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:editItem(2, "Still 2. Entry", colors.red)
```

View File

@@ -0,0 +1,16 @@
## getAll
Returns all items as table
#### Returns:
1. `table` All items
#### Usage:
* Creates a default menubar with 3 entries and prints a table.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getAll())
```

View File

@@ -0,0 +1,19 @@
## getItem
Returns a item by index
#### Parameters:
1. `number` The index which should be returned
#### Returns:
1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItem(2).text)
```

View File

@@ -0,0 +1,16 @@
## getItemCount
Returns the current item count
#### Returns:
1. `number` The item list count
#### Usage:
* Creates a default dropdown with 3 entries and prints the current item count.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItemCount())
```

View File

@@ -0,0 +1,17 @@
## getItemIndex
returns the item index of the currently selected item
#### Returns:
1. `number` The current index
#### Usage:
* Creates a default dropdown with 3 entries selects the second entry and prints the currently selected index.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
basalt.debug(aDropdown:getItemIndex())
```

View File

@@ -0,0 +1,20 @@
## getOffset
Returns the current index offset
#### Returns:
1. `number` offset value
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3, also prints the current offset.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
basalt.debug(aDropdown:getOffset())
```

View File

@@ -0,0 +1,19 @@
## removeItem
Removes a item from the dropdown
#### Parameters:
1. `number` The index which should get removed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:removeItem(2)
```

View File

@@ -0,0 +1,19 @@
## selectItem
selects a item in the dropdown (same as a player would click on a item)
#### Parameters:
1. `number` The index which should get selected
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and selects the second entry.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
```

View File

@@ -0,0 +1,26 @@
## setDropdownSize
Sets the size of the opened dropdown
#### Parameters:
1. `number` The width value
2. `number` The height value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown, adds 3 entries and sets the dropdown size to 15w, 8h
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown():setDropdownSize(15,8)
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry")
aDropdown:addItem("3. Entry")
```
```xml
<dropdown dropdownWidth="15" dropdownHeight="8">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
</dropdown>
```

View File

@@ -0,0 +1,32 @@
## setOffset
Sets the offset of the dropdown (the same as you would scroll) - default is 0
#### Parameters:
1. `number` The offset value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
```
```xml
<dropdown offset="3">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
<item><text>4. Entry</text></item>
<item><text>5. Entry</text></item>
<item><text>6. Entry</text></item>
</dropdown>
```

View File

@@ -0,0 +1,28 @@
## setSelectedItem
Sets the background and the foreground of the item which is currently selected
#### Parameters:
1. `number|color` The background color which should be used
2. `number|color` The text color which should be used
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 4 entries and sets the selection background color to green.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:addItem("4. Entry")
aDropdown:setSelectedItem(colors.green, colors.red)
```
```xml
<dropdown selectionBG="green" selectionFG="red">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>2. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```

View File

@@ -1,409 +1,39 @@
<a href="https://i.imgur.com/aikc0K1.png"><img src="https://i.imgur.com/aikc0K1.png" height="500" /></a>
Frames are like containers, but are also normal objects.
In other words, you can add other objects _(even frames)_ to a frame; if the frame itself is visible
all sub-objects _(if they are set as visible)_ are also visible. A better description will follow.
## basalt.createFrame
Creates a new non-parent frame - in most cases it is the first thing you'll need.
#### Parameters:
1. `string` name (should be unique)
#### Returns:
1. `frame | nil` The frame created by createFrame, or `nil` if there is already a frame with the given name.
#### Usage:
* Create a frame with an id "myFirstFrame", stored in a variable named frame
```lua
local myFrame = basalt.createFrame("myFirstFrame")
```
## addFrame
Creates a child frame on the frame, the same as [basalt.createFrame](https://github.com/Pyroxenium/Basalt/wiki/Frame#basaltcreateframe) except the frames are given a parent-child relationship automatically
#### Parameters:
1. `string` name (should be unique)
#### Returns:
1. `frame | nil` The frame created by addFrame, or `nil` if there is already a child frame with the given name.<br>
#### Usage:
* Create a new main frame and adds a child frame to it
```lua
local mainFrame = basalt.createFrame()
local myFrame = mainFrame:addFrame()
```
```xml
<frame></frame>
```
## setBar
Sets the text, background, and foreground of the upper bar of the frame, accordingly.
#### Parameters:
1. `string` The title text to set the bar to
2. `number` The background color
2. `number` The foreground color
#### Returns:
1. `frame` The frame being used
#### Usage:
* Set the title to "My first frame!", with a background of black and a foreground of light gray.
```lua
frame:setBar("My first Frame!", colors.black, colors.lightGray)
```
* Store the frame, use the named frame variable after assigning.
```lua
local mainFrame = basalt.createFrame()
local myFrame = MainFrame:addFrame()
myFrame:setBar("My first Frame!")
```
* This abuses the call-chaining that Basalt uses.
```lua
local mainFrame = basalt.createFrame()
local myFrame = mainFrame:addFrame():setBar("My first Frame!")
```
```xml
<frame barText="My first Frame!" barBG="black" barFG="lightGray"></frame>
```
## setBarTextAlign
Sets the frame's bar-text alignment
#### Parameters:
1. `string` Can be supplied with "left", "center", or "right"
#### Returns:
1. `frame` The frame being used
#### Usage:
* Set the title of myFrame to "My first frame!", and align it to the right.
```lua
myFrame:setBar("My first Frame!"):setBarTextAlign("right")
```
```xml
<frame barAlign="right"></frame>
```
## showBar
Toggles the frame's upper bar
#### Parameters:
1. `boolean | nil` Whether the frame's bar is visible or if supplied `nil`, is automatically visible
#### Returns:
1. `frame` The frame being used
#### Usage:
* Sets myFrame to have a bar titled "Hello World!" and subsequently displays it.
```lua
myFrame:setBar("Hello World!"):showBar()
```
```xml
<frame bar="true"></frame>
```
## setMonitor
Sets this frame as a monitor frame
#### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new monitor frame, you can use to show objects on a monitor.
```lua
local mainFrame = basalt.createFrame()
local monitorFrame = basalt.createFrame():setMonitor("right")
monitorFrame:setBar("Monitor 1"):showBar()
```
```xml
<frame monitor="right"></frame>
```
## setMirror
mirrors this frame to another peripheral monitor object.
#### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates mirror of your main frame to a monitor on the left side.
```lua
local mainFrame = basalt.createFrame():setMirror("left")
```
```xml
<frame mirror="left"></frame>
```
## getObject
Returns a child object of the frame
#### Parameters:
1. `string` The name of the child object
#### Returns:
1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name
#### Usage:
* Adds a button with id "myFirstButton", then retrieves it again through the frame object
```lua
myFrame:addButton("myFirstButton")
local aButton = myFrame:getObject("myFirstButton")
```
## removeObject
Removes a child object from the frame
#### Parameters:
1. `string` The name of the child object
#### Returns:
1. `boolean` Whether the object with the given name was properly removed
#### Usage:
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id
```lua
myFrame:addButton("myFirstButton")
myFrame:removeObject("myFirstButton")
```
## setFocusedObject
Sets the currently focused object
#### Parameters:
1. `object` The child object to focus on
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new button, sets the focused object to the previously mentioned button
```lua
local aButton = myFrame:addButton()
myFrame:setFocusedObject(aButton)
```
## removeFocusedObject
Removes the focus of the supplied object
#### Parameters:
1. `object` The child object to remove focus from
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new button then removes the focus from that button when clicking on it
```lua
local aButton = myFrame:addButton():setFocus():onClick(function()
myFrame:removeFocusedObject(aButton)
end)
```
## getFocusedObject
Gets the currently focused object
#### Returns:
1. `object` The currently focused object
#### Usage:
* Gets the currently focused object from the frame, storing it in a variable
```lua
local focusedObject = myFrame:getFocusedObject()
```
## setMovable
Sets whether the frame can be moved. _In order to move the frame click and drag the upper bar of the frame_
#### Parameters:
1. `boolean` Whether the object is movable
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable
```lua
local myFrame = basalt.createFrame():setMovable(true)
```
```xml
<frame moveable="true"></frame>
```
## setOffset
Sets the frame's coordinate offset. The frame's child objects will receive the frame's coordinate offset. For example, when using a scrollbar, if you use its value to add an offset to a frame, you will get a scrollable frame.
Objects are also able to ignore the offset by using :ignoreOffset() (For example, you may want to ignore the offset on the scrollbar itself)
The function can also be supplied with negative values
#### Parameters:
1. `number` The x direction offset (+/-)
2. `number` The y direction offset (+/-)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame with x offset of 5 and a y offset of 3
```lua
local myFrame = basalt.createFrame():setOffset(5, 3)
```
* Creates with x offset of 5 and a y offset of -5 (Meaning if you added a button with y position 5, it would be at y position 0)
```lua
local myFrame = basalt.createFrame():setOffset(5, -5)
```
```xml
<frame xOffset="5" yOffset="-5"></frame>
```
## addLayout
Adds a new XML Layout into your frame.
#### Parameters:
1. `string` Path to your layout
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayout("mainframe.xml")
```
```xml
<frame layout="mainframe.xml"></frame>
```
## addLayoutFromString
Adds a new XML Layout as string into your frame.
#### Parameters:
1. `string` xml
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayoutFromString("<button x='12' y='5' bg='black' />")
```
## getLastLayout
returns a table of all objects this frame has created via xml (useful if you'd like to access all of them for some reason)
#### Returns:
1. `table` table with objects
## setTheme
Sets the default theme of that frame children objects always try to get the theme of its parent frame, if it does not exist it goes to its parent parent frame, and so on until it reaches the basalt managers theme - which is sotred in theme.lua (Please checkout [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for how it could look like.
#### Parameters:
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds a new theme which only changes the default color of buttons.
```lua
local myFrame = basalt.createFrame():setTheme({
ButtonBG = colors.yellow,
ButtonText = colors.red,
})
```
## setScrollable
Makes the frame scrollable with mousewheel.
#### Parameters:
1. `bool` scrollable or not
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable
```lua
local myFrame = basalt.createFrame():setScrollable()
```
```xml
<frame scrollable="true"></frame>
```
## setMinScroll
Sets the minimum offset it is allowed to scroll (default 0)
#### Parameters:
1. `number` minimum y offset
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and sets the minimum amount to -5
```lua
local myFrame = basalt.createFrame():setScrollable():setMinScroll(-5)
```
```xml
<frame minScroll="-5"></frame>
```
## setMaxScroll
Sets the maximum offset it is allowed to scroll (default 10)
#### Parameters:
1. `number` maximum y offset
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and sets the maximum amount to 25
```lua
local myFrame = basalt.createFrame():setScrollable():setMaxScroll(25)
```
```xml
<frame maxScroll="25"></frame>
```
## setImportantScroll
By default if you hovering your mouse over children objects, you wont scroll the frame, if you set this to true the frame scrolling becomes more important
#### Parameters:
1. `bool` important or not
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and defines it as important
```lua
local myFrame = basalt.createFrame():setScrollable():setImportantScroll(true)
```
```xml
<frame importantScroll="true"></frame>
```
# XML Example
*This is how you would implement frames via xml:
Frames are like groups or windows. You can add objects on them and if you move the frame, all its children objects will also be moved. Frames also have
some special functionality to create very advanced programs.
[Object](objects/Object.md) methods also apply for frames.
| | |
|---|---|
|[addObject](objects/Frame/addObject.md)|Adds a new object
|[setBar](objects/Frame/setBar.md)|Sets the top bar text and colors - deprecated
|[setBarTextAlign](objects/Frame/setBarTextAlign.md)|Sets the top bars text align - deprecated
|[showBar](objects/Frame/showBar.md)|Shows the top bar - deprecated
|[setMonitor](objects/Frame/setMonitor.md)|Sets the frame to be a monitor frame (only for base frames)
|[setMirror](objects/Frame/setMirror.md)|Sets the frame to mirror onto a monitor (only for base frames)
|[getObject](objects/Frame/getObject.md)|Returns the object by its name (or id)
|[removeObject](objects/Frame/removeObject.md)|Removes the object by its name (or id)
|[setFocusedObject](objects/Frame/setFocusedObject.md)|Sets the currently focused object by this frame
|[removeFocusedObject](objects/Frame/removeFocusedObject.md)|Removes the currenlty focused object (it only removes beeing focused)
|[getFocusedObject](objects/Frame/getFocusedObject.md)|Returns the currently focused object
|[setMovable](objects/Frame/setMovable.md)|Makes the frame movable (only for sub frames)
|[setOffset](objects/Frame/setOffset.md)|Sets the frames offset (will be added to the childrens x and y positions)
|[getOffset](objects/Frame/getOffset.md)|Returns the current x and y offset
|[addLayout](objects/Frame/addLayout.md)|Adds a new XML Layout into the frame
|[addLayoutFromString](objects/Frame/addLayoutFromString.md)|Adds a new XML Layout via string into the frame
|[getLastLayout](objects/Frame/getLastLayout.md)|Returns a table of all objects generated by the last addLayout/FromString method
|[setTheme](objects/Frame/setTheme.md)|Sets the theme of that frame and all its childrens
|[setScrollable](objects/Frame/setScrollable.md)|Makes the frame scrollable via mousewheel (internally this uses setOffset)
|[setScrollAmount](objects/Frame/setScrollAmount.md)|Sets how far the user is allowed to scroll
This is how you would implement frames via xml:
```xml
<frame>
<frame width="50%" bg="red">
<frame width="parent.w * 0.5" bg="red">
<button x="2" y="2" width="17" text="Example Button!"/>
</frame>
<frame x="50%+1" width="50%+1" bg="black">
<textfield bg="green" x="2" width="100%-2" />
<frame x="parent.w * 0.5 + 1" width="parent.w * 0.5 +1" bg="black">
<textfield bg="green" x="2" width="parent.w-2" />
</frame>
</frame>
```
```

View File

@@ -0,0 +1,17 @@
## addLayout
Adds a new XML Layout into your frame.
#### Parameters:
1. `string` Path to your layout
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayout("mainframe.xml")
```
```xml
<frame layout="mainframe.xml"></frame>
```

View File

@@ -0,0 +1,14 @@
## addLayoutFromString
Adds a new XML Layout as string into your frame.
#### Parameters:
1. `string` xml
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayoutFromString("<button x='12' y='5' bg='black' />")
```

View File

@@ -0,0 +1,18 @@
## add&#60;Object&#62;
Adds a new object. Don't use add&#60;Object&#62; please use addTheObjectYouNeed For example if you want a new Frame, use
addFrame, if you want to add a button, use addButton
#### Parameters:
1. `string` optional - the id if you don't add a id it will autimatically generate one for you
#### Returns:
1. `object` The new object you've created
#### Usage:
* Creates some example objects
```lua
local main = basalt.createFrame()
local button = main:addButton()
local label = main:addLabel()
local frame = main:addFrame()
```

View File

@@ -0,0 +1,11 @@
## getFocusedObject
Gets the currently focused object
#### Returns:
1. `object` The currently focused object
#### Usage:
* Gets the currently focused object from the frame, storing it in a variable
```lua
local focusedObject = myFrame:getFocusedObject()
```

View File

@@ -0,0 +1,5 @@
## getLastLayout
returns a table of all objects this frame has created via xml (useful if you'd like to access all of them for some reason)
#### Returns:
1. `table` table with objects

View File

@@ -0,0 +1,15 @@
## getObject
Returns a child object of the frame
#### Parameters:
1. `string` The name of the child object
#### Returns:
1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name
#### Usage:
* Adds a button with id "myFirstButton", then retrieves it again through the frame object
```lua
myFrame:addButton("myFirstButton")
local aButton = myFrame:getObject("myFirstButton")
```

View File

View File

@@ -0,0 +1,16 @@
## removeFocusedObject
Removes the focus of the supplied object
#### Parameters:
1. `object` The child object to remove focus from
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new button then removes the focus from that button when clicking on it
```lua
local aButton = myFrame:addButton():setFocus():onClick(function()
myFrame:removeFocusedObject(aButton)
end)
```

View File

@@ -0,0 +1,15 @@
## removeObject
Removes a child object from the frame
#### Parameters:
1. `string` The name of the child object
#### Returns:
1. `boolean` Whether the object with the given name was properly removed
#### Usage:
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id
```lua
myFrame:addButton("myFirstButton")
myFrame:removeObject("myFirstButton")
```

View File

@@ -0,0 +1,30 @@
## setBar
Sets the text, background, and foreground of the upper bar of the frame, accordingly.
#### Parameters:
1. `string` The title text to set the bar to
2. `number` The background color
2. `number` The foreground color
#### Returns:
1. `frame` The frame being used
#### Usage:
* Set the title to "My first frame!", with a background of black and a foreground of light gray.
```lua
frame:setBar("My first Frame!", colors.black, colors.lightGray)
```
* Store the frame, use the named frame variable after assigning.
```lua
local mainFrame = basalt.createFrame()
local myFrame = MainFrame:addFrame()
myFrame:setBar("My first Frame!")
```
* This abuses the call-chaining that Basalt uses.
```lua
local mainFrame = basalt.createFrame()
local myFrame = mainFrame:addFrame():setBar("My first Frame!")
```
```xml
<frame barText="My first Frame!" barBG="black" barFG="lightGray"></frame>
```

View File

@@ -0,0 +1,17 @@
## setBarTextAlign
Sets the frame's bar-text alignment
#### Parameters:
1. `string` Can be supplied with "left", "center", or "right"
#### Returns:
1. `frame` The frame being used
#### Usage:
* Set the title of myFrame to "My first frame!", and align it to the right.
```lua
myFrame:setBar("My first Frame!"):setBarTextAlign("right")
```
```xml
<frame barAlign="right"></frame>
```

View File

@@ -0,0 +1,15 @@
## setFocusedObject
Sets the currently focused object
#### Parameters:
1. `object` The child object to focus on
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new button, sets the focused object to the previously mentioned button
```lua
local aButton = myFrame:addButton()
myFrame:setFocusedObject(aButton)
```

View File

@@ -0,0 +1,17 @@
## setMirror
mirrors this frame to another peripheral monitor object.
#### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates mirror of your main frame to a monitor on the left side.
```lua
local mainFrame = basalt.createFrame():setMirror("left")
```
```xml
<frame mirror="left"></frame>
```

View File

@@ -0,0 +1,19 @@
## setMonitor
Sets this frame as a monitor frame
#### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new monitor frame, you can use to show objects on a monitor.
```lua
local mainFrame = basalt.createFrame()
local monitorFrame = basalt.createFrame():setMonitor("right")
monitorFrame:setBar("Monitor 1"):showBar()
```
```xml
<frame monitor="right"></frame>
```

View File

@@ -0,0 +1,17 @@
## setMovable
Sets whether the frame can be moved. _In order to move the frame click and drag the upper bar of the frame_
#### Parameters:
1. `boolean` Whether the object is movable
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable
```lua
local myFrame = basalt.createFrame():setMovable(true)
```
```xml
<frame moveable="true"></frame>
```

View File

@@ -0,0 +1,25 @@
## setOffset
Sets the frame's coordinate offset. The frame's child objects will receive the frame's coordinate offset. For example, when using a scrollbar, if you use its value to add an offset to a frame, you will get a scrollable frame.
Objects are also able to ignore the offset by using :ignoreOffset() (For example, you may want to ignore the offset on the scrollbar itself)
The function can also be supplied with negative values
#### Parameters:
1. `number` The x direction offset (+/-)
2. `number` The y direction offset (+/-)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame with x offset of 5 and a y offset of 3
```lua
local myFrame = basalt.createFrame():setOffset(5, 3)
```
* Creates with x offset of 5 and a y offset of -5 (Meaning if you added a button with y position 5, it would be at y position 0)
```lua
local myFrame = basalt.createFrame():setOffset(5, -5)
```
```xml
<frame xOffset="5" yOffset="-5"></frame>
```

View File

@@ -0,0 +1,17 @@
## setScrollAmount
Sets the maximum offset it is allowed to scroll
#### Parameters:
1. `number` maximum y offset
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and sets the maximum amount to 25
```lua
local myFrame = basalt.createFrame():setScrollable():setScrollAmount(25)
```
```xml
<frame scrollAmount="25"></frame>
```

Some files were not shown because too many files have changed in this diff Show More