Skip to content

"expand: false" does not affect checkboxes when adding them to a SpBoxlayout #1845

@koendehondt

Description

@koendehondt

Sending add: ... expand: false to add buttons

Consider this code:

mainPresenter := SpPresenter new.
button1 := mainPresenter newButton label: 'Button 1'; yourself.
button2 := mainPresenter newButton label: 'Button 2'; yourself.
button3 := mainPresenter newButton label: 'Button 3'; yourself.
mainLayout := SpBoxLayout newLeftToRight
	add: button1 expand: false;
	add: button2 expand: false;
	add: button3 expand: false;
	yourself.
mainPresenter layout: mainLayout.
mainPresenter open.
mainPresenter window extent: 500@50

The last line is included to reduce the size of the screenshots.

The snippet opens this window:

Image

All good. The default alignment is hAlignStart. Indeed, the buttons are aligned like that. expand: false is in effect, because the buttons take their natural width.

Let's add hAlignEnd:

mainPresenter := SpPresenter new.
button1 := mainPresenter newButton label: 'Button 1'; yourself.
button2 := mainPresenter newButton label: 'Button 2'; yourself.
button3 := mainPresenter newButton label: 'Button 3'; yourself.
mainLayout := SpBoxLayout newLeftToRight
	hAlignEnd;
	add: button1 expand: false;
	add: button2 expand: false;
	add: button3 expand: false;
	yourself.
mainPresenter layout: mainLayout.
mainPresenter open.
mainPresenter window extent: 500@50

We see:

Image

All good.

Let's use hAlignCenter:

mainPresenter := SpPresenter new.
button1 := mainPresenter newButton label: 'Button 1'; yourself.
button2 := mainPresenter newButton label: 'Button 2'; yourself.
button3 := mainPresenter newButton label: 'Button 3'; yourself.
mainLayout := SpBoxLayout newLeftToRight
	hAlignCenter;
	add: button1 expand: false;
	add: button2 expand: false;
	add: button3 expand: false;
	yourself.
mainPresenter layout: mainLayout.
mainPresenter open.
mainPresenter window extent: 500@50
Image

All good.

Sending add: ... expand: false to add checkboxes

mainPresenter := SpPresenter new.
checkbox1 := mainPresenter newCheckBox label: 'Choice 1'; yourself.
checkbox2 := mainPresenter newCheckBox label: 'Choice 2'; yourself.
checkbox3 := mainPresenter newCheckBox label: 'Choice 3'; yourself.
mainLayout := SpBoxLayout newLeftToRight
	add: checkbox1 expand: false;
	add: checkbox2 expand: false;
	add: checkbox3 expand: false;
	yourself.
mainPresenter layout: mainLayout.
mainPresenter open.
mainPresenter window extent: 500@50
Image

expand: false has no effect. The window's width is divided among the checkboxes.

Let's add hAlignEnd:

mainPresenter := SpPresenter new.
checkbox1 := mainPresenter newCheckBox label: 'Choice 1'; yourself.
checkbox2 := mainPresenter newCheckBox label: 'Choice 2'; yourself.
checkbox3 := mainPresenter newCheckBox label: 'Choice 3'; yourself.
mainLayout := SpBoxLayout newLeftToRight
	hAlignEnd;
	add: checkbox1 expand: false;
	add: checkbox2 expand: false;
	add: checkbox3 expand: false;
	yourself.
mainPresenter layout: mainLayout.
mainPresenter open.
mainPresenter window extent: 500@50

We see:

Image

The screenshot is the same as before. Using hAlignEnd has no effect.

Let's use hAlignCenter:

mainPresenter := SpPresenter new.
checkbox1 := mainPresenter newCheckBox label: 'Choice 1'; yourself.
checkbox2 := mainPresenter newCheckBox label: 'Choice 2'; yourself.
checkbox3 := mainPresenter newCheckBox label: 'Choice 3'; yourself.
mainLayout := SpBoxLayout newLeftToRight
	hAlignCenter;
	add: checkbox1 expand: false;
	add: checkbox2 expand: false;
	add: checkbox3 expand: false;
	yourself.
mainPresenter layout: mainLayout.
mainPresenter open.
mainPresenter window extent: 500@50

We see:

Image

Again, no change.

Sending add:width:

For completeness, let's use a fixed width for the checkboxes:

mainPresenter := SpPresenter new.
checkbox1 := mainPresenter newCheckBox label: 'Choice 1'; yourself.
checkbox2 := mainPresenter newCheckBox label: 'Choice 2'; yourself.
checkbox3 := mainPresenter newCheckBox label: 'Choice 3'; yourself.
mainLayout := SpBoxLayout newLeftToRight
	add: checkbox1 width: 80;
	add: checkbox2 width: 80;
	add: checkbox3 width: 80;
	yourself.
mainPresenter layout: mainLayout.
mainPresenter open.
mainPresenter window extent: 500@50

Then we see:

Image

All good.

Conclusion

expand: false does not affect checkboxes when adding them to a SpBoxlayout. That is a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions