Try Styling as asset

I think it’s explain on Lemur Doc (styling)

…or set your style up as a class resource (or asset) and use the BaseStyles class to load it.

BaseStyles.loadStyleResources("styles/myCoolStyle.groovy");

Myabe I misunderstood this. I try to put MyStyle.groovy to asset folder. And I’m not sure do that styling correctly.

I got something like this error:

Uncaught exception thrown in Thread[jME3 Main,5,main]
RuntimeException: Error running resource:jar:file:/M:/lemur/MyStyle/MyStyle/build/assets/libs/assets.jar!/Interface/styles/MyStyle.groovy

What’s probably I do wrongly?

This:

Does not match:

Where is the file and what does the actual code look like that you are using to load it?

Sorry.

is from lemur doc (styling).
Here’s my Interface/styles/MyStyle.groovy

import com.simsilica.lemur.*;
import com.simsilica.lemur.Button.ButtonAction;
import com.simsilica.lemur.component.*;

def gradient = TbtQuadBackgroundComponent.create( 
                                        texture( name:"/Interface/icons/bordered.png", 
                                                 generateMips:false ),
                                                 1, 1, 1, 126, 126,
                                                 1f, false );
 
def border = TbtQuadBackgroundComponent.create(
                                        texture( name:"/Interface/icons/border.png", 
                                                 generateMips:false ),
                                                 1, 1, 1, 6, 6,
                                                 1f, false );
def border2 = TbtQuadBackgroundComponent.create(
                                        texture( name:"/Interface/icons/border.png", 
                                                 generateMips:false ),
                                                 1, 2, 2, 6, 6,
                                                 1f, false );
 
                                  
selector( "MyStyle" ) {
    fontSize = 14
}
 
selector( "label", "MyStyle" ) {
    insets = new Insets3f( 2, 2, 0, 2 );
    color = color(255, 0, 0, 0.85)     
}

selector( "container", "MyStyle" ) {
    background = gradient.clone()
    background.setColor(color(255, 0, 0, 0.5))
}

selector( "slider", "MyStyle" ) {
    background = gradient.clone()
    background.setColor(color(255, 0, 0, 0.5))
} 

def pressedCommand = new Command<Button>() {
        public void execute( Button source ) {
            if( source.isPressed() ) {
                source.move(1, -1, 0);
            } else {
                source.move(-1, 1, 0);
            }
        }       
    };
    
def stdButtonCommands = [
        (ButtonAction.Down):[pressedCommand], 
        (ButtonAction.Up):[pressedCommand]
    ];

selector( "title", "MyStyle" ) {
    color = color(255, 0, 0, 0.85f)
    highlightColor = color(255, 0, 0, 0.85f)
    shadowColor = color(0, 0, 0, 0.15f)
    shadowOffset = new com.jme3.math.Vector3f(2, -2, -1);
    background = new QuadBackgroundComponent( color(255, 0, 0, 0.5) );
    
    buttonCommands = stdButtonCommands;
}


selector( "button", "MyStyle" ) {
    background = gradient.clone()
    color = color(255, 255, 255, 0.85f)
    background.setColor(color(255, 0, 0, 0.5))
    insets = new Insets3f( 2, 2, 2, 2 );
    
    buttonCommands = stdButtonCommands;
}

selector( "slider", "MyStyle" ) {
    insets = new Insets3f( 1, 3, 1, 2 );    
}

selector( "slider", "button", "MyStyle" ) {
    background = doubleGradient.clone()
    background.setColor(color(255, 0, 0, 0.5))
    insets = new Insets3f( 0, 0, 0, 0 );
}

selector( "slider.thumb.button", "MyStyle" ) {
    text = "[]"
    color = color(255, 0, 0, 0.85)     
}

selector( "slider.left.button", "MyStyle" ) {
    text = "-"
    background = doubleGradient.clone()
    background.setColor(color(255, 0, 0, 0.5))
    background.setMargin(5, 0);
    color = color(0.6, 0.8, 0.8, 0.85)     
}

selector( "slider.right.button", "MyStyle" ) {
    text = "+"
    background = doubleGradient.clone()
    background.setColor(color(255, 0, 0, 0.5))
    background.setMargin(4, 0);
    color = color(0.6, 0.8, 0.8, 0.85)     
}

selector( "checkbox", "MyStyle" ) {
    def on = new IconComponent( "/Interface/icons/flatred-check-on.png", 1f,
                                 0, 0, 1f, false );
    on.setColor(color(0.5, 0.9, 0.9, 0.9))
    on.setMargin(5, 0);
    def off = new IconComponent( "/Interface/icons/flatred-check-off.png", 1f,
                                 0, 0, 1f, false );
    off.setColor(color(0.6, 0.8, 0.8, 0.8))
    off.setMargin(5, 0);
    
    onView = on;
    offView = off;    

    color = color(0.8, 0.9, 1, 0.85f)
}

selector( "rollup", "MyStyle" ) {
    background = gradient.clone()  
    background.setColor(color(0.25, 0.5, 0.5, 0.5))
}

selector( "tabbedPanel", "MyStyle" ) {
    activationColor = color(0.8, 0.9, 1, 0.85f)
}

selector( "tabbedPanel.container", "MyStyle" ) {
    background = null
}

selector( "tab.button", "MyStyle" ) {
    background = gradient.clone()
    background.setColor(color(0.25, 0.5, 0.5, 0.5))
    color = color(0.4, 0.45, 0.5, 0.85f)
    insets = new Insets3f( 4, 2, 0, 2 );
    
    buttonCommands = stdButtonCommands;
}

And com/mystyle/mygame/StyleTest.java

package com.mystyle.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 StyleTest extends SimpleApplication {

    public static void main( String... args ) {
        StyleTest main = new StyleTest();
        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.loadStyleResources("Interface/styles/MyStyle.groovy");

        // Set 'glass' as the default style when not specified
        GuiGlobals.getInstance().getStyles().setDefaultStyle("MyStyle");

        // 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.");
                }
            });            
    }    
}

What’s the mistake I made?

BaseStyles.loadStyleResources(“/Interface/styles/MyStyle.groovy”);

AssetManager automatically adds the “/” to the beginning for assets but Java doesn’t for class resources.

I change to

BaseStyles.loadStyleResources("/Interface/styles/MyStyle.groovy");

But still experiencing the same error.

I mean, you can debug this further pretty easily. Just try seeing if you can get at your file as a class resource. That’s all Lemur is doing.

Edit: and actually, I was wrong… Lemur does automatically add the / at the beginning if you don’t have one.

Actually, I didn’t read carefully.

It IS finding your groovy file. You just have an error it in somewhere. It probably lists that in the rest of the error message.

For an exception… the stack trace is 90% of the useful information. So in the above, you left out 90% of the useful information.

Understood. I made mistake in creating the style. It works when creating much simpler like…

import com.simsilica.lemur.*;
import com.simsilica.lemur.Button.ButtonAction;
import com.simsilica.lemur.component.*;

selector('SimpleStyle') {
    fontSize = 20
}
selector('button', 'SimpleStyle') {
    background = new QuadBackgroundComponent(color(255, 0, 0, 1))
    color = color(255, 0, 0, 0.85)
}
selector('slider', 'button', 'SimpleStyle') {
    fontSize = 10

}

Yeah, since I can’t see the error, I can’t really say what was wrong with the other code.

I dont understand. The error I show you is the only error I got on jme window. I think I dont have error on console. It build succesfully. However I think it doesn’t matter now.

Edit: maybe there are error. but im too lazy to check that out again. maybe ill got error when try another.