This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Exerro's profile picture

Flare - The extensive, extendable UI library.

Started by Exerro, 18 August 2015 - 09:53 PM
Exerro #1
Posted 18 August 2015 - 11:53 PM
Flare is a UI library I've been working on for some time now. It's OOP based, meaning you create objects and manipulate the object itself rather than calling some other function with a label or ID.

When I say extensive, I'm referring to its large selection of UI elements you can use, and it's *amazing* animation library. When I say extendible, I'm referring to its easy to use internal API and ability to create your own objects (although undocumented atm). It's also unbelievably quick, quicker than I ever imagined in fact. I've been testing on a CCLite emulator with 101x35 resolution, and have never noticed any lag. However, what really showed it off is when I was testing the UITerminal element. I ran Flare inside itself 9 times, so that's flare in flare in flare in flare in flare in flare in flare in flare in flare in flare, and the lag was barely noticeable. On a normal computer, you'd run out of screen space before you noticed any lag.

Spoiler

So, let's get started. What does Flare actually do?

It's really easy to make a Flare application. Below is a small example:

require "UIButton"
local button = application.view:addChild( UIButton( 0, 0, 20, 5, "Hello world!" ) )
button.colour = colours.cyan
button.textColour = colours.white

Line 2 is the same as doing this, by the way:

local button = UIButton( 0, 0, 20, 5, "Hello world!" )
application.view:addChild( button )

What does this look like?


Simple right? You may have noticed I used '0' instead of '1' for the coordinates? Flare's coordinate system is 0-based instead of 1-based, unlike computercraft. This is mainly to make internal things easier, but also offers a slight performance benefit.

Now, buttons are meant to be clicked, and that's just as easy to do. Following from the previous example, you can do this:

function button:onClick()
	self.colour = 2 ^ math.random( 0, 15 )
end

This will change the button colour every time you click it. You should be aware that buttons are clever about drawing when you're holding them. They automatically lighten or darken their colour (depending on the colour) when you're holding them, giving the appearance of flashing when you click them, so the button colour when holding will always look ok even if you change its default colour.

Now, what about animation? I mentioned animation earlier. Instead of making the button change colour, let's make it move to and from 0 and 20 pixels across, animated in .3 seconds (the default animation time of all elements):

local state = false
function button:onClick()
	self.animatedX = state and 0 or 20
	state = not state
end

Surely it can't be that simple!? It is. You can also animate width and internal offset (think of containers that scroll) like this.

Now, to exit this application, right now, we have to terminate it (hold ctrl-t for a horribly long time). Wouldn't it be better to press ctrl-shift-x and have it stop?

application.view:createShortcut( "stop, please", "ctrl-shift-x", function()
	 application:stop()
end )

The first parameter is the identifier of the shortcut. You can use that to change the shortcut combo or function later on.

Flare does a lot more than just buttons, for example, it can run a shell inside a resizeable and moveable window with about 20 lines of code. Refer to the UITerminal and UIWindow documentation to get an idea of how to do this.

If you're not sold yet, take a look at the demo - a showcase of most of the default elements in Flare (I'm lazy and didn't quite finish it, so it's missing a few):
pastebin get T9ADyKrk FlareDemo

You can download Flare like this (the demo does it automatically):
pastebin run SD25GhYf

Before using Flare, it's worth taking a look at the documentation.

Some things you should know:

Flare applications must be in a folder. When you build them, it turns the folder into a single file that can be run on any computer just fine (it will automatically download Flare too!)

Flare is sadly anchored to the 'Flare' folder… you can't install it anywhere else.

There is documentation included in the Flare install. Read through 'Flare/docs', starting with 'Getting Started.txt' for more information.
Edited on 22 August 2015 - 09:51 AM
Lyqyd #2
Posted 19 August 2015 - 01:10 AM
Obfuscated downloads are not allowed. Please provide a plain-text installer instead.
Exerro #3
Posted 19 August 2015 - 08:20 AM
Both the installer and packager just stripped newlines from the packages to make it a bit easier to read. Literally this:

:gsub( "\\\n", "\\n" )
(replacing actual newlines with '\n' so each file went on one line.)

I've removed that and edited back in the pastebin links. Hopefully this counts as un-obfuscated now? I wonder what would happen if I wrote every file of Flare on one line, would that count as obfuscated :blink:/>? I mean it's not like it's impossible to see what the code did in Flare from that installer.
MKlegoman357 #4
Posted 19 August 2015 - 11:13 AM
I wouldn't call that code obfuscated either, but IMO something like multi-file installers and programs packed into one file packages should have a place to view each individual file, like GitHub.

Anyway, this looks really nice! +1 :)/>
CrazedProgrammer #5
Posted 19 August 2015 - 11:30 AM
Nice!
Could you please put the documentation on Github?
It is very annoying to have no online documentation.
Exerro #6
Posted 19 August 2015 - 11:51 AM
GitHub doesn't seem to work for me. Whenever I try and do… anything… I get this:


If I ever manage to get it to work, I will upload everything straight away, but for now you're stuck with the docs that come with Flare I'm afraid.

Edit: Woo! Got it to work. The documentation is here, and I'll upgrade it to markdown at some point so it looks a bit nicer.
Edited on 19 August 2015 - 09:59 AM
LeDark Lua #7
Posted 19 August 2015 - 04:02 PM
Just awesome. Animating and stuff. This looks freaking awesome. +1 to you.
FUNCTION MAN! #8
Posted 19 August 2015 - 05:00 PM
GitHub doesn't seem to work for me. Whenever I try and do… anything… I get this:


If I ever manage to get it to work, I will upload everything straight away, but for now you're stuck with the docs that come with Flare I'm afraid.

Edit: Woo! Got it to work. The documentation is here, and I'll upgrade it to markdown at some point so it looks a bit nicer.

I'll mark it down for you.
Exerro #9
Posted 19 August 2015 - 05:09 PM
I'll mark it down for you.

Thanks, but beat you to it.

Nice!
Could you please put the documentation on Github?
It is very annoying to have no online documentation.

Yup, here they are.
Lyqyd #10
Posted 19 August 2015 - 06:28 PM
Both the installer and packager just stripped newlines from the packages to make it a bit easier to read. Literally this:

:gsub( "\\\n", "\\n" )
(replacing actual newlines with '\n' so each file went on one line.)

I've removed that and edited back in the pastebin links. Hopefully this counts as un-obfuscated now? I wonder what would happen if I wrote every file of Flare on one line, would that count as obfuscated :blink:/>/>? I mean it's not like it's impossible to see what the code did in Flare from that installer.

I'll give you the same reply I gave to the other person who asked a question about your packager:

Lyqyd, on 19 August 2015 - 06:55 AM said:
The installation data is encoded in a way that makes it significantly more difficult to read than the extracted file would be. Given the way it's packaged (a serialized flat table), the encoding is entirely unnecessary, and therefore could only serve to obfuscate the code. Just use block quotes and leave the newlines and tab characters alone. It'd be an extremely simple change to your packaging tool, and would actually cause the file size to be smaller.

I'd have a hard time believing that you'd actually written a non-trivial program on just one line, rather than writing it normally and then stripping newlines. :P/>
Exerro #11
Posted 19 August 2015 - 07:18 PM
Yeah, true, and looking over the code again I see that it was pretty impossible to read, the "\n"s throughout made it look… well, you saw it. Would it be ok to include minified and non-minified versions of it all? I just took a look at the size of everything and got a nasty shock.
Lyqyd #12
Posted 19 August 2015 - 07:47 PM
I'm not sure what you mean by minified, since in this case your packager adds characters to the overall length of the files. Obfuscated downloads aren't allowed even with plaintext versions available, since it's too hard to verify that the obfuscated version hasn't had anything added to it by the obfuscation tool.
FUNCTION MAN! #13
Posted 19 August 2015 - 08:15 PM
Obfuscated downloads are not allowed. Please provide a plain-text installer instead.

Why? Are you trying to get people with many libraries to make their PCs fill up faster?
Lignum #14
Posted 19 August 2015 - 08:23 PM
GitHub doesn't seem to work for me. Whenever I try and do… anything… I get this:


If I ever manage to get it to work, I will upload everything straight away, but for now you're stuck with the docs that come with Flare I'm afraid.

Edit: Woo! Got it to work. The documentation is here, and I'll upgrade it to markdown at some point so it looks a bit nicer.

You should try out git itself instead of GitHub's client. If you're familiar with using a CLI, Git won't be as much of a conundrum to deal with. This should help you get started quickly.

Back on topic:
This looks great! I have yet to experiment with it, but it seems like a worthy competitor to Bedrock, which is (sadly) rare around here.
Exerro #15
Posted 19 August 2015 - 08:27 PM
My packager didn't actually add any characters, it replaced a slash followed by a newline with a slash followed by an 'n'. Anyway, by minified, I mean using an actual Lua minifier tool (parsing and rebuilding the whole Lua file, removing un-needed whitespace, making local names smaller). Its entire purpose is to make the source code smaller while still being executable.

What I just finished: -f and -c in build arguments - you can include the Flare files (only ones you use) with -f so Flare doesn't need to be downloaded at all, and you can minify your project using -c to reduce its filesize to about 2/3 of what it was (using the demo as an example, 137kb to 90kb with pretty much all of Flare included).

Still not entirely sure what the take is on minified downloads as certain programs I've seen on here have a minified version, so be prepared to remove links to minified downloads if you use the -c flag and distribute that build.

Edit, ninja'd :ph34r:/> I'm quite the opposite of familiar with CLI, couldn't even manage to find the path for 'git' in cmd and ended up using Windows PowerShell from the GitHub client to fix the issue (the issue is fixed by the way, it was some weird login thing).
Edited on 19 August 2015 - 06:29 PM
TheOddByte #16
Posted 19 August 2015 - 09:51 PM
I gotta say, this is extremely well made, and I love to see all the future stuff that you're going to add as well, I fell in love with the animations as soon as I saw them, they're smooth and just look really nice.

And I noticed something that may or may not have been intentional, but when selecting text with the mouse in the "TextInput" tab, it doesn't automatically scroll to continue selecting text to the right, well technically it selects the text, but it just doesn't scroll further so you can't really see everything that you're selecting.
And I don't think it should de-select the text when you're using the scrollbar using the mouse( left mouse button for example ).
Lyqyd #17
Posted 19 August 2015 - 10:23 PM
Why? Are you trying to get people with many libraries to make their PCs fill up faster?

Yep, that's definitely it. Evil ol' admin trying to fill up your hard drive. Totally unrelated to trying to protect users from malicious code.

My packager didn't actually add any characters, it replaced a slash followed by a newline with a slash followed by an 'n'. Anyway, by minified, I mean using an actual Lua minifier tool (parsing and rebuilding the whole Lua file, removing un-needed whitespace, making local names smaller). Its entire purpose is to make the source code smaller while still being executable.

What I just finished: -f and -c in build arguments - you can include the Flare files (only ones you use) with -f so Flare doesn't need to be downloaded at all, and you can minify your project using -c to reduce its filesize to about 2/3 of what it was (using the demo as an example, 137kb to 90kb with pretty much all of Flare included).

Still not entirely sure what the take is on minified downloads as certain programs I've seen on here have a minified version, so be prepared to remove links to minified downloads if you use the -c flag and distribute that build.

Edit, ninja'd :ph34r:/>/> I'm quite the opposite of familiar with CLI, couldn't even manage to find the path for 'git' in cmd and ended up using Windows PowerShell from the GitHub client to fix the issue (the issue is fixed by the way, it was some weird login thing).

Minified alternative downloads would probably be less problematic if they're posted as alternative downloads. The bigger issue is when the primary/authoritative download is obfuscated. There's a difference between "Here's the download, and here's a minified version if you're neurotic about disk space" and "Here's the obfuscated download (oh, and here's a plain text version that might or might not be the same code, to keep the staff happy)."
HPWebcamAble #18
Posted 19 August 2015 - 11:27 PM
I'm not sure what you mean by minified…

You must have heard of Lua Minifier? No? Ok
https://mothereff.in/lua-minifier
Lyqyd #19
Posted 19 August 2015 - 11:37 PM
Oh, I know what minification is, there just had only been mention of a packager previously, so I assumed it was a reference to the packaging tool and was confused because it does not minify. It has since been clarified, but thanks.
cyanisaac #20
Posted 20 August 2015 - 02:41 AM
you mods sure do hate any form of obsfucation/minification, I can't help but feel like not many people would intentionally create something to sabotage users.
Cloud Ninja #21
Posted 20 August 2015 - 03:48 AM
you mods sure do hate any form of obsfucation/minification, I can't help but feel like not many people would intentionally create something to sabotage users.
Incorrect. You have NO clue how many users would love to upload 'malicious' (to the fullest lua/CC extent) onto the forums, but we aren't. Like, i would love to have released my getfenv() hook program, but i wouldnt be allowed as its only major use is 'botnetting' really. Obfuscation allows people to SAY its doing one thing, but even if only one line is obfuscated, it can do some pretty nasty stuff, like download and then run a file, or just run mal code.
jplee #22
Posted 22 August 2015 - 06:28 AM
This is an awsome looking library for the UI; but unfortunatly the documentation is not attached, making it difficult for me to tinker with it. :(/>
Exerro #23
Posted 22 August 2015 - 11:50 AM
Oh I think I forgot to update the OP, the documentation is on the github wiki here.
LDDestroier #24
Posted 22 August 2015 - 09:53 PM
So are you going to create an OS out of this?
Exerro #25
Posted 22 August 2015 - 11:25 PM
Probably at some point.
cyanisaac #26
Posted 24 August 2015 - 06:48 PM
I would very much appreciate it if this were modified to NOT be anchored to needing to install to /Flare…. I am building an OS and I would much prefer to store it in a subdirectory somewhere to keep things neat.

PLEASE consider this.

EDIT: using flare for a program in the OS, so it makes sense to store it with other APIs
Edited on 24 August 2015 - 04:49 PM
Exerro #27
Posted 24 August 2015 - 08:15 PM
Sorry, it's just too awkward to do. Since Flare is intended to be used by multiple things, making it be able to be installed anywhere would require some heavy modification to the builder and run.lua, and the installer would have to change too. If you really don't want Flare in the root path, use the -f flag when building your program and it'll include Flare when built so you don't even need Flare installed. If you're distributing the source of the program with the OS… don't… Flare isn't designed to work like that, and you'll get unnecessary lag when starting the program.
クデル #28
Posted 27 August 2015 - 06:01 AM
Would I be able to change the location of /Flare simply by modifying the FS API? making it think something such as APIs/Flare is /Flare without a performance hit?
Exerro #29
Posted 27 August 2015 - 09:56 AM
Yup, that would do it, although why do you want to move it so much?
クデル #30
Posted 27 August 2015 - 09:58 AM
Personally, I'm a bit OCD and a bit of a perfectionist, so its nice to be able to change the file structure to my liking.
PixelFox #31
Posted 19 September 2015 - 12:35 PM
Flare doesn't work for me. I did everything. I ran FlareDemo, and "attempt to call nil". ._.
FUNCTION MAN! #32
Posted 19 September 2015 - 01:57 PM
Flare doesn't work for me. I did everything. I ran FlareDemo, and "attempt to call nil". ._.
Going to need just a bit more info.
Exerro #33
Posted 19 September 2015 - 05:58 PM
Chances are you're running it on an older version of ComputerCraft. Without a line number, there's nothing I can do to help, however, as it works perfectly for me on a fresh computer.
PixelFox #34
Posted 19 September 2015 - 09:33 PM
Chances are you're running it on an older version of ComputerCraft. Without a line number, there's nothing I can do to help, however, as it works perfectly for me on a fresh computer.
What version does it need? I HAVE to stay on 1.73

Okay, I tried it on 1.74, and it works.

I just wish you could make it just an api that you load using a different technique, and not have to compile it. :/

Oh and also, make it so button.color and button.textColor work…

I really thought I was doing something wrong, until I saw you had a "u" in "colors", and made it "colours".
So, yeah, please don't forget about americans.


Yeah, I'm just not gonna use it, I don't wanna compile it into an unreadable mess every time I wanna use it, it's a pain in the butt.
Edited on 19 September 2015 - 08:03 PM
FUNCTION MAN! #35
Posted 20 September 2015 - 01:38 AM
Chances are you're running it on an older version of ComputerCraft. Without a line number, there's nothing I can do to help, however, as it works perfectly for me on a fresh computer.
What version does it need? I HAVE to stay on 1.73

Okay, I tried it on 1.74, and it works.

I just wish you could make it just an api that you load using a different technique, and not have to compile it. :/

Oh and also, make it so button.color and button.textColor work…

I really thought I was doing something wrong, until I saw you had a "u" in "colors", and made it "colours".
So, yeah, please don't forget about americans.


Yeah, I'm just not gonna use it, I don't wanna compile it into an unreadable mess every time I wanna use it, it's a pain in the butt.

Compilation makes it faster and easier to parse. It isn't supposed to be readable, that's why the source is avaiable. Compile it once. Put it in a disk, a pastebin, whatever.
Edited on 19 September 2015 - 11:38 PM
Exerro #36
Posted 20 September 2015 - 10:35 AM
I made Flare/bin/debug for exactly that reason. That will run it without you needing to build it first. What's so bad about compiling anyway?
LeDark Lua #37
Posted 20 September 2015 - 10:49 AM
I think he wants this peace of ar to be an API. But why? If awsumben13 will create an OS using this framework, then you will create apps using this framework as API.

EDIT: I think I explained well :D/>
Edited on 20 September 2015 - 08:50 AM
Exerro #38
Posted 20 September 2015 - 11:07 AM
I did actually make an OS that used Flare. It worked pretty well… multi-user support, awesome animations, multitasking, and a much better way of switching between apps. However, I got bored of it (like most projects) so yeah… I might release it actually.

Anyway, now I'm on my laptop, I can go into some more depth as to why you have to compile things.

Firstly, you don't need to write any installers yourself, it will automatically download Flare and all your files are run just fine. Secondly, it allows things like minification, including Flare, and putting all sorts of files from all over your computer in. You can even extend other projects by adding them to the build path. Finally, it means that operating systems using Flare as a UI framework can alter how the program is run, potentially tying program UIs into their own and doing all sorts of clever stuff. Phoenix (the OS I was writing) does this iirc. Another advantage is that you don't need to worry about calling app:run() or anything, all that is done for you, you can just set up a GUI and it simply works.

Edit: Why not? The successor to Nova, and already abandoned, I present to you: Phoenix! pastebin run NhY9B7cb
Edited on 20 September 2015 - 11:40 AM
LeDark Lua #39
Posted 20 September 2015 - 11:26 AM
I did actually make an OS that used Flare. It worked pretty well… multi-user support, awesome animations, multitasking, and a much better way of switching between apps. However, I got bored of it (like most projects) so yeah… I might release it actually.

Anyway, now I'm on my laptop, I can go into some more depth as to why you have to compile things.

Firstly, you don't need to write any installers yourself, it will automatically download Flare and all your files are run just fine. Secondly, it allows things like minification, including Flare, and putting all sorts of files from all over your computer in. You can even extend other projects by adding them to the build path. Finally, it means that operating systems using Flare as a UI framework can alter how the program is run, potentially tying program UIs into their own and doing all sorts of clever stuff. Phoenix (the OS I was writing) does this iirc. Another advantage is that you don't need to worry about calling app:run() or anything, all that is done for you, you can just set up a GUI and it simply works.

Awesome.
H4X0RZ #40
Posted 20 September 2015 - 02:49 PM
I think there is a bug in the tasks view of Phoenix. You can still enter stuff into the shell(s), and there is a blinking cursor in the top-left corner.
LeDark Lua #41
Posted 20 September 2015 - 04:23 PM
Oh meh gaaawd, AWESOME OS. Please continue working on it :o/>
Exerro #42
Posted 20 September 2015 - 05:38 PM
I think there is a bug in the tasks view of Phoenix. You can still enter stuff into the shell(s), and there is a blinking cursor in the top-left corner.
Yup, that ain't ever gonna get fixed.

Oh meh gaaawd, AWESOME OS. Please continue working on it :o/>
Thanks, but I'm working on a language that's taking up all my time, not to mention starting A-levels and actually having to do homework.
LeDark Lua #43
Posted 20 September 2015 - 06:01 PM
I think there is a bug in the tasks view of Phoenix. You can still enter stuff into the shell(s), and there is a blinking cursor in the top-left corner.
Yup, that ain't ever gonna get fixed.

Oh meh gaaawd, AWESOME OS. Please continue working on it :o/>
Thanks, but I'm working on a language that's taking up all my time, not to mention starting A-levels and actually having to do homework.

Well then. Good luck on the language and A-levels.