diff --git a/Basalt/objects/Textfield.lua b/Basalt/objects/Textfield.lua index bef156d..09f0715 100644 --- a/Basalt/objects/Textfield.lua +++ b/Basalt/objects/Textfield.lua @@ -34,9 +34,9 @@ return function(name) return pos end - local function updateColors() - local fgLine = tHex[base.fgColor]:rep(fgLines[textY]:len()) - local bgLine = tHex[base.bgColor]:rep(bgLines[textY]:len()) + local function updateColors(self) + local fgLine = tHex[self.fgColor]:rep(fgLines[textY]:len()) + local bgLine = tHex[self.bgColor]:rep(bgLines[textY]:len()) for k,v in pairs(rules)do local pos = stringGetPositions(lines[textY], v[1]) if(#pos>0)then @@ -68,8 +68,8 @@ return function(name) local object = { init = function(self) - base.bgColor = self.parent:getTheme("TextfieldBG") - base.fgColor = self.parent:getTheme("TextfieldText") + self.bgColor = self.parent:getTheme("TextfieldBG") + self.fgColor = self.parent:getTheme("TextfieldText") end, getType = function(self) return objectType @@ -78,8 +78,8 @@ return function(name) setValuesByXMLData = function(self, data) base.setValuesByXMLData(self, data) if(data["lines"]~=nil)then - for k,v in pairs(data["lines"])do - self:addLine(xmlValue("line", v)) + for k,v in pairs(data["lines"]["line"])do + self:addLine(v:value()) end end if(data["keywords"]~=nil)then @@ -100,13 +100,13 @@ return function(name) end end if(data["rules"]~=nil)then - if(data["rules"]["item"]~=nil)then - local tab = data["rules"]["item"] - if(data["rules"]["item"].properties~=nil)then tab = {data["rules"]["item"]} end + if(data["rules"]["rule"]~=nil)then + local tab = data["rules"]["rule"] + if(data["rules"]["rule"].properties~=nil)then tab = {data["rules"]["rule"]} end for k,v in pairs(tab)do - if(xmlValue("rule", v)~=nil)then - self:addRule(xmlValue("rule", v), colors[xmlValue("fg", v)], colors[xmlValue("bg", v)]) + if(xmlValue("pattern", v)~=nil)then + self:addRule(xmlValue("pattern", v), colors[xmlValue("fg", v)], colors[xmlValue("bg", v)]) end end end @@ -118,7 +118,7 @@ return function(name) end; getLine = function(self, index) - return lines[index] or "" + return lines[index] end; editLine = function(self, index, text) @@ -127,10 +127,22 @@ return function(name) end; addLine = function(self, text, index) - if (index ~= nil) then - table.insert(lines, index, text) - else - table.insert(lines, text) + if(text~=nil)then + if(#lines==1)and(lines[1]=="")then + lines[1] = text + bgLines[1] = tHex[self.bgColor]:rep(text:len()) + fgLines[1] = tHex[self.fgColor]:rep(text:len()) + return self + end + if (index ~= nil) then + table.insert(lines, index, text) + table.insert(bgLines, index, tHex[self.bgColor]:rep(text:len())) + table.insert(fgLines, tHex[self.fgColor]:rep(text:len())) + else + table.insert(lines, text) + table.insert(bgLines, tHex[self.bgColor]:rep(text:len())) + table.insert(fgLines, tHex[self.fgColor]:rep(text:len())) + end end return self end; @@ -253,7 +265,7 @@ return function(name) if (textY < hIndex) then hIndex = hIndex - 1 end - updateColors() + updateColors(self) self:setValue("") end @@ -271,7 +283,7 @@ return function(name) fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. fgLines[textY]:sub(textX + 1, fgLines[textY]:len()) bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. bgLines[textY]:sub(textX + 1, bgLines[textY]:len()) end - updateColors() + updateColors(self) end if (key == keys.enter) then @@ -380,7 +392,7 @@ return function(name) if (textX >= w + wIndex) then wIndex = wIndex + 1 end - updateColors() + updateColors(self) self:setValue("") end diff --git a/docs/objects/Button.md b/docs/objects/Button.md index d093a71..c4894b8 100644 --- a/docs/objects/Button.md +++ b/docs/objects/Button.md @@ -13,8 +13,12 @@ Sets the displayed button text #### Usage: * Creates a button with "Click me!" as text. ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local button = mainFrame:addButton("myFirstButton"):setText("Click me!"):show() +local mainFrame = basalt.createFrame() +local button = mainFrame:addButton():setText("Click me!") +``` + +```xml + +``` + ## hide Hides the object @@ -27,6 +32,11 @@ local button = mainFrame:addButton("myFirstButton"):setText("Close"):onClick(fun button:show() ``` +#### XML: +```xml + +``` + ## setPosition Changes the position relative to its parent frame #### Parameters: @@ -44,6 +54,11 @@ local mainFrame = basalt.createFrame("myFirstFrame"):show() mainFrame:addButton("myFirstButton"):setPosition(2,3) ``` +#### XML: +```xml + +``` + ## setBackground Changes the object background color, if you set the value to false the background wont be visible. For example you could see trough a frame. #### Parameters: @@ -58,6 +73,11 @@ Changes the object background color, if you set the value to false the backgroun local mainFrame = basalt.createFrame("myFirstFrame"):setBackground(colors.gray) ``` +#### XML: +```xml + +``` + ## setForeground Changes the object text color #### Parameters: @@ -72,6 +92,11 @@ Changes the object text color local mainFrame = basalt.createFrame("myFirstFrame"):setForeground(colors.green) ``` +#### XML: +```xml + +``` + ## setSize Changes the object size #### Parameters: @@ -88,6 +113,11 @@ local mainFrame = basalt.createFrame("myFirstFrame"):show() local subFrame = mainFrame:addFrame("myFirstSubFrame"):setSize(15,12):show() ``` +#### XML: +```xml + +``` + ## setFocus Sets the object to be the focused object. If you click on an object, it's normally automatically the focused object. For example, if you call :show() on a frame, and you want this particular frame to be in @@ -118,6 +148,12 @@ local aButton = mainFrame:addButton("myFirstButton"):setZIndex(1):setPosition(2, local aLabel = mainFrame:addButton("myFirstLabel"):setZIndex(2):setPosition(2,2):setText("I am a label!"):show() ``` +#### XML: +```xml + + +``` + ## setParent Sets the parent frame of the object #### Parameters: @@ -195,6 +231,11 @@ local aButton = mainFrame:addButton("myFirstButton") :show() ``` +#### XML: +```xml + +``` + ## getAbsolutePosition Converts the relative coordinates into absolute coordinates #### Parameters: @@ -212,26 +253,6 @@ local aButton = mainFrame:addButton("myFirstButton"):setSize(8,1):setPosition(4, basalt.debug(aButton:getAbsolutePosition()) -- returns 7,5 (frame coords + own coords) instead of 4,2 ``` -## setTextAlign -Sets the text align of the object (for example buttons) -#### Parameters: -1. `string` horizontal -2. `string` vertical ("left", "center", "right") - -#### Returns: -1. `object` The object in use - -#### Usage: -* Creates a button with text aligned to `right, center` -```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aButton = mainFrame:addButton("myFirstButton") - :setSize(12,3) - :setTextAlign("right", "center") - :setText("Don't...") - :show() -``` - ## setValue Sets the value of that object (input, label, checkbox, textfield, scrollbar,...) #### Parameters: @@ -247,6 +268,11 @@ local mainFrame = basalt.createFrame("myFirstFrame"):show() local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show() ``` +#### XML: +```xml + +``` + ## getValue Returns the currently saved value #### Returns: @@ -317,7 +343,11 @@ local subFrame = mainFrame:addFrame("mySubFrame") :setSize(18,6) :setShadow(colors.green) :showShadow(true) - :show() +``` + +#### XML: +```xml + ``` ## showShadow @@ -332,14 +362,19 @@ Shows or hides the shadow #### Usage: * Shows the shadow: ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local subFrame = mainFrame:addFrame("mySubFrame") +local mainFrame = basalt.createFrame():show() +local subFrame = mainFrame:addFrame() :setMoveable() :setSize(18,6) :showShadow(true) :show() ``` +#### XML: +```xml + +``` + ## setBorder Sets the border color - default: colors.black @@ -361,6 +396,11 @@ local subFrame = mainFrame:addFrame("mySubFrame") :show() ``` +#### XML: +```xml + +``` + ## showBorder Shows or hides the border @@ -377,6 +417,11 @@ local mainFrame = basalt.createFrame("myFirstFrame"):show() local subFrame = mainFrame:addFrame("mySubFrame") :setMoveable() :setSize(18,6) - :showBorder("left", "top", "right", "bottom") + :showBorder("left", "top", "bottom") :show() ``` + +#### XML: +```xml + +``` \ No newline at end of file diff --git a/docs/objects/Pane.md b/docs/objects/Pane.md index d5928b4..7f94152 100644 --- a/docs/objects/Pane.md +++ b/docs/objects/Pane.md @@ -8,9 +8,13 @@ Pane doesn't have any custom functionallity. If you want to change the color/pos ## Example: ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aPane = mainFrame:addPane("myFirstBackground") +local mainFrame = basalt.createFrame() +local aPane = mainFrame:addPane() aPane:setSize(30, 10) aPane:setBackground(colors.yellow) aPane:show() +``` + +```xml + ``` \ No newline at end of file diff --git a/docs/objects/Program.md b/docs/objects/Program.md index 4cef915..d5d8b5e 100644 --- a/docs/objects/Program.md +++ b/docs/objects/Program.md @@ -35,6 +35,11 @@ local aProgram = mainFrame:addProgram("myFirstProgram"):show() aProgram:execute("rom/programs/fun/worm.lua") -- executes worm ``` +#### XML: +```xml + +``` + ## stop Stops a currently running program diff --git a/docs/objects/Progressbar.md b/docs/objects/Progressbar.md index 82a8312..5a8e884 100644 --- a/docs/objects/Progressbar.md +++ b/docs/objects/Progressbar.md @@ -15,11 +15,15 @@ Sets the direction in which the bar should be expanding. #### Usage: * Creates a progressbar and sets the direction from bottom to top ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show() +local mainFrame = basalt.createFrame():show() +local aProgressbar = mainFrame:addProgressbar():show() aProgressbar:setDirection(3) ``` +```xml + +``` + ## setProgress This is the function you need to call if you want the progression to change. @@ -32,23 +36,22 @@ This is the function you need to call if you want the progression to change. #### Usage: * Creates a progressbar and sets the current progress to 50 ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show() +local mainFrame = basalt.createFrame():show() +local aProgressbar = mainFrame:addProgressbar():show() aProgressbar:setProgress(50) ``` ## getProgress Returns the current progress status - #### Returns: 1. `number` progress (0-100) #### Usage: * Creates a progressbar, sets the current progress to 50 and prints the current progress ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show() +local mainFrame = basalt.createFrame():show() +local aProgressbar = mainFrame:addProgressbar():show() aProgressbar:setProgress(50) basalt.debug(aProgressbar:getProgress()) ``` @@ -67,9 +70,13 @@ This function will change the visual display of your progress bar #### Usage: * Creates a progressbar and sets the progressbar color to green ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show() -aProgressbar:setProgressBar(colors.green) +local mainFrame = basalt.createFrame():show() +local aProgressbar = mainFrame:addProgressbar():show() +aProgressbar:setProgressBar(colors.green, colors.yellow, colors.red) +``` + +```xml + ``` ## setBackgroundSymbol @@ -84,11 +91,15 @@ Will change the default background symbol (default is " " - space) #### Usage: * Creates a progressbar and sets the progressbar background symbol to X ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show() +local mainFrame = basalt.createFrame():show() +local aProgressbar = mainFrame:addProgressbar():show() aProgressbar:setBackgroundSymbol("X") ``` +```xml + +``` + # Events # onProgressDone @@ -98,13 +109,30 @@ A custom event which gets triggered as soon as the progress reaches 100. Here is a example on how to add a onProgressDone event to your progressbar: ```lua -local basalt = dofile("basalt.lua") +local basalt = require("Basalt") -local mainFrame = basalt.createFrame("myMainFrame"):show() -local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show() +local mainFrame = basalt.createFrame():show() +local aProgressbar = mainFrame:addProgressbar():show() function progressDone() basalt.debug("The Progressbar reached 100%!") end aProgressbar:onProgressDone(progressDone) ``` + +## XML Example + +```lua +local basalt = require("Basalt") + +local mainFrame = basalt.createFrame() + +basalt.setVariable("progressDone", function() + basalt.debug("The Progressbar reached 100%!") +end) +``` + +```xml + +``` + diff --git a/docs/objects/Textfield.md b/docs/objects/Textfield.md index 1933df6..bfe2cab 100644 --- a/docs/objects/Textfield.md +++ b/docs/objects/Textfield.md @@ -55,8 +55,8 @@ basalt.debug(aTextfield:editLine(1, "Hello!")) Adds a line on index position #### Parameteres: -1. `number` index -2. `string` text +1. `string` text +2. `number` index #### Returns: 1. `object` The object in use @@ -66,7 +66,15 @@ Adds a line on index position ```lua local mainFrame = basalt.createFrame("myFirstFrame"):show() local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() -basalt.debug(aTextfield:addLine(1, "Hello!")) +basalt.debug(aTextfield:addLine("Hello!", 1)) +``` + +```xml + + + Hello! + + ``` ## removeLine @@ -93,3 +101,64 @@ Gets text cursor position #### Returns: 1. `number` x position 2. `number` y position + +## addKeywords +Adds keywords for special coloring + +#### Parameteres: +1. `number|color` color of your choice +2. `table` a list of keywords which should be colored example: {"if", "else", "then", "while", "do"} + +#### Returns: +1. `object` The object in use + +#### Usage: +* Changes the color of some words to purple +```lua +local mainFrame = basalt.createFrame() +local aTextfield = mainFrame:addTextfield():addKeywords(colors.purple, {"if", "else", "then", "while", "do", "hello"}) +``` + +```xml + + + + if + else + then + while + do + hello + + + +``` + +## addRule +Adds a new rule for special coloring + +#### Parameteres: +1. `string` a pattern - check out this page: (https://riptutorial.com/lua/example/20315/lua-pattern-matching) +2. `number|color` text color +3. `number|color` background color - optional + +#### Returns: +1. `object` The object in use + +#### Usage: +* Changes the color of all numbers +```lua +local mainFrame = basalt.createFrame() +local aTextfield = mainFrame:addTextfield():addRule("%d", colors.lightBlue) +``` + +```xml + + + + %d + lightBlue + + + +``` \ No newline at end of file diff --git a/docs/objects/Thread.md b/docs/objects/Thread.md index b41f3e0..3a8ab82 100644 --- a/docs/objects/Thread.md +++ b/docs/objects/Thread.md @@ -12,8 +12,8 @@ starts a new thread and executes the function #### Usage: * Starts a new thread ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aThread = mainFrame:addThread("myFirstThread"):show() +local mainFrame = basalt.createFrame() +local aThread = mainFrame:addThread() local function randomThreadFunction() while true do basalt.debug("Thread is active") @@ -21,6 +21,14 @@ local function randomThreadFunction() end end aThread:start(randomThreadfunction) +``` +```lua + basalt.setVariable("myThread", function() while true do os.sleep(1) end end) + +``` +```xml + + ``` ## stop @@ -32,8 +40,8 @@ stops the thread #### Usage: * Stops the current running thread by clicking on a button ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aThread = mainFrame:addThread("myFirstThread"):show() +local mainFrame = basalt.createFrame() +local aThread = mainFrame:addThread() local function randomThreadFunction() while true do basalt.debug("Thread is active") @@ -41,7 +49,7 @@ local function randomThreadFunction() end end aThread:start(randomThreadfunction) -local aButton = mainFrame:addButton("myFirstButton"):setText("Stop Thread"):onClick(function() aThread:stop() end):show() +local aButton = mainFrame:addButton():setText("Stop Thread"):onClick(function() aThread:stop() end) ``` ## getStatus @@ -52,7 +60,7 @@ gets the current thread status #### Usage: ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aThread = mainFrame:addThread("myFirstThread"):show() +local mainFrame = basalt.createFrame() +local aThread = mainFrame:addThread() basalt.debug(aThread:getStatus()) ```