Easy GUI System
EGS uses the LGPL license 3.0. Basically give me credit - Any fixes you make to my code; give me them too. You don't need to give me your code; though. I think it goes somewhat like that. [License details and stuff].
The license above does NOT APPLY TO the 'Tetris.mp3' sound included, not the debug.lua file included. Neither of those were made by me (See #Included)
Easy GUI System is an easy-to-use GUI system made by User:Trappingnoobs.
Contents
General tutorial
Included
- Ships with debug.lua by Kalle2990 from love2D forum.
- Ships with class.lua by Trappingnoobs from love2D forum.
- Ships with 'Tetris with DONK' by Jordan Snelling (Jordach) from newgrounds.
If any owner of an above file/product does not wish EGS to contain their products anymore; you can contact me via email (Ash2424@live.co.uk), or via the Love2D forum (Send a private message to 'Trappingnoobs' or post on the EGS thread.)
Class.lua by Trappingnoobs
My class system is incredibly simple to use. The following few tutorials will just teach you the basics.
Defining a class
Class "ClassName" {Properties}
There we have a basic class called 'ClassName'. It has ONE property, called "Properties", with a default value of an empty string (We didn't give it a default value).
Defining a class with multiple properties
Class "ClassName" {
Property1,
Property2,
}
Yet another very basic class. It literally just creates a class with two properties. If it wasn't obvious from #Defining a class, you pass in a table.
Defining a class with multiple properties with default values
Class "ClassName" {
["Property1"] = 7,
Property2,
}
To give a property a default value, just make it a key instead of a value, such as above, and give it a value of the default value.
Default values can be functions, tables, anything!
Instanciating a class
You only ever run new on a class. Do not type "ClassName.Property1 = ." because it WILL error. Only change instance's properties if that makes sense..
Class "ClassName" {
["Property1"] = 7,
Property2,
}
ClassName:new("InstanceName")
print(InstanceName.Property1)
>7
As you can see, and probably already noticed, we're passing in the names, rather than getting a return value, such as the above instead of
ClassName = Class {
["Property1"] = 7,
Property2,
}
InstanceName = ClassName:new()
The class function makes use of the 'getfenv()' function. This allows it to define variables in the calling environment. Classes are not local variables, they are global. So are instances.
Creating multiple intances of a class
Class "ClassName" {
["Property1"] = 7,
Property2,
}
ClassName:new("InstanceName")
InstanceName.Property2 = "Ohai world"
print("InstanceName1 says: "..InstanceName.Property2)
ClassName:new("InstanceName2")
print("InstanceName2 says: "..InstanceName2.Property2)
>InstanceName1 says: Ohai world
>InstanceName2 says:
Like I said earlier; if no default is set, a class property will get a default value of an empty string, not nil, so it doesn't error when you try to concatenate it.
Inheriting properties
Class "ClassName" {
["eggs"] = true,
}
Class "ClassName2" ({
["Property1"] = 7,
Property2,
}, {ClassName})
ClassName2:new("InstanceName")
print(tostring(InstanceName.eggs))
>true
To inherit, instead of typing
Class "cName" {Properties}
We type
Class "cName" ({Properties}, {Which classes to inherit from})
As it's a table you can inherit from multiple classes.
If you have the same property in both classes, for example
Class "cName" {["Prop1"] = "LOLHAX5000"}
Class "cName2" ({["Prop1"] = "LOLHAX6000"}, {cName})
Like that, it inherits from an object with a property the same, the second class (cName2)'s Prop1 will become it's default, as it overrides the inherited value.
So if I instanced "cName", and printed it's Prop1, it'd print LOLHAX5000, but doing the same to cName2 would print LOLHAX6000. This allows you to make classes that inherit the majority of things from another, but change or completely destroy (just set it to nil) some, you can.
End of class tutorial
I hoped your understood; but if not, you don't need to understand it all. Only that you should know how to instance classes (ClassName:new("InstanceName).
Using my GUI library
By now you should be familiar with my class system.
My GUI library classes are organised into two sections: Structural and Non-Structural classes.
What are Structural Classes?
In my GUI library, structural classes are classes that the only purpouse is for other classes to inherit from. Instancing them is a VERY bad idea.
What are Non-Structural Classes?
Non-Structural classes are things like Checkboxes. You can instance them, and they are mainly GUI items.