[Lemur] Component size can't be set

Hello everyone,
I have yet another problem with lemur, which is probably related to me being a newb with the library, but I can’t find anything in the docs either. Now, I have this code:
/---------------------------------------------Main Menu---------------------------------------------/
menuContainer = new Container();
menuContainer.setPreferredSize(new Vector3f(program.getSettingVariables().WIDTH, program.getSettingVariables().HEIGHT, 0));
menuContainer.setLocalTranslation(0, program.getSettingVariables().HEIGHT, 0);
menuContainer.setBackground(new QuadBackgroundComponent(program.getAssetManager().loadTexture(“Interface/Menu/BG.png”)));

        //TODO: Correct size of components
        Container buttons = new Container();
        buttons.setPreferredSize(new Vector3f(300, 200, 0));
        buttons.setLocalTranslation(program.getSettingVariables().WIDTH / 2 - 150, program.getSettingVariables().HEIGHT - 50, 0);
        menuContainer.addChild(buttons);
        
        Label title = new Label(StaticVariables.name);
        title.setFontSize(50);
        buttons.addChild(title);
        
        Button newGame = buttons.addChild(new Button("New Game"));
        newGame.addClickCommands(new Command<Button>()
        {
            @Override
            public void execute(Button source)
            {
                program.getStateManager().getState(MenuState.class).startGame();
            }
        });
        
        Button loadGame = buttons.addChild(new Button("Load Game"));
        loadGame.addClickCommands(new Command<Button>()
        {
            @Override
            public void execute(Button source)
            {
                program.getStateManager().getState(MenuState.class).loadGame();
            }
        });
        
        Button settings = buttons.addChild(new Button("Settings"));
        settings.addClickCommands(new Command<Button>()
        {
            @Override
            public void execute(Button source)
            {
                program.getStateManager().getState(MenuState.class).settings();
            }
        });
        
        Button quit = buttons.addChild(new Button("Quit"));
        quit.addClickCommands(new Command<Button>()
        {
            @Override
            public void execute(Button source)
            {
                program.stop();
            }
        });

But it just always resizes the buttons to basically occupy the full window, and the text is at the left.
Any ideas why this happens?

Because buttons is a child of menuContainer then it will be laid out by menuContainer. Your preferred size is only a suggestion at that point.

What is the actual effect you want? Then I can help.

I would like to have the buttons container be the size I want it to,
and lay out everything in it as normal. A reduced size of the container would then result in the buttons having the right size.
Any other way to get the buttons (and the label) to take the size and position I want them to would also work.

Well, if you don’t want them as a child of the parent then don’t add them as a child. Else they are part of the layout and they will be laid out.

Or if you want them as a child of the parent but want to control their size relative to the parent then give the buttons container some insets to make it smaller.

As it stands, you’ve added the buttons container as a child of a container that has a SpringGridLayout… so it will try to stretch them to be as big as the cell’s size… which in this case will be full width.

Hmmm… I guess you could nest them under another Container without a layout or with a SpringGridLayout where the fill mode is set to FillMode.None.

2 Likes

That did it.
Thanks a lot!