-
Notifications
You must be signed in to change notification settings - Fork 33
Getting Started
- Download Lemur.jar
- Download Lemur-proto.jar
- Download Lemur Dependencies
- Include jars in your project
- Initialize the GUI layer
- Initialize a default style
- Make a GUI
Download the latest Lemur core jar from here: Latest
It is also recommended to grab the latest Lemur-proto.jar as this contains many useful components that are 'incubating' and will eventually be included in the main module. Check the Lemur Releases page for the latest release. This is the current release as of this writing.
It might be worth grabbing the javadoc jar files for each or just bookmark these links:
Lemur requires a minimal amount of external dependencies, many of which will be useful in your projects anyway.
- Guava version 12 or later
- slf4j version 1.7.5 or later, plus an adapter for your preferred logging framework. (At minimum, you will need the API jar, something like: slf4j-api-1.7.5.jar)
- jME version 3.1-alpha or later. (beta1 or above is recommended)
- (optional but highly recommended) Groovy version 2.1.9 or later. This is only need if you want to use the style language support and in the end you only need groovy-jsr223.jar. (For example: groovy-jsr223-2.1.9.jar)
This is IDE specific but you must include the above jars as dependencies for your project. (Lemur is also available on JCenter as a standard gradle/maven dependency.) For the JME SDK, right click on Libraries in your project tree and select "Add JAR/Folder..."
If you use a build tool like gradle or maven (or the support in your IDE of choice) then Lemur is available through JCenter. This will automatically include any dependencies you need.
Example of including Lemur and Lemur-proto in a gradle build:
dependencies {
compile "com.simsilica:lemur:1.14.0"
compile "com.simsilica:lemur-proto:1.11.0"
}
For a full example of a project that uses Lemur in a gradle build, see: SimEthereal Basic Example
Lemur requires very minimal initialization to setup its internal defaults, register some base listeners with the system, and setup some default app states. This requires only one line of code:GuiGlobals.initialize(app)
This should be done early during application initialization but after jME has been started, so typically this is done in the simpleInit() method as follows:
@Override
public void simpleInitApp() {
// Initialize the globals access so that the default
// components can find what they need.
GuiGlobals.initialize(this);
....
Lemur GUI elements by default include no styling at all. Buttons will not even have borders, etc.. Lemur includes some default styling that you can easily include (or extend the same mechanism to add your own style sets).
Note: the default styling feature requires Groovy as a project dependency as it uses the groovy-based styling language. If you use the styling code below then make sure you have some version of groovy-all.jar or groovy-jsr223.jar in your project dependencies.
The following will load the default 'glass' style that is included. (Other styles are currently under construction.)
// Load the 'glass' style
BaseStyles.loadGlassStyle();
If you want this to be the default style for all new GUI elements then simply add:
// Set 'glass' as the default style when not specified
GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
For more information on extending this style loading see: extending base styles (under construction)
At this point, you can make a GUI. Here is a simple example:
// Create a simple container for our elements
Container myWindow = new Container();
guiNode.attachChild(myWindow);
// Put it somewhere that we will see it.
// Note: Lemur GUI elements grow down from the upper left corner.
myWindow.setLocalTranslation(300, 300, 0);
// Add some elements
myWindow.addChild(new Label("Hello, World."));
Button clickMe = myWindow.addChild(new Button("Click Me"));
clickMe.addClickCommands(new Command<Button>() {
@Override
public void execute( Button source ) {
System.out.println("The world is yours.");
}
});
It should look like this when you run it:
If so then Congratulations!
Full source example:
package mygame;
import com.jme3.app.SimpleApplication;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Command;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.style.BaseStyles;
public class GuiDemo extends SimpleApplication {
public static void main( String... args ) {
GuiDemo main = new GuiDemo();
main.start();
}
@Override
public void simpleInitApp() {
// Initialize the globals access so that the defualt
// components can find what they need.
GuiGlobals.initialize(this);
// Load the 'glass' style
BaseStyles.loadGlassStyle();
// Set 'glass' as the default style when not specified
GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
// Create a simple container for our elements
Container myWindow = new Container();
guiNode.attachChild(myWindow);
// Put it somewhere that we will see it
// Note: Lemur GUI elements grow down from the upper left corner.
myWindow.setLocalTranslation(300, 300, 0);
// Add some elements
myWindow.addChild(new Label("Hello, World."));
Button clickMe = myWindow.addChild(new Button("Click Me"));
clickMe.addClickCommands(new Command<Button>() {
@Override
public void execute( Button source ) {
System.out.println("The world is yours.");
}
});
}
}
A good place to start would be the more extensive Documentation page.