Nifty Flow/Grid layout?

Hello All,

I’m fleshing out the basics of my current game project. It’s an RTS style game and I want to have the GUI have buttons for the actions the player can perform. As the game progresses, or unit selections change, different actions will be available at any given moment.

I want to display the actions, as a small image and action name, in a grid pattern. If this were swing, I’d just use panels of equal width, and a flow layout and add them, the flow layout would then fill the top row first and move down a row when it was full. Is there a way to do this with Nifty, or will I have to make a new panel element for every full row and lay it out myself?

Also is there a way to pass an object through to an element? I need a way to get the action from the button that the player clicks, At the moment I plan to use the name of the action to look up the action, but if there’s a way to attach the action directly I would prefer it.

No, unfortunally there’s no way to have a Flow layout outof the box with nifty-gui.

will I have to make a new panel element for every full row and lay it out myself?
Yes this could be a workaround , or you can create a new class that implements LayoutManager interface and set it to your desired element( just call setLayoutElement(yourlayoutmanger) on your element instance. If you have some practice with github you can also fork nifty-gui repo and add a new layoutManager or modify the HorizontalLayout manager. Actually is not to complicated you have just to modify this class to achieve a nice flow behavior. If you want to create a new class , it must implement the LayoutManager interface and you should change the Convert class accordingly.

About attach an object to an element I’m sorry with 1.3 is impossibile, but if you use the 1.4 version there a very useful setUserdata method , for this cases.