←  APIs and Utilities

ComputerCraft | Programmable Computers for Minecraft

»

Bedrock - The Complete GUI Framework

oeed's Photo oeed 20 Jul 2014

What is Bedrock?

Bedrock is an extremely advanced and powerful framework for developing beautiful, easy to use ComputerCraft programs. Not only does it make for a more pleasant experience for the user, by coding programs with Bedrock removes the need for you, the developer, to wrangle with low level aspects of programs. With Bedrock file sizes are also significantly lower than previously due to huge amounts of code, that would have previously made your program huge bigger, being in one central API. A single line of code is all that is needed to download and install Bedrock, and if Bedrock was already installed by another program it will use that version, saving precious disk space.

Bedrock is designed to be similar to existing interface frameworks such as Apple’s Cocoa, the framework used to develop the majority of iOS and OS X. I’m sure that it will also be similar to others such as .NET and possible Java, but I’m not very familiar with them. If you’ve used these in the past, Bedrock should be pretty easy to pickup, if you haven’t, don’t worry. It may take some time to work it out, but once you do you’ll be able to create better programs in record time.

It's hard to explain just what Bedrock is really. Take a look at the tutorial (link at the bottom of the post) for a more detailed description and example code.

What objects does it support?
  • Buttons
  • CollectionViews (think the icon view in OneOS's Files)
  • ImageViews
  • Labels
  • ListViews
  • Menus
  • ProgressBars (including multiple values and colours, think the storage usage bar in About OneOS)
  • ScrollBars (these are automatically handled by ScrollViews though)
  • ScrollViews
  • Separator (just single line)
  • TextBox
  • Windows
Bedrock also makes it very easy to make your own objects. For example, in OneOS the thing that draws programs is actually just a custom object.

What are the benefits of Bedrock?

Bedrock is designed to be very quick and easy to use, yet very powerful. It only takes a matter of minutes to learn how to use it and will save you hours in the long run.
One of Bedrock's main goals is to reduce the amount of code you need to write. I've personally found that programs I use Bedrock are normally a third the number of lines, and that doesn't include having to write the APIs in the first place.

What are some programs made with Bedrock?
If you made a program with Bedrock let me know, I’ll add you to the list!

- OneOS - OneOS and most of it’s programs were entirely coded using Bedrock. Anything that OneOS does you can do with ease.
- Your next program?

Installation/Download

If you want to just take a look at the code you should use the GitHub repo. https://github.com/oeed/Bedrock

Installation is very easy, simply add this line to the top of your file and it will automatically download and load the API.
local bedrockPath='/' if OneOS then OneOS.LoadAPI('/System/API/Bedrock.lua', false)elseif fs.exists(bedrockPath..'/Bedrock')then os.loadAPI(bedrockPath..'/Bedrock')else if http then print('Downloading Bedrock...')local h=http.get('http://pastebin.com/raw.php?i=0MgKNqpN')if h then local f=fs.open(bedrockPath..'/Bedrock','w')f.write(h.readAll())f.close()h.close()os.loadAPI(bedrockPath..'/Bedrock')else error('Failed to download Bedrock. Is your internet working?') end else error('This program needs to download Bedrock to work. Please enable HTTP.') end end if Bedrock then Bedrock.BasePath = bedrockPath Bedrock.ProgramPath = shell.getRunningProgram() end

How to use it.

Bedrock is quite different to most other APIs/frameworks. I've made a very sizeable tutorial which I highly recommend you read. At this stage the tutorial is the only documentation.
Edited by oeed, 29 November 2014 - 10:29 AM.
Quote

Geforce Fan's Photo Geforce Fan 20 Jul 2014

Huh. Looks cool. I'll look into this later... this could save me a LOT of trouble in Sapphari(and pretty much do everything for me...)
Although it seems it's not all in one file. This could bring problems if using an online version.
Edited by Geforce Fan, 20 July 2014 - 03:01 AM.
Quote

oeed's Photo oeed 20 Jul 2014

View PostGeforce Fan, on 20 July 2014 - 02:59 AM, said:

Huh. Looks cool. I'll look into this later... this could save me a LOT of trouble in Sapphari(and pretty much do everything for me...)
Although it seems it's not all in one file. This could bring problems if using an online version.
It's one single file, it puts the APIs as strings so it functions as if they are separate though.
It's all in this file.
Quote

LDShadowLord's Photo LDShadowLord 20 Jul 2014

Hmmm, I may adopt this. It will save me the hassle of trying to shoe-horn a GUI system into Colligo.
Quote

Win7yes's Photo Win7yes 20 Jul 2014

How do you make the program stop running?
Quote

oeed's Photo oeed 20 Jul 2014

View PostWin7yes, on 20 July 2014 - 10:35 AM, said:

How do you make the program stop running?
Use program:Quit()
At the moment it doesn't clear the screen or anything though (IIRC).
Quote

logsys's Photo logsys 20 Jul 2014

Very powerful and useful! Everyone's programs should use it
Quote

Win7yes's Photo Win7yes 20 Jul 2014

View Postoeed, on 20 July 2014 - 11:56 AM, said:

View PostWin7yes, on 20 July 2014 - 10:35 AM, said:

How do you make the program stop running?
Use program:Quit()
At the moment it doesn't clear the screen or anything though (IIRC).
Edit: Nevermind, I had an useless if statement in the middle of the code wich broke everything.
Edited by Win7yes, 20 July 2014 - 07:29 PM.
Quote

oeed's Photo oeed 20 Jul 2014

View PostWin7yes, on 20 July 2014 - 07:25 PM, said:

View Postoeed, on 20 July 2014 - 11:56 AM, said:

View PostWin7yes, on 20 July 2014 - 10:35 AM, said:

How do you make the program stop running?
Use program:Quit()
At the moment it doesn't clear the screen or anything though (IIRC).
Edit: Nevermind, I had an useless if statement in the middle of the code wich broke everything.
What was it? I might be able to add an error telling you how to fix it.
Quote

sjkeegs's Photo sjkeegs 21 Jul 2014

Does this have any dependency on any version of ComputerCraft. I'm still using 1.58.
Quote

Win7yes's Photo Win7yes 21 Jul 2014

View Postoeed, on 20 July 2014 - 09:56 PM, said:

View PostWin7yes, on 20 July 2014 - 07:25 PM, said:

View Postoeed, on 20 July 2014 - 11:56 AM, said:

View PostWin7yes, on 20 July 2014 - 10:35 AM, said:

How do you make the program stop running?
Use program:Quit()
At the moment it doesn't clear the screen or anything though (IIRC).
Edit: Nevermind, I had an useless if statement in the middle of the code wich broke everything.
What was it? I might be able to add an error telling you how to fix it.
I made an Alert Box be displayed when a button is clicked, and before adding the code to close the program by pressing the button of the box, I left some code that
was supposed to close the Alert Box, And that wrecked up everything making the program only close the Alert Box, but not the program itself. It was something like this
if program:Window then
or something like that.
By the way, Is there any way to "switch" views?
Quote

oeed's Photo oeed 21 Jul 2014

View Postsjkeegs, on 21 July 2014 - 01:39 AM, said:

Does this have any dependency on any version of ComputerCraft. I'm still using 1.58.
Bedrock should work on all versions of CC that support colour. Let me know if you find an issue.

View PostWin7yes, on 21 July 2014 - 02:05 AM, said:

I made an Alert Box be displayed when a button is clicked, and before adding the code to close the program by pressing the button of the box, I left some code that
was supposed to close the Alert Box, And that wrecked up everything making the program only close the Alert Box, but not the program itself. It was something like this
if program:Window then
or something like that.
By the way, Is there any way to "switch" views?
First, in future please make help posts on the tutorial post. It just keeps things more tidy.

I don't completely get what you're saying, but Alert Boxes should close themselves when you click a button (let me know if they're not).

If you want an alert box to close your program you should (haven't tested) be able to do something like this:
program:GetObject('HelloButton').OnClick = function(self, event, side, x, y)
program:DisplayAlertWindow('Quit?', 'Are you sure you want to quit?', {'Quit', 'Cancel'}, function(value)
if value == 'Quit' then
program:Quit()
end
end)
end

Yes, there is. I forgot to mention that in the tutorial.

Simply do this:
program:LoadView('viewname') --without the .view
Quote

Win7yes's Photo Win7yes 21 Jul 2014

No but I mean I left some things that made the program:Quit() fail to close and it just closed the Alert box. And Sorry :P I will make help posts in the tutorial
topic in the future
Quote

oeed's Photo oeed 21 Jul 2014

View PostWin7yes, on 21 July 2014 - 02:46 AM, said:

No but I mean I left some things that made the program:Quit() fail to close and it just closed the Alert box. And Sorry :P I will make help posts in the tutorial
topic in the future

Oh I see, can you give some example code? (post in the tut. topic)
Quote

daawsomest's Photo daawsomest 22 Jul 2014

Hello,

This framework looks awesome and will be very helpful for my current projects, but I can't get it working. I have tried multiple times on different CC computers with no luck. The error I get is "No loaded view. You need to do program:LoadView first". I have created a main view and was under the assumption that it would be loaded automatically.

Screenshots:
Spoiler
Quote

oeed's Photo oeed 23 Jul 2014

View Postdaawsomest, on 22 July 2014 - 11:11 PM, said:

Hello,

This framework looks awesome and will be very helpful for my current projects, but I can't get it working. I have tried multiple times on different CC computers with no luck. The error I get is "No loaded view. You need to do program:LoadView first". I have created a main view and was under the assumption that it would be loaded automatically.

Screenshots:
Spoiler
Sorry for the late reply, I didn't get a notification for some reason.

That is strange, there's nothing that seems to be incorrect.

Looking at Bedrock's code I'm pretty sure that the only way this could've happened is it think the file doesn't exist.
For now, try doing this at the top of the program:Run function.
program:LoadView('main')
Let me know if it works/has an error.

If possible could you upload a zip file of the computer so I can see whats wrong?
Quote

Win7yes's Photo Win7yes 23 Jul 2014

It happend to me too when I started making my OneOS Log Displayer (By the way I need help to make it work on OneOS. And the scroll textbox thing). It said that I needed to load it first with program:LoadView and I added program:LoadView("main") to the code and it worked. Didn't report it because I thought it wasn't like a big thing.
Quote

oeed's Photo oeed 24 Jul 2014

View PostWin7yes, on 23 July 2014 - 10:52 PM, said:

It happend to me too when I started making my OneOS Log Displayer (By the way I need help to make it work on OneOS. And the scroll textbox thing). It said that I needed to load it first with program:LoadView and I added program:LoadView("main") to the code and it worked. Didn't report it because I thought it wasn't like a big thing.
Hmm ok, could you, at some point, send the files to me. I'd like to get that fixed. I'm rather busy at the moment, but I'll try to help if I can.
Quote

Win7yes's Photo Win7yes 24 Jul 2014

Is it ok if I put the files in a ZIP and upload the ZIP somewhere? (Somewhere like Google Drive. Or to be more specific, Google Drive)
Edited by Win7yes, 24 July 2014 - 01:39 AM.
Quote

oeed's Photo oeed 24 Jul 2014

View PostWin7yes, on 24 July 2014 - 01:22 AM, said:

Is it ok if I put the files in a ZIP and upload the ZIP somewhere? (Somewhere like Google Drive. Or to be more specific, Google Drive)
Yea sure, I'd just like to see if I can figure out what the issue is.
Quote