From b6c5531290fc37e9e031149eafeca9eb56886782 Mon Sep 17 00:00:00 2001
From: Robert Jelic <36573031+NoryiE@users.noreply.github.com>
Date: Fri, 26 Aug 2022 21:13:19 +0200
Subject: [PATCH] example changes and cursor bugfix
---
Basalt/objects/Input.lua | 3 +++
Basalt/objects/Textfield.lua | 4 ++++
examples/basaltPreview.lua | 14 +++++++-------
examples/basaltPreview2.lua | 7 ++++++-
examples/basaltPreview2.xml | 22 +++++++++++-----------
examples/progressBarEnergyExample.lua | 17 ++++++++---------
examples/redstoneAnalogOutput.lua | 2 +-
7 files changed, 40 insertions(+), 29 deletions(-)
diff --git a/Basalt/objects/Input.lua b/Basalt/objects/Input.lua
index 654481c..32e2e99 100644
--- a/Basalt/objects/Input.lua
+++ b/Basalt/objects/Input.lua
@@ -332,6 +332,9 @@ return function(name)
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
end
end,
diff --git a/Basalt/objects/Textfield.lua b/Basalt/objects/Textfield.lua
index c9c59ba..2516e01 100644
--- a/Basalt/objects/Textfield.lua
+++ b/Basalt/objects/Textfield.lua
@@ -596,6 +596,10 @@ return function(name)
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
end
end,
diff --git a/examples/basaltPreview.lua b/examples/basaltPreview.lua
index 5646d46..1018e8d 100644
--- a/examples/basaltPreview.lua
+++ b/examples/basaltPreview.lua
@@ -1,17 +1,17 @@
--Basalt configurated installer
-local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
+local filePath = "basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
-local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
+local basalt = require(filePath:gsub(".lua", ""))
local w, h = term.getSize()
-local main = basalt.createFrame("mainFrame"):show()
-local objFrame = main:addFrame("objectFrame"):setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-1):show()
-local programFrame = main:addFrame("programFrame"):setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-1)
-local editorFrame = main:addFrame("editorFrame"):setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-1)
+local main = basalt.createFrame("mainFrame")
+local objFrame = main:addFrame("objectFrame"):setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-1)
+local programFrame = main:addFrame("programFrame"):setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-1):hide()
+local editorFrame = main:addFrame("editorFrame"):setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-1):hide()
local menuBar = main:addMenubar("mainMenuBar"):addItem("Object"):addItem("Program"):addItem("Editor"):setBackground(colors.gray):setSize(w, 1):setSpace(5):setScrollable():show()
menuBar:onChange(function(self)
@@ -67,7 +67,7 @@ end):start()
--Program Frame:
local programCount = 1
visualButton(programFrame:addButton("exampleButton"):setText("Add Shell"):setSize(13,3):setPosition(2,2):onClick(function()
- local newProgramWindow = programFrame:addFrame("programFrame"..programCount):setMoveable(true):setBar("Console", colors.black, colors.lightGray):showBar():setPosition(3,3):setSize(26,12):show()
+ local newProgramWindow = programFrame:addFrame("programFrame"..programCount):setMovable(true):setBar("Console", colors.black, colors.lightGray):showBar():setPosition(3,3):setSize(26,12):show()
local program = newProgramWindow:addProgram("exampleProgram"..programCount):setSize(26,11):setPosition(1,2):setBackground(colors.black):show()
program:execute("rom/programs/shell.lua")
programCount = programCount + 1
diff --git a/examples/basaltPreview2.lua b/examples/basaltPreview2.lua
index 5f3da3f..c3b0220 100644
--- a/examples/basaltPreview2.lua
+++ b/examples/basaltPreview2.lua
@@ -1,4 +1,9 @@
-local basalt = require("Basalt")
+--Basalt configurated installer
+local filePath = "basalt.lua" --here you can change the file path default: basalt
+if not(fs.exists(filePath))then
+ shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
+end
+local basalt = require(filePath:gsub(".lua", ""))
basalt.setVariable("buttonColor", basalt.schedule(function(self)
self:setBackground(colors.black)
diff --git a/examples/basaltPreview2.xml b/examples/basaltPreview2.xml
index f544727..bbcbdfe 100644
--- a/examples/basaltPreview2.xml
+++ b/examples/basaltPreview2.xml
@@ -1,9 +1,9 @@
-
-
+
+
-
+
@@ -11,7 +11,7 @@
-
+
- Radio 121black
@@ -29,13 +29,13 @@
-
+
-
+
- Entry 1
@@ -71,7 +71,7 @@
-
+
@@ -142,7 +142,7 @@
-
+
@@ -185,13 +185,13 @@
-
+
-
+
-
+
diff --git a/examples/progressBarEnergyExample.lua b/examples/progressBarEnergyExample.lua
index f1431aa..ca68795 100644
--- a/examples/progressBarEnergyExample.lua
+++ b/examples/progressBarEnergyExample.lua
@@ -1,30 +1,29 @@
-- This is a example on how to use progressbars for energy. I used the Mekanism Ultimate Energy Cube.
-local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
+--Basalt configurated installer
+local filePath = "basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
- shell.run("pastebin run ESs1mg7P packed true "..filePath) -- this is an alternative to the wget command
+ shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
-local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
+local basalt = require(filePath:gsub(".lua", ""))
local energyCube = peripheral.find("ultimateEnergyCube")
-local main = basalt.createFrame("main"):show()
+local main = basalt.createFrame()
-local progressText = main:addLabel("currentEnergyValue")
+local progressText = main:addLabel()
:setText(0)
:setForeground(colors.gray)
:setBackground(false)
:setPosition(10, 3)
:setZIndex(6)
- :show()
-local energyProgress = main:addProgressbar("mainEnergyCube")
+local energyProgress = main:addProgressbar()
:setSize(20,3)
:setPosition(2,2)
:setBackground(colors.black)
:setProgressBar(colors.green)
- :show()
energyProgress:onChange(function()
local energy = tostring(energyCube.getEnergy())
@@ -47,6 +46,6 @@ local function checkCurrentEnergy()
end
end
-main:addThread("energyThread"):start(checkCurrentEnergy)
+main:addThread():start(checkCurrentEnergy)
basalt.autoUpdate()
diff --git a/examples/redstoneAnalogOutput.lua b/examples/redstoneAnalogOutput.lua
index 41ddc99..f0dd29a 100644
--- a/examples/redstoneAnalogOutput.lua
+++ b/examples/redstoneAnalogOutput.lua
@@ -20,7 +20,7 @@ local sub = main:addFrame()
local rFrame = sub:addFrame("redstoneFrame")
:setPosition(1,1)
:setSize(25,5)
- :setMoveable(true) -- the next release of Basalt will fix spelling to :setMovable
+ :setMovable(true)
:setBackground(colours.red)
-- Redstone Analog Output