Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Budj Demo
- By Dave-ee Jones
- --]]
- term.setBackgroundColor(colors.black)
- term.clear()
- -- Prepare Budj
- os.loadAPI("/budj")
- -- Budj stuff
- local board1 = budj.BOARD:new("Main")
- local button1 = budj.BUTTON:new(board1,"Button",2,2,14,6,colours.white,colors.blue,colors.lightBlue,true)
- local cb1 = budj.CHECKBOX:new(board1,"Checkbox",2,9,colours.white,colours.black,colours.white,colours.blue,colours.lightBlue)
- -- The function to be assigned to button1/checkbox
- -- Swaps the label of the given object
- local function swapLabel(o)
- if o.LABEL == "Button" then
- o:assignLabel("Button 2")
- elseif o.LABEL == "Button 2" then
- o:assignLabel("Button")
- elseif o.LABEL == "Checkbox" then
- o:assignLabel("Checkbox 2")
- elseif o.LABEL == "Checkbox 2" then
- o:assignLabel("Checkbox")
- end
- end
- -- Another function to be assigned to button1
- -- Toggles checkbox being drawn or not
- local function undrawObject(o)
- if o.DRAWN then
- o:undraw()
- else
- o:draw()
- end
- end
- -- More Budj stuff - but adjusting this time
- button1:alignLabel("centered")
- button1:assignFunction(function() undrawObject(cb1) end) -- Now, when you click the button it undraws the checkbox
- cb1:assignFunction(function() swapLabel(button1) end) -- When you toggle the checkbox it changes button1's label
- board1:draw()
- while true do
- -- Event handling, proudly supported by Budj
- local event = { os.pullEvent() }
- if event[1] == "key" and event[2] == keys.enter then
- break
- end
- local status, object, returned = budj.handleEvent(unpack(event))
- -- Ignore this clearing stuff, not important
- term.setCursorPos(1,12)
- term.clearLine()
- term.setCursorPos(1,13)
- term.clearLine()
- term.setCursorPos(1,14)
- term.clearLine()
- term.setCursorPos(1,15)
- term.clearLine()
- term.setCursorPos(1,12)
- print(status)
- -- It begins!
- if status then
- print("Object label: "..object.LABEL)
- if status ~= "wait" then
- print("Object's function returned: "..tostring(returned[1]))
- print("Object returned: "..tostring(returned[2]))
- end
- end
- end
- board1:undraw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement