hi guys,
i m very confused about nifty 1.3 … well about nifty at all
all i did until now was some static things… now i tried to make some dynamical tries… but i dont understand whats now important …
i tried a bit around nifty 1.2 (but never really understood) and now with nifty 1.3 i m totally confused.
how do u use the label for example?
[xml]
<nifty xmlns=“http://nifty-gui.sourceforge.net/nifty.xsd” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty.xsd http://nifty-gui.sourceforge.net/nifty.xsd”>
<useStyles filename=“nifty-default-styles.xml” />
<useControls filename=“nifty-default-controls.xml” />
<controlDefinition name=“label” controller=“mygame.Controller”>
<text id=“text-id” font=“A.fnt” text=“old text” textHAlign=“center” textVAlign=“center” width=“100%” height=“100%” x=“0” y=“0” color="#f00f" />
</controlDefinition>
<screen id=“start” controller=“mygame.Controller”>
<layer id=“layer” backgroundColor="#003f" childLayout=“center”>
<panel id=“panel” height=“25%” width=“35%” align=“center” valign=“center” backgroundColor="#f60f" childLayout=“center” visibleToMouse=“true”>
<interact onClick=“change()”/>
<effect>
<onStartScreen name=“move” mode=“in” direction=“top” length=“300” startDelay=“0” inherit=“true”/>
<onEndScreen name=“move” mode=“out” direction=“bottom” length=“300” startDelay=“0” inherit=“true”/>
<onHover name=“pulsate” scaleFactor=“0.008” startColor="#f600" endColor="#ffff" post=“true”/>
</effect>
<control name=“label” id =“label” align=“center”/>
</panel>
</layer>
</screen>
</nifty>
[/xml]
like this should be the xml, nor?
the control “label” is there (btw should there only id? or only name? or both?)
and above a control definition for the “label”
now the java … well … i see that LabelControl is deleted for some reasons … but Label, LabelBuilder and CreateLabelControl are there, so i think i have to work with this… but could someone post an actually working example of the label for example, so i know how to use it in general?
i would really appreciate it!
my attemps so far :
[java]
Label l;
…
…
l = screen.findControl(“label”, ) [/java]
as 2nd argument i would need a controlClass… dunno what to do
thx in advance
Terry
Label contols are used to be display texts
All controls works like that :
[java]
<control id ="ID" name="CONTROLNAME" [parametersForAllElement] [parametersSpecificToThisControl] />
[/java]
parametersForAllElement :
Those parameters are use to define the size and the position of the element
You can use : width, height, align, valign, etc…
parametersSpecificToThisControl :
Those one depend from the control used.
For labels, you can use : text, font, textHAlign, textVAlign, …
For example, you can create a label like that :
[java]
<control id ="title" name="label" width="100%" height="50px" valign="top" text="My title" textHAlign="right" />
[/java]
If you want to retrieve the label in the JAVA part, you have two choices :
Choice 1 :
You can retrieve the real controller of the element
Here is the definition of the control
[java] <controlDefinition style="nifty-label" name="label" controller="de.lessvoid.nifty.controls.label.LabelControl">[…][/java]
So you use something like this to retrieve it :
[java]
Element element = screen.findElementByName( "title" );
LabelControl control = element.getControl( LabelControl.class );
control.setText( "New title" );
[/java]
Or the shortcut :
[java]
LabelControl control = screen.findControl( "title", LabelControl.class );
control.setText( "New title" );
[/java]
This is the best method for custom control you create, but there is an easier method for classic Nifty controls.
Choice 2 :
Classic Nifty controls are implementing different services that enable you to interact with the control
Check this page to see which services are available for your control :
http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Nifty_Standard_Controls_(Nifty_1.3)
For the label control, you have only one service : Label
So you use something like that :
[java]
Label service = screen.findNiftyControl( "title", Label.class );
[/java]
This one is cleaner.
The class Label is an interface implemented by the LabelControl that filter what can be use to manage the control.
wow now its crystal clear!
i already thought it might be just this simple, but that…well …
i got confused, that the 2nd argument has to be a ControllerClass… didnt thought Label itself woud do the job ^^
THX
i still dont know what nifty is capable of, but this was A BIG help!
greetings
Terry
Excellent explanation didialchichi!
@terry: please forget Choice 1 and go with Choice 2 for the build-in Nifty controls! Choice 2 is the prefered way for this…