pharo-spec / Spec

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

A label does not apply the inherited background color from the stylesheet #1521

Open koendehondt opened 4 months ago

koendehondt commented 4 months ago

Consider this code:

| application mainLayout mainPresenter tab selectedTab |
application := SpApplication new
    addStyleSheetFromString: '.application [
        Draw { #backgroundColor: #lightRed},
        .tab [
            Container { #borderWidth: 1, #borderColor: #FFFFFF } ],
        .selectedTab [
            Draw { #backgroundColor: #FFFFFF } ]
    ]'.
mainPresenter := SpPresenter newApplication: application.
tab := mainPresenter newPresenter.
tab
    addStyle: 'tab';
    layout: (SpBoxLayout newTopToBottom vAlignCenter; add: (tab newLabel label: 'Not selected') expand: true fill: true padding: 5).
selectedTab := mainPresenter newPresenter.
selectedTab
    addStyle: 'selectedTab';
    layout: (SpBoxLayout newTopToBottom vAlignCenter; add: (selectedTab newLabel label: 'Selected') expand: true fill: true padding: 5).
mainLayout := SpBoxLayout newLeftToRight
    spacing: 10;
    add: tab expand: false;
    add: selectedTab expand: false;
    yourself.
mainPresenter layout: mainLayout; open

The stylesheet specifies that the window opens with a lightRed background color. The window contains 2 presenters called "tab" and "selectedTab", each having a nested label. The stylesheet defines a white border around a tab, and a white background for a selected tab.

However, the code opens this window:

Screenshot 2024-02-18 at 16 17 32

That is not what we expect. We expect the background color of the label with text "Selected" to be white, not the background color of the window. Apparently, the inherited background color of the surrounding "selectedTab" presenter is not applied.

Is this issue related to other issues with stylesheets and labels, such as https://github.com/pharo-spec/Spec/issues/1256?

Let's narrow down the code to the bare essentials, i.e. with 2 labels that are not nested.

| application mainLayout mainPresenter label selectedLabel |
application := SpApplication new
    addStyleSheetFromString: '.application [
        Draw { #backgroundColor: #lightRed},
        .tab [
            Container { #borderWidth: 1, #borderColor: #FFFFFF } ],
        .selectedTab [
            Draw { #backgroundColor: #FFFFFF } ]
    ]'.
mainPresenter := SpPresenter newApplication: application.
label := mainPresenter newLabel
    addStyle: 'tab';
    label: 'Not selected'.
selectedLabel := mainPresenter newLabel
    addStyle: 'selectedTab';
    label: 'Selected'.
mainLayout := SpBoxLayout newLeftToRight
    spacing: 10;
    vAlignCenter;
    add: label expand: false;
    add: selectedLabel expand: false;
    yourself.
mainPresenter layout: mainLayout; open

This code opens this window:

Screenshot 2024-02-18 at 16 39 16

That is the expected behaviour.

Conclusion: the inherited background color of a parent presenter is not applied to a label nested in that presenter.

koendehondt commented 4 months ago

Forgot to add: this was tested in Pharo 12 and Pharo 11. The behaviour is the same in both versions.