[haiku-development] Re: Layout Question With Checkboxes / Window

  • From: "Adrien Destugues" <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 06 Apr 2020 10:23:28 +0000

6 avril 2020 12:03 "Andrew Lindesay" <apl@xxxxxxxxxxxxxx> a écrit:

Hello;

Hi!
 
```
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(fMessageTextView, 1)
.Add(fConfirmMinimumAgeCheckBox, 1)
.Add(fConfirmUserUsageConditionsCheckBox, 1)
.Add(fUserUsageConditionsLink, 1)
.AddGroup(B_HORIZONTAL, 1)
.AddGlue()
.Add(fLogoutButton)
.Add(fAgreeButton)
.End()
.SetInsets(B_USE_WINDOW_INSETS);
```

Which is working well except that with the two `BCheckBox` items, the window 
width reduces to the
width of the checkboxes + label. Without the checkboxes in the layout the 
windows remains
as-specified in the constructor of the window.

Any idea why the checkboxes have this effect in this case? Let me know if 
there isn't enough
detail.

Each control defines its own preferred, minimum and maximum size. The default 
behavior is to have the window satisfy the preferred size as much as possible.

You have two options:
- Set a larger preferred (and maybe minimum) size on your checkboxes, using 
SetExplicitPreferredSize / SetExplicitMinSize
- Use a grid layout instead, and leave an empty column to the right of your 
checkboxes:

BLayoutBuilder::Grid<>(this, B_VERTICAL)
.Add(fMessageTextView, 0, 0, 2)
.Add(fConfirmMinimumAgeCheckBox, 1, 0, 1)
.Add(fConfirmUserUsageConditionsCheckBox, 2, 0, 1)
.Add(fUserUsageConditionsLink, 3, 0, 2)
.AddGroup(B_HORIZONTAL, 4, 0, 2)
.AddGlue()
.Add(fLogoutButton)
.Add(fAgreeButton)
.End()
.SetInsets(B_USE_WINDOW_INSETS);

(I may have swapped the x and y positions in the Add() arguments as I write 
this without looking at the docs)

The idea is that the message textview, usage link, and group at the bottom each 
occupy two columns, while the checkboxes occupy only the leftmost one. The free 
space next to the checkboxes removes the constraint on the window size.

-- 
Adrien.


Other related posts: