Hello,
Can I have an example with a control “nifty-drop-down” ?
Thanks in advance
There is one in the nifty-examples project: http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty-examples/trunk/src/main/java/de/lessvoid/nifty/examples/controls/
It’s a bit hidden because this example does really demonstrate a lot more but you should find a working nifty-drop-down example within it.
It’s all available online
http://nifty-gui.svn.sourceforge.net/viewvc/nifty-gui/nifty-examples/trunk/src/main/resources/controls/controls.xml?revision=1136&view=markup
You could svn check out the whole project, you know?
PS: consider donation for nifty gui
Hehe,
It’s a reflex I still don’t have, thank you for the link
I will try to go there before asking next time.
Edit : I still have a problem with the dropDown element.
Since I use it with JME3 I have to intercepts the clicks done on it so that they won’t trigger actions in the 3D scene.
I’ve managed for the opening of the dropDown :
[xml]
|control id=“attitudeDropDown” name=“dropDownControl” |
|interact onClick=“clickOnAttitudeDropDown()” /|
|/control|
[/xml]
[java]
public void clickOnAttitudeDropDown( )
{
interceptClick();
if( attitudeElt == null )
loadAttitudeDropDown( );
attitudeElt.dropDownClicked();
}
[/java]
But I don’t know which method I have to override for intercepting the click when the user choose the new item in the list.
I tried to override the method dropDownSelectionChanged()
But it’s too late, it occurs after the treatment of the click by the 3D scene
Edit2 : Is there a way to let the dropdown goes up instead of going down when clicked ?
Edit2: Yes, that’s possible but you might not like it! You’ll need your own style for this. The best way would probably be to copy the complete style from the black- or grey-style, e.g.: “dropdown/nifty-drop-down.xml” to your own style file, include it in your xml with "<useStyles filename=“my-style.xml>” and change the style “nifty-drop-down#list-panel”. The Nifty effects in there define how the dropdown drops down or up. You could even make it left, right or something completly different
Edit1: Uhm, I don’t think you can intercept that call directly The control it is called on is an internal control inside of the control definition of the drop down control. You cant really access this - without creating your own version of the control too, which might be the only solution at the moment.
A better solution will be the fixing of the event handling in Nifty/JME3 but this will take some time, I’m afraid.
Ok, thanks for the answers.
I will try to create my own style
Otherwise, I’ve encountered something strange : I tried to replace the dropdown with a layer that pop up when clicking on a button ( which was previously the dropdown )
I works find but : When I hide the panel I loose control of my gui and can’t click on a button anymore.
Here is the code of my panel :
[xml]
|!–
Popup for choosing attitude
–|
|layer id=“attitudeLayer” childLayout=“center” height=“100%” width=“100%” |
|panel id=“attitudePanel” height=“150px” width=“100%” align=“left” valign=“bottom” childLayout=“horizontal” visibleToMouse=“true”|
|panel width=“650px” /|
|panel height=“100%” width=“150px” align=“left” valign=“bottom” childLayout=“overlay” visibleToMouse=“true”|
|image height=“100%” width=“100%” filename=“portraitBack.png” imageMode=“normal” /|
|panel height=“100%” width=“100%” align=“center” valign=“center” childLayout=“horizontal” visibleToMouse=“true”|
|panel width=“20px” /|
|panel width=“80%” height=“100%” align=“center” valign=“center” childLayout=“vertical” visibleToMouse=“true”|
|panel height=“20px” /|
|control type=“button” height=“30px” width=“110px” style=“ae-button” label=“Cool” |
|interact onClick=“changeAttitude(Cool)” /|
|/control|
|panel height=“10px” /|
|control type=“button” height=“30px” width=“110px” style=“ae-button” label=“Normal” |
|interact onClick=“changeAttitude(Normal)” /|
|/control|
|panel height=“10px” /|
|control type=“button” height=“30px” width=“110px” style=“ae-button” label=“Agressive” |
|interact onClick=“changeAttitude(Agressive)” /|
|/control|
|panel height=“20px” /|
|/panel|
|panel width=“20px” /|
|/panel|
|control id=“btnSelectCharacter” type=“button” style=“portraitFrame” height=“100%” width=“100%” /|
|/panel|
|/panel|
|/layer|
[/xml]
And the method changeAttitude :
[java]
public void changeAttitude( String attitude )
{
interceptClick();
attitudeElt.setText( attitude );
attitudePopup.hide();
}
[/java]
the line that pose problem is : attitudePopup.hide();
if I call it inside this method, I loose control over my GUI.
I can still call it from another button of my gui.
Is there somthing I’m missing ?
if I call it inside this method, I loose control over my GUI.
What does that mean exactly? Loosing control? Loosing the keyboard focus or what exactly happens?
The GUI doesn’t detect that my mouse is hover a button or not and it seems that the interaction are disabled to .
( If i click on a button
[xml]
|control type=“button” height=“30px” width=“110px” style=“ae-button” label=“Agressive” |
|interact onClick=“changeAttitude(Agressive)” /|
|/control|
[/xml]
the method changeAttitude(…) is not called )
This problem only occurs when I try to hide the panel containing the button that triggered the events.
Do I need to queue the command of hidden a panel ( like for adding a button to a panel ? )
What Nifty Version do you use?
Just tried that with the SVN version (and the Lwjgl Renderer) and it works as far as I see o_O
There was a change not so long ago, maybe you’re using an older version?
@public
Make sure that hidden elements will lose the keyboard/mouse focus when the parent element gets hidden
(kudos go to nifty user gaba1978 for figuring this out)
I’m still usinf the jme3 package form 11/16/2010.
I will try to update