Last active
March 30, 2016 00:25
-
-
Save AquariusPower/56a49175aa8e35ef34ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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