How to make a centered label with Icon?


#62

I would have expected to see in the log something like “setting color of Label to X because file Y says so”, but I can’t figure it out. I thought that I was just dumb but your comment makes me think that the logs just don’t have this information.

Besides, all the selector have the “glass” tag. What does it mean, since I’m not using glass anymore? Should I replace it with something else to avoid conflict?


#63

Styles are loaded and are already all resolved to specific values before being applied.

I mean, if you aren’t using the glass style then setting things on the glass style won’t do anything.

What have you set your default style too? And/or what style are you actually using on your buttons?


#64

Ok, mixing styles made me found the issue: I had duplicate declaration :sob:

Such a stupid mistake…


#65

Now: how to change the color on mouse over, and focus gained?
(Actually the color is already changing, but don’t know where/how)

EDIT: I tried with this but it doesn’t work

def hoverCommand = new Command<Button>() {
    public void execute ( Button source ) {
        source.color = blackColor;
    }
}

def stdButtonCommands = [
        (ButtonAction.Hover):[hoverCommand], 
        (ButtonAction.Down):[pressedCommand], 
        (ButtonAction.Up):[pressedCommand]
    ];

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: Hover for class: com.simsilica.lemur.Button$ButtonAction
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320)
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72)
at javax.script.CompiledScript.eval(CompiledScript.java:92)
at com.simsilica.lemur.style.StyleLoader.loadStyle(StyleLoader.java:177)
… 8 more
Caused by: groovy.lang.MissingPropertyException: No such property: Hover for class: com.simsilica.lemur.Button$ButtonAction
at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:1002)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1857)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1833)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3758)
at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
at Script2.run(Script2.groovy:74)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
… 11 more


#66

#67

Also I’d like to integrate it with bigbanana:

so I need a listener for focusGain and focusLost. Where can I hook them in the Button?


#68

What version of Lemur are you using?

Note that the highlight color is already a stylable property:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/Button.html


#69

Cool it works! I need to change the background on mouseover/highligh as well…


#70

Note: I just updated DynamicInsetsComponent to support 0 insets, ie: to allow dynamic stretching. This will go into the next release but you can build lemur from source if you want it now (easy with gradle install).

I also updated the demo to have a dynamic insets demo.


#71

Ok, I’ll switch to master version. I also want to add the functionality I need to make it work like I want. Basically, the button should have 3 visible states:

default
MouseOver or FocusOn
Pressed

For each state I need different text color and different background (basically swap the 9-patch Texture)


#72

You can do this with the existing functionality, just register the appropriate action handler or listener.


#73

I meant from the groovy file


#74

So did I… it’s easy to add stylable actions for any of these:


#75

Something don’t work as expected; MouseOver makes background invisible:

def defBackground = TbtQuadBackgroundComponent.create("Interface/ui-menu-button.png", 1f, 50, 0, 100, 68, 0f, false);
def defPinkBackground = TbtQuadBackgroundComponent.create("Interface/ui-menu-button-pink.png", 1f, 50, 0, 100, 68, 0f, false);
def defWhiteBackground = TbtQuadBackgroundComponent.create("Interface/ui-menu-button-white.png", 1f, 50, 0, 100, 68, 0f, false);

def hoverCommand = new Command<Button>() {
    public void execute ( Button source ) {
        source.background = defPinkBackground;
    }
}

def stdButtonCommands = [
        (ButtonAction.Hover):[hoverCommand], 
        (ButtonAction.Down):[pressedCommand], 
        (ButtonAction.Up):[pressedCommand]
    ];

selector( "button", "amethyst" ) {
    background = defBackground
    color = pinkColor
    highlightColor = blackColor
    font = fontFQ26
    fontSize = 35
    textVAlignment = VAlignment.Center
    textHAlignment = HAlignment.Center
    //insets = new Insets3f( 2, 2, 2, 2 );
    
    buttonCommands = stdButtonCommands;
}


#76

You can’t share components across GUI elements… just like (and for the same reason that) you can’t share the same Geometry across Nodes.

…you have to clone it when you set it yourself like this. Normal styles do this automatically when applying them.


#77

Ok thanks! Back to the container, this code shrink vertically the buttons AND don’t put any padding between them:

    Container c=new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.Even));
    c.setPreferredSize(new Vector3f(500,900,0));
    main.attachChild(c);
    c.setLocalTranslation(500, 800, 0);
    campaign.addControl(bbftCampaign);
    options.addControl(bbftOptions);
    for (int i = 0; i < mains.length; i++) {
        ActionButton b = new ActionButton(mains[i]);
        b.setInsetsComponent(new DynamicInsetsComponent(0.5f, 0, 0.5f, 0));
        c.addChild(b);

 //Instead, the code below does what I want:
        //b.setLocalTranslation((MSGlobals.MS_WIDTH - 400 - 84) / 2, 650 - i * 90, 0);
        //b.setPreferredSize(new Vector3f(500,68,0));
        //main.attachChild(b);
    }

#78

I’ve checked the source of DynamicInsetsDemo. It turns out it works ok as long as you do:

    Container c=new Container();

But if you do this instead:

    Container c=new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.Even));

Then it doesn’t work.


#79

I wonder why it’s not filling vertically… hmm…


#81

The joke passed over my head :sweat_smile:.


#84

I’ve made a custom label; I get the correct background but the text isn’t visible…

selector( "big", "label", "amethyst" ) {
    background = defPinkBackground
    color = blackColor
    font = fontFQ26
    fontSize = 35
    textVAlignment = VAlignment.Center
    textHAlignment = HAlignment.Center
} 

What am I missing? thanks!