BButton in Layout API scaling?

Hi, is there something special about BButton in layouts, or is there some way to resize it with the Layout API? I have code similar to this:

BStringView* textView = new BStringView("label", "string");

BButton* button1 = new BButton("b1", "A", new BMessage(A_MSG));

BGridLayout* buttonLayout = BLayoutBuilder::Grid<>(this)
    .Add(textView, 0, 0)
    .Add(button1, 1, 0);

buttonLayout->SetMaxColumnWidth(1, 5);

The BButton just never scales down. If I put something else in that cell, it respects my SetMaxColumnWidth, but the BButton is resisting.

I appreciate any ideas or critiques if I’m doing it wrong.

BButton sets its size constraints depending on its label, and it adds quite a bit of margins by default.

You can force a smaller size using one of the SetExplicit*Size functions (SetExplicitMaxSize or SetExplicitMinSize)

Thanks! I tried SetExplicitMaxSize and that made the button smaller, yay! - but it still takes up the same amount of space in the layout.

Before:
nosize

After SetExplicitMaxSize:
explsize

Is there something else I need to do to get the layout to react to the smaller button?

How’d you get the box around the row?

Looks like it’s a BBox (without a title).

Maybe SetExplicitMinSize also needs to be used. Maybe the weight of the columns can be tweaked too. It’s hard to say without seeing the complete layout, as there are constraints coming from several places, for example, is the box itself allowed to be smaller, or is it constrained to remain this wide?

Yes! SetExplicitMinSize was the trick! Thank you!

I was worried about something else in the layout being the issue initially, but other controls besides BButton worked with with just the BGridLayout cell sizing.

As Pulkomandy says, it’s a BBox with the layout inside of it. The BBox has the B_FANCY_BORDER flag set on it.