pharo-spec / Spec

Spec is a framework in Pharo for describing user interfaces.
MIT License
62 stars 65 forks source link

Alignment not applied when using SpBoxLayout>>#addLast: #1615

Open koendehondt opened 1 month ago

koendehondt commented 1 month ago

As mentioned in https://github.com/pharo-spec/Spec/issues/1614, it is unclear whether SpBoxLayout>>#addLast: should still be used and if not, what the alternative is. Given that Pharo itself still sends the message in Pharo 12 and Pharo 13, I like to report an issue.

Consider this code:

presenter := SpPresenter new.
presenter layout: (SpBoxLayout newLeftToRight
    vAlignCenter;
    add: (SpButtonPresenter new label: 'Button 1'; yourself);
    add: (SpButtonPresenter new label: 'Button 2'; yourself);
    yourself);
    open

Note vAlignCenter to align the two buttons in the center.

The code opens this window:

Screenshot 2024-10-04 at 08 26 09

All is good.

Now change the code:

presenter := SpPresenter new.
presenter layout: (SpBoxLayout newLeftToRight
    vAlignCenter;
    add: (SpButtonPresenter new label: 'Button 1'; yourself);
    addLast: (SpButtonPresenter new label: 'Button 2'; yourself);
    yourself);
    open

The only difference is that addLast: is sent instead of add: to add the second button. The window opens like this:

Screenshot 2024-10-04 at 08 28 25

That is not expected. Sending vAlignCenter appears not to have any impact anymore on the second button.

Now change the code to:

presenter := SpPresenter new.
presenter layout: (SpBoxLayout newLeftToRight
    vAlignEnd;
    add: (SpButtonPresenter new label: 'Button 1'; yourself);
    addLast: (SpButtonPresenter new label: 'Button 2'; yourself);
    yourself);
    open

The only change is sending vAlignEnd instead of vAlignCenter. Now the window opens like this:

Screenshot 2024-10-04 at 08 30 11

Again, we see that sending vAlignEnd has no effect on the second button.

This is a bug. The alignment should be applied to presenters that are added with SpBoxLayout>>#addLast:.