How can I make my theme for lemur GUI?

how can I make my theme for lemur GUI?

1 Like

Take a look at the glass style:

and

1 Like

I downloaded medieval theme and copy it in assets root folder.
it works correctly but when I want to edit it has some problem in importing :

Does it work when you run it anyway? It might just be an SDK cache issue.

1 Like

yes it works.
but I need to edit it.

I don’t understand. Why can’t you edit it?

1 Like

import classes have a problem.
I can’t ctrl+click to go to source of each classes like TbtQuadBackground Component.create().
I can’t read it and so I can’t understand how to edit it.

Do you have the groovy plugin installed?

http://plugins.netbeans.org/plugin/3914/groovy

1 Like

yes

Hrm. I’m not certain tbh. I use intellij, but there’s always the source. Annoying, but at least you can still continue for now.

1 Like

ok thanks.

I prefer using java for the styles, that way i know is going to work on android
I have a version on java of the medieval theme but i dont know if it looks and works the same, tried to copie the same code but there is one line of code i didnt knew where it came from, well this is what a have, maybe it can help

import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Command;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.HAlignment;
import com.simsilica.lemur.Insets3f;
import com.simsilica.lemur.VAlignment;
import com.simsilica.lemur.component.IconComponent;
import com.simsilica.lemur.component.TbtQuadBackgroundComponent;
import com.simsilica.lemur.style.Attributes;
import com.simsilica.lemur.style.Styles;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Pankey
 */
public class MedievalTheme {
    public MedievalTheme(String style){
        Styles styles =GuiGlobals.getInstance().getStyles();
        Attributes attrs;

        TbtQuadBackgroundComponent ltBrownBorderedBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/panel_beige.png",false,false),
                        1, 20, 32, 48, 75, 1f, false);

        TbtQuadBackgroundComponent darkBrownBorderedBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/panel_brown.png",false,false),
                        1, 20, 32, 48, 75, 1f, false);

        TbtQuadBackgroundComponent grayBorderedBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/panel_blue.png",false,false),
                        1, 20, 32, 48, 75, 1f, false);

        TbtQuadBackgroundComponent ltBrownInsetBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/panelInset_beige.png",false,false),
                        1, 17, 28, 44, 71, 1f, false);

        TbtQuadBackgroundComponent grayButtonBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/buttonSquare_blue.png",false,false),
                        1, 7, 8, 38, 45, 1f, false);

        TbtQuadBackgroundComponent grayPressedButtonBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/buttonSquare_blue_pressed.png",false,false),
                        1, 7, 4, 38, 41, 1f, false);

        TbtQuadBackgroundComponent barBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/barBack.png",false,false),
                        1, 9, 0, 27, 18, 1f, false);

        TbtQuadBackgroundComponent orangeBarBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/barRed.png",false,false),
                        1, 9, 0, 27, 18, 1f, false);

        TbtQuadBackgroundComponent blueBarBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/barBlue.png",false,false),
                        1, 9, 0, 27, 18, 1f, false);

        TbtQuadBackgroundComponent greenBarBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/barGreen.png",false,false),
                        1, 9, 0, 27, 18, 1f, false);

        TbtQuadBackgroundComponent selectedBg = TbtQuadBackgroundComponent.create(
                        GuiGlobals.getInstance().loadTexture("Textures/selected.png",false,false),
                        1, 9, 0, 27, 18, 1f, false);

        IconComponent checkOnIcon = new IconComponent("Textures/checkbox_on.png", 0.3f, 2, 2, 1, false);
        IconComponent checkOffIcon = new IconComponent("Textures/checkbox_on.png", 0.3f, 2, 2, 1, false);

        ColorRGBA darkTextColor = new ColorRGBA(0.341f, 0.322f, 0.275f, 1.0f);
        ColorRGBA lightTextColor = new ColorRGBA(0.831f, 0.847f, 0.914f, 1.0f);

        Command<Button> pressedCommand = new Command<Button>() {
            @Override
            public void execute(Button source) {
                if (source.isPressed()) {
                    source.setBackground(grayPressedButtonBg.clone());
                    source.getPreferredSize().y -= 4;
                } else {
                    source.setBackground(grayButtonBg.clone());
                    source.getPreferredSize().y += 4;
                }
            }
        };

        Command<Button> repeatCommand = new Command<Button>() {
            private long startTime=0;
            private long lastClick=0;
            @Override
            public void execute(Button source) {
                // Only do the repeating click while the mouse is
                // over the button (and pressed of course)
                if (source.isPressed() && source.isHighlightOn()) {
                    long elapsedTime = System.currentTimeMillis() - startTime;
                    // After half a second pause, click 8 times a second
                    if (elapsedTime > 500) {
                        if (elapsedTime - lastClick > 125) {
                            //source.click();

                            // Try to quantize the last click time to prevent drift
                            lastClick = ((elapsedTime - 500) / 125) * 125 + 500;
                        }
                    }
                } else {
                    startTime = System.currentTimeMillis();
                    lastClick = 0;
                }
            }
        };
        List<Command<Button>> command = new ArrayList();
        command.add(pressedCommand);
        Map<Button.ButtonAction, List<Command<Button>>>  stdButtonCommands = new EnumMap<>(Button.ButtonAction.class);
            stdButtonCommands.put(Button.ButtonAction.Down, command);
            stdButtonCommands.put(Button.ButtonAction.Up, command);

        List<Command<Button>> repeatcommand = new ArrayList();
        command.add(repeatCommand);
        Map<Button.ButtonAction, List<Command<Button>>>  sliderButtonCommands = new EnumMap<>(Button.ButtonAction.class);
            stdButtonCommands.put(Button.ButtonAction.HighlightOn, repeatcommand);


        attrs = styles.getSelector(style);
        attrs.set("fontSize", 16);

        attrs = styles.getSelector("container", style);
        attrs.set("background", darkBrownBorderedBg.clone());
        darkBrownBorderedBg.setMargin(10, 10);

        attrs = styles.getSelector("darkContainer", style);
        attrs.set("background", grayBorderedBg.clone());
        grayBorderedBg.setMargin(10, 10);

        attrs = styles.getSelector("insetContainer", style);
        attrs.set("background", ltBrownInsetBg.clone());
        ltBrownInsetBg.setMargin(10, 10);

        attrs = styles.getSelector("label", style);
        attrs.set("insets", new Insets3f(2, 2, 2, 2));
        attrs.set("color", darkTextColor.clone());
        attrs.set("textVAlignment", VAlignment.Center);

        attrs = styles.getSelector("lightLabel", style);
        attrs.set("insets", new Insets3f(2, 2, 2, 2));
        attrs.set("color", lightTextColor.clone());
        attrs.set("textVAlignment", VAlignment.Center);

        attrs = styles.getSelector("button", style);
        attrs.set("background", grayButtonBg.clone());
        attrs.set("insets", new Insets3f(2, 2, 2, 2));
        attrs.set("color", lightTextColor.clone());

        ColorRGBA highlightColor = new ColorRGBA(0.82f, 0.749f, 0.561f, 1.0f);

        attrs.set("buttonCommands", stdButtonCommands);        

        attrs = styles.getSelector("slider.thumb.button", style);        
        attrs.set("text", "");
        attrs.set("buttonCommands", null);

        attrs = styles.getSelector("slider.down.button", style);
        attrs.set("buttonCommands", sliderButtonCommands);

        attrs = styles.getSelector("checkbox", style);
        attrs.set("onView", checkOnIcon.clone());
        attrs.set("offView", checkOffIcon.clone());
        attrs.set("insets", new Insets3f(2,2,0,2));
        attrs.set("color", lightTextColor.clone());
        attrs.set("preferredSize", new Vector3f(50, 50, 0));

        attrs = styles.getSelector("orangeBar.value", style);
        attrs.set("background",  orangeBarBg.clone());
        orangeBarBg.setMargin(0, 0);

        attrs = styles.getSelector("orangeBar.container", style);
        attrs.set("background", barBg.clone());
        barBg.setMargin(0, 0);

        attrs = styles.getSelector("orangeBar.label", style);
        attrs.set("textHAlignment", HAlignment.Center);
        attrs.set("textVAlignment", VAlignment.Center);
        attrs.set("insets", new Insets3f(1, 0, 1, 0));

        attrs = styles.getSelector("blueBar.value", style);
        attrs.set("background", blueBarBg.clone());
        blueBarBg.setMargin(0, 0);

        attrs = styles.getSelector("blueBar.container", style);
        attrs.set("background", barBg.clone());
        barBg.setMargin(0, 0);

        attrs = styles.getSelector("blueBar.label", style);
        attrs.set("textHAlignment", HAlignment.Center);
        attrs.set("textVAlignment", VAlignment.Center);
        attrs.set("insets", new Insets3f(1, 0, 1, 0));

        attrs = styles.getSelector("greenBar.value", style);
        attrs.set("background", greenBarBg.clone());
        greenBarBg.setMargin(0, 0);
        attrs.set("textHAlignment", HAlignment.Center);
        attrs.set("textVAlignment", VAlignment.Center);
        attrs.set("insets", new Insets3f(1, 0, 1, 0));
        blueBarBg.setMargin(0, 0);

        attrs = styles.getSelector("greenBar.container", style);
        attrs.set("background", barBg.clone());
        barBg.setMargin(0, 0);

        attrs = styles.getSelector("greenBar.label", style);
        attrs.set("textHAlignment", HAlignment.Center);
        attrs.set("textVAlignment", VAlignment.Center);
        attrs.set("insets", new Insets3f(1, 0, 1, 0));////


        attrs = styles.getSelector("list.container", style);
        attrs.set("background", ltBrownInsetBg.clone());
        barBg.setMargin(0, 0);

        attrs = styles.getSelector("list.items", style);
        attrs.set("insets", new Insets3f(0, 0, 0, 10));

        attrs = styles.getSelector("list.item", style);
        attrs.set("color", darkTextColor.clone());
        attrs.set("textVAlignment", VAlignment.Center);
        attrs.set("insets", new Insets3f(2, 2, 2, 2));

        attrs = styles.getSelector("list.selector", style);
        attrs.set("background", selectedBg.clone());
    }
}
2 Likes

how can I load and use it?

well i always add the styles on the simpleInitApp method like this, and for using it, just specify the name of the style on your panel

@Override
public void simpleInitApp() {
    GuiGlobals.initialize(this);
    GuiGlobals.getInstance().getStyles().setDefault(new MedievalTheme("MedievalTheme"));
    
    Container container = new Container("MedievalTheme");
    container.setLocalTranslation(0, 450f, 0);
    this.getGuiNode().attachChild(container); 
    
}
1 Like

The line of code that I dont know where it came from is inside the repeatCommand, it has something like this.

    Command<Button> repeatCommand = new Command<Button>() {
        @Override
        public void execute(Button source) {
               source.click();// cant find click inside Button
        }
    };

Since im a noob with groovy, i assume its something specific of the languaje, but maybe someone can clarify

1 Like

Iirc that thing is for sliders, not quite sure what it does atm. I just copied it from the default glass theme I think.

1 Like

What version of Lemur are you using? Button has had a click() method for almost a year.

lol, i have “com.simsilica:lemur:1.10” on my gradle

latest version is 1.13.0, in gradle you can have it find the latest version of a library using the following

compile "com.simsilica:lemur:[1.+,)"
2 Likes

For the record, that release is from Feb 18, 2017… so won’t include button.click() (among other things).

1 Like