Skip to content
Thomas Cashman edited this page Aug 13, 2017 · 3 revisions

This documentation is for 1.3.x

UI elements

All ui elements extend the UiElement class. The following UI elements are currently supported by the framework:

On top of these elements, there are layout elements for structuring the UI.

  • Column (can be set to width of multiple columns)
  • Row

Finally, to add your elements to the UiContainer, you must use one of the following:

The difference between a Modal and a Container is that a Modal can have navigation and hotkeys attached to it.

Loading UIs through XML

To simplify creating your UIs, all elements can be loaded and saved using Mdx.xml. The following example shows an AlignedModal which contains two Rows that have a TextButton each.

Note: the root element must always be called data.

<?xml version="1.0"?>
<data id="startGameModal">
    <visibility>VISIBLE</visibility>
    <verticalAlignment>BOTTOM</verticalAlignment>
    <horizontalAlignment>CENTER</horizontalAlignment>
    <children length="2">
    	<value class="org.mini2Dx.ui.element.Row" id="newGameRow">
            <visibility>VISIBLE</visibility>
            <children length="1">
            	<value class="org.mini2Dx.ui.element.TextButton" id="newGameButton">
            		<visibility>VISIBLE</visibility>
            		<text>New Game</text>
            		<textAlignment>CENTER</textAlignment>
            	</value>
            </children>
        </value>
    	<value class="org.mini2Dx.ui.element.Row" id="quitGameRow">
            <visibility>VISIBLE</visibility>
            <children length="1">
            	<value class="org.mini2Dx.ui.element.TextButton" id="quitGameButton">
            		<visibility>VISIBLE</visibility>
            		<text>New Game</text>
            		<textAlignment>CENTER</textAlignment>
            	</value>
            </children>
        </value>
    </children>
</data>

This can then be loaded using standard Mdx.xml calls.

AlignedModal modal = Mdx.xml.fromXml(Gdx.files.internal("startgamemodal.xml").reader(), AlignedModal.class);
uiContainer.add(modal);

If you want to call methods on the UI elements, you look look them up by their ID.

TextButton newGameButton = (TextButton) modal.getElementById("newGameButton");

Information on what XML fields are supported by different UiElements can be found on the UiElements XML wiki page.

Clone this wiki locally