Lemur and Size of 3d spatial for layouts

First of all great job. Only been using it for a dozen or so hours.

When i add a simple 3d spatial. I add a GuiControler set its size and prefered size. Yet this seems to be completely ignored when i add it to a container, in other words it just overlaps other elements. Of course i can’t use addChild and must use attach child. What am i missing? It adds a new label no problems and pushes the button lower. But ignores the spatial.

Here is my test code.

    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);
        
        Box b = new Box(10f, 10f, 10f); // create cube shape
	Geometry geom = new Geometry("Box", b); // create cube geometry from the shape
	Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 
	mat.setColor("Color", ColorRGBA.Red); // set color of material to blue
	geom.setMaterial(mat);
	geom.setLocalRotation(new Quaternion(new float[] {1,1,1}));
		
	Node node=new Node();
	node.attachChild(geom);
	GuiControl gc=new GuiControl("");
	node.addControl(gc);
	//gc.setSize(new Vector3f(10, 10,0));
	gc.setPreferredSize(new Vector3f(10, 10, 0));
	Panel panel=new Panel();
	panel.attachChild(geom);


        // Add some elements
        myWindow.addChild(new Label("Hello, World."));
        myWindow.addChild(new Label("Hello, World2."));
        myWindow.addChild(panel);
        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.");
                }
            });            
    }    

I get

Also i don’t understand the parameters i should be passing to the GuiControler constructor. The javadoc was less than clear about what either the string should be or what the gui elements are for.

Thanks in advanced.

If you don’t addChild() then the layout will be completely bypassed.

Also, it’s probably a mistake that you are creating a Node, attaching the GuiControl to it, and then never actually using it.

Try panel.addChild(node).

If you already have some GuiComponents like a QuadBackgroundComponent, etc. that you know you will need then you can pass them on the constructor. Or if you know that you will have certain named layers and that they should be in a certain order then you can pass that on the other constructor. Named layers are an easy way to manage things like “border” versus “insets” versus “background” while allowing you to freely change them (by name) without having to worry about the order of the GuiComponents when you add them.

This might be helpful when understanding the component stack:

It’s basically the compositional way that many GUI elements are created. For example, a Label will potentially have insets, a border, a background, a shadow layer, and a text layer. I think there is an icon layer in there, too. Any of which could be set or not depending on need. You can look into Label.java to see how it sets up the layers in its own GuiControl:

Though for including a 3D spatial in a 2D GUI, most of that stuff is probably overkill.

There was another thread where someone was creating a GuiComponent that could hold a 3D spatial and properly participate in reshape() and preferred size calculation.

1 Like

Awesome, super fast reply there. Thanks heaps. Thanks for the clear explanations. Thanks for the code. My new GUI elements are probably just going to be spatial with some controllers on em! like say a health bar. Also with adding mouse listeners to spatials… Yea don’t need another GUI lib. This is even better than Unities. Well at least my 3 hours with it.

1 Like

Hi,

this code is not possible, because addChild does not support to take a node as a parameter.

How to add a jme3-spatial to lemur gui and / or just make them clickable?

Thanks - Enomine

There is no addChild() method for panels. The method you want is named attachChild().

class com.simsilica.lemur.Panel extends com.jme3.scene.Node
class com.jme3.scene.Node has a method attachChild(com.jme3.scene.Spatial)
class com.jme3.scene.Node extends com.jme3.scene.Spatial

Therefore you can pass a com.jme3.scene.Node to com.simsilica.lemur.Panel.attachChild()

Container has an addChild() that takes a node… as does GuiControl. The point is that if you attach a child directly to the Panel then Lemur can’t know about it. You must pass it to one of the methods that cares about a layout. (Those methods will not work like you want without the child have its own GuiControl anyway.)

To just make a JME spatial clickable just add a Lemur mouse listener to it. There was even a lemur gem for this.

And it works in 2D or 3D.

1 Like

The only problem iv had with lemur is scrolling, though that’s partly due to me not pushing anything :stuck_out_tongue: - Other than that, it’s my default GUI anyway and find it to be very painless to use. Property panels are awesome too. Check out the proto’s.

It lacks, like a few other goldmines for jme, someone to advertise them as well as they should be. Jme is so much a dark horse because of that. A lot of really good stuff.

1 Like