SquareBracketAssociates / BuildingApplicationWithSpec2

A book to build user interfaces using the Spec 2.0 framework.
21 stars 12 forks source link

Finish chapter "Styling applications" #82

Open koendehondt opened 2 months ago

koendehondt commented 2 months ago

Open issues from https://github.com/SquareBracketAssociates/BuildingApplicationWithSpec2/pull/60:

Other:

koendehondt commented 3 weeks ago

@Ducasse Please try something for me.

The section "How do styles work?" states that the button would scale when using a stylesheet instead of using #add:withConstraints:.

But, if you change the size of the fonts of the Pharo image using Settings/Ap- pearance/Standard Fonts/Huge, using fixed constraints, you will obtain the following result shown in Figure 14-3. You will for example not be able to see the icons because the size is not recomputed correctly. When using styles, the size of the button will also scale as shown in Figure 14-4.

I cannot reproduce that. I see no scaling of the button when using a stylesheet. Here is the code that I used, which is not part of the book (and maybe it should).

With #add:withConstraints:

presenter := SpPresenter new.
presenter
    layout: (SpBoxLayout newLeftToRight
        vAlignCenter;
        hAlignCenter;
        add: (presenter newButton icon: (presenter iconNamed: #smallLoadProject)) withConstraints: [ :constraints | constraints height: 20; width: 20 ];
        yourself);
    open

With stylesheet

application := SpApplication new.
application addStyleSheetFromString: '.application [
    .button [ Geometry { #height: 20, #width: 20 } ]
]'.
presenter := SpPresenter newApplication: application.
button := presenter newButton icon: (presenter iconNamed: #smallLoadProject).
button addStyle: 'button'.
presenter
    layout: (SpBoxLayout newLeftToRight
        vAlignCenter;
        hAlignCenter;
        add: button expand: false;
        yourself);
    open
Ducasse commented 3 weeks ago

So in that case we should remove this from the book