Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

background color ignored by sub box label widget #767

Open
BrendanSimon opened this issue Dec 30, 2019 · 3 comments · May be fixed by #2484
Open

background color ignored by sub box label widget #767

BrendanSimon opened this issue Dec 30, 2019 · 3 comments · May be fixed by #2484
Labels
bug A crash or error in behavior.

Comments

@BrendanSimon
Copy link
Contributor

If I set a box with a background color, label widget children of that box are displayed correctly with the specified background.

However, if a child is another box that contains a label, then the background colour of the outer box is not propagated to the inner boxes.

Is that the expected behaviour?

I would have thought the I could set a background colour of a box and then all sub-widgets (no matter how deep in sub-boxes) would also be rendered with the same background colour.

#!/usr/bin/env python

import toga
from toga.style import Pack
from toga.style.pack import ( COLUMN, ROW, CENTER )

#!============================================================================

class Test_App( toga.App ) :

    def startup( self ) :
        #! Create the main window
        self.main_window = toga.MainWindow( title=self.name )

        body_box = toga.Box( id = 'days_box',
                             style = Pack( direction=ROW, flex=0, background_color='yellow' ),
                             children = [
                                toga.Label( "XXX" ),
                                toga.Box( children = [ toga.Label( "YYY" ) ] ),
                                toga.Label( "ZZZ" ),
                                        ],
                             ) 

        main_box = toga.Box( id = 'main_box',
                             style = Pack( direction=COLUMN, flex=0 ),
                             children = [ body_box ],
                             )

        self.main_window.content = main_box

        #! Show the main window
        self.main_window.show()

#!============================================================================

def main() :
    return Test_App( 'Test App', 'au.com.etrix.test_app' )

Note how label "YYY" does not have the specified background colour. It has the default system colour.

toga-background-color-issue

@freakboy3742
Copy link
Member

Agreed this is a little unexpected. I can certainly explain it - but that explanation is more of a rationalization than a satisfying API.

The underlying problem here is that styles don't currently cascade (or, more specifically, there's no concept of "inherit" as a value in Pack).

Broadly, we should be aiming to follow the lead of HTML and CSS here; so the YYY block should be inheriting it's color from it's parent. In this case, it's, not because it's getting the default background color.

@freakboy3742 freakboy3742 added bug A crash or error in behavior. up-for-grabs labels Apr 25, 2020
@Vipul-Cariappa Vipul-Cariappa mentioned this issue Jul 30, 2020
4 tasks
@freakboy3742
Copy link
Member

Doing some housekeeping; it occurs to me that one simple fix here might be to make the default background color for box transparent/no fill - that way, a child box will inherit the parent color by virtue of being transparent.

@mhsmith
Copy link
Member

mhsmith commented Apr 15, 2023

Only some properties are inherited in CSS, and background-color isn't one of them. However, CSS's default background-color is indeed transparent. So I think that's a better solution.

@freakboy3742 freakboy3742 linked a pull request Apr 7, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants