Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --let's say the API is in /fsEAPI
- os.loadAPI("/fsEAPI")
- --make a table for the items, this is necessary
- local items = {}
- local debug = fs.open("/debug", "w")
- --add a button to the screen, labeled 'myButton' --> items['myButton']
- fsEAPI.addButton(items, "myButton", "Button", 6, 2, 2)
- --add a textbox to the screen, labeled 'myTextBox' --> items['myTextBox']
- fsEAPI.addTextBox(items, "myTextBox", "Edit me senpai", 20, 2, 4)
- --add a scrollbox to the screen, labeled 'myScrollBox' --> items['myScrollBox']
- fsEAPI.addScrollBox(items, "myScrollBox", 20, 3, 2, 6)
- --add a label
- fsEAPI.addLabel(items, "myLabel", "Hello, World!", 20, 2, 10)
- --add 'Hello' into the scrollbox
- fsEAPI.addChild(items['myScrollBox'], "Hello")
- --add 'My' into the scrollbox
- fsEAPI.addChild(items['myScrollBox'], "My")
- --add 'Friend' into the scrollbox
- fsEAPI.addChild(items['myScrollBox'], "Friend")
- --add 'Lolz' into the scrollbox
- fsEAPI.addChild(items['myScrollBox'], "Lolz")
- --add a context menu for the scrollbox, containing "Open" and "Delete"
- --'bg' is the backgroundcolor and 'fg' is the textcolor
- local list = {
- {
- text = "Open",
- bg = colors.white,
- fg = colors.blue,
- },
- {
- text = "Delete",
- bg = colors.white,
- fg = colors.red,
- },
- }
- --now create a context menu for that scrollbox giving the made list
- local ok, err = fsEAPI.addContextMenu(items['myScrollBox'], list)
- --preselect an item in myScrollBox, 2 should be 'My'
- items['myScrollBox'].childs[2].selected = true
- --clear the screen and draw every child
- fsEAPI.updateAll(items, colors.black)
- --Everything should be drawn on a black screen now
- --Now create a coroutine for reading the events so you can still process the information, you don't have to do that tho, you can use parallel too for example
- local c = coroutine.create(fsEAPI.run)
- --the way my API is made, it works by just resuming the coroutine with the table for "initializing"
- coroutine.resume(c, items)
- --this coroutine has your table now loaded and returns events just for that table
- --now start reading events and process the output
- local file = fs.open("/log", "w")
- --for testing purposes, we'll log the events
- --create a table for events (e.g. mouseclicks)
- local evt = {}
- --initialize a loop
- while true do
- coroutine.resume(c, unpack(evt))
- evt = {os.pullEvent()}
- --now check if your coroutine returned any button clicks
- if evt[1] == "button_press" then
- --if a button was pressed
- --log that and the name (key) of the button
- file.writeLine("Button: "..evt[3].." was pressed.")
- file.flush()
- elseif evt[1] == "scrollBox_select" then
- --if an item in the myScrollBox was selected
- --log that and the name (table.text) of the item
- file.writeLine("Item: "..evt[3]..": child: "..items[evt[3]].childs[evt[4]].text.." was selected.")
- file.flush()
- --edit the text of myLabel to the selected item and update
- items["myLabel"].text = items[evt[3]].childs[evt[4]].text
- fsEAPI.update(items.myLabel)
- elseif evt[1] == "context_select" and evt[2] == "myScrollBox" then
- --if something inside the context window (specificly from myScrollBox) is clicked, log that
- file.writeLine("Item: "..evt[2]..": child: "..items.myScrollBox.childs[evt[3]].text.." context: "..evt[4].." was clicked.")
- file.flush()
- if evt[4] == "Delete" then
- fsEAPI.removeChild(items.myScrollBox, evt[3])
- fsEAPI.update(items.myScrollBox)
- end
- elseif evt[1] == "textBox_input" and evt[3] == "myTextBox" then
- --if something was written in the textbox, log it and add a new child to the scrollbox
- file.writeLine("Item: "..evt[3].." was edited.")
- file.flush()
- fsEAPI.addChild(items.myScrollBox, items.myTextBox.text)
- fsEAPI.update(items.myScrollBox)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement