Skip to content

Instantly share code, notes, and snippets.

@AquariusPower
Last active March 30, 2016 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AquariusPower/56a49175aa8e35ef34ff to your computer and use it in GitHub Desktop.
Save AquariusPower/56a49175aa8e35ef34ff to your computer and use it in GitHub Desktop.
package tests;
import com.jme3.app.SimpleApplication;
import com.jme3.math.Vector3f;
import com.jme3.system.AppSettings;
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.TextField;
import com.simsilica.lemur.style.BaseStyles;
public class LemurLayoutCrashTest extends SimpleApplication {
public static void main( String... args ) {
LemurLayoutCrashTest main = new LemurLayoutCrashTest();
AppSettings as = new AppSettings(true);
as.setWidth(640);
as.setHeight(480);
main.setSettings(as);
main.setShowSettings(false);
main.start();
}
private TextField tf;
@SuppressWarnings("unchecked")
@Override
public void simpleInitApp() {
GuiGlobals.initialize(this);
BaseStyles.loadGlassStyle();
GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
int iMargin=10;
Container myWindow = new Container();
myWindow.setName("myWindow");
myWindow.setPreferredSize(new Vector3f(
getContext().getSettings().getWidth()-iMargin*2,
1,
0)); //still crashes even if Z is set to 1 or 10
guiNode.attachChild(myWindow);
myWindow.setLocalTranslation(iMargin, getContext().getSettings().getHeight()-iMargin, 0);
int iIndex=0;
Label lbl = new Label("test");
/**
* click on any button to copy the textfield text to the label
*/
for(int i=0;i<4;i++){
Button clickMe = myWindow.addChild(new Button("Click Me "+i),0,iIndex++);
clickMe.setName("clickMe"+i);
clickMe.setPreferredSize(new Vector3f(50,1,0)); //buttons do not obbey it?
clickMe.addClickCommands(new Command<Button>() {
@Override
public void execute( Button source ) {
lbl.setText(tf.getText());
}
});
}
//enabling this will prevent the crash
boolean bFixedLabelWidth=false;if(bFixedLabelWidth)lbl.setPreferredSize(new Vector3f(getContext().getSettings().getWidth()/2,1,0));
lbl.setName("lbl");
myWindow.addChild(lbl,0,iIndex++);
/**
* one character less on the text field and it will not crash
*/
tf = new TextField("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567");
tf.setName("tf");
// tf.setPreferredSize(new Vector3f(100,1,0)); //z 10 crash too
tf.setPreferredWidth(100); //works fine!
tf.setPreferredLineCount(1);
myWindow.addChild(tf,0,iIndex++);
}
@Override
public void simpleUpdate(float tpf) {
super.simpleUpdate(tpf);
GuiGlobals.getInstance().requestFocus(tf);
try{Thread.sleep(1000/60);}catch(Exception e){} //let GPU fan rest
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment