[SOLVED] Sizing labels and text in Lemur

I am trying to understand how to lay out my GUI with Lemur (jME 3.1.0-stable-FINAL, lemur-1.10.1.jar). What I want is this
https://i.imgur.com/WXuDfS8.png but without doing it this way:

        guiContainer = new Container();
            
        guiContainer.addChild(new Label(longName));

        SpringGridLayout gridLayout = new SpringGridLayout(Axis.X, Axis.Y);
        Container settingsContainer = new Container(gridLayout);
        guiContainer.addChild(settingsContainer);
        
        int row = 0;
        for (Setting setting: settings) {
            TextField settingText = new TextField(Float.toString(setting.value));

            Vector3f guiContainerSize = guiContainer.getPreferredSize();
            Vector3f settingSize = new Vector3f(guiContainerSize.x - 30f, 20f, 0f);
            
            settingText.setPreferredSize(settingSize);      // <-- makes it 'work'

            setting.setGuiTextField(settingText);
            gridLayout.addChild(1, row, settingText);

            Label nameText = new Label(setting.getShortName());
//            nameText.setPreferredSize(new Vector3f(20f, 30f, 0f));
            gridLayout.addChild(0, row, nameText);
            row++;
        }

The layout is a long Label on the top with below it a few rows of short Label followed by TextField. I want the short Label to always be the same width, 20 in this case. I also want the TextField to fill the remaining width, as I know my long Label at the top will make it wide enough (and if the TextField doesn’t fill it it looks rubbish). I tried setting the preferred size of the short Label without setting the TextField size but it ignored the width and only seemed to use the height https://i.imgur.com/HbaAjaE.png. I got it to ‘work’ by reading the size of the container while I’m still filling it and setting the preferred width of the TextField to that minus 20. This is horrible. So now the question: how should I set the short Label width to 20 and have the TextField fill the rest, however much that is, especially if the Container may change size?

The formatting for this javadoc is not great but it might give you a clue:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/FillMode.html

The short answer is that you want FillMode.Last for the horizontal axis and probably FillMode.None for the vertical axis. That will give all of the extra size to the last item horizontally but won’t do any stretching at all vertically.

Wow! Quick, to the point and totally works! My thanks again.

1 Like

I thought I would post my updated code in case it helps anyone else…

        guiContainer = new Container();
            
        guiContainer.addChild(new Label(longName));

        SpringGridLayout gridLayout = new SpringGridLayout(Axis.X, Axis.Y, FillMode.Last, FillMode.None);
        Container settingsContainer = new Container(gridLayout);
        guiContainer.addChild(settingsContainer);
        
        int row = 0;
        for (Setting setting: settings) {
            Label nameText = new Label(setting.getShortName());
            gridLayout.addChild(0, row, nameText);

            TextField settingText = new TextField(Float.toString(setting.value));

            setting.setGuiTextField(settingText);
            gridLayout.addChild(1, row, settingText);

            row++;
    }
1 Like

Change that to:
SpringGridLayout gridLayout = new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.Last);

And then you can get rid of the row stuff…

change this:
gridLayout.addChild(0, row, nameText);

To:
gridLayout.addChild(nameText);

And this:
gridLayout.addChild(1, row, settingText);

To:
gridLayout.addChild(settingText, 1);

By default, if you don’t specify a row or a column then it will advance to the next in row/col in the major axis. If you specify only one value then it’s the minor axis.

So:
gridLayout.addChild(nameText);
gridLayout.addChild(settingText, 1);

…creates a new row with nameText as the first column and adds the settingText to the second column of the same row.