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

Reading layout properties changes behavior in slint code #7725

Open
hunger opened this issue Feb 24, 2025 · 1 comment
Open

Reading layout properties changes behavior in slint code #7725

hunger opened this issue Feb 24, 2025 · 1 comment
Labels
a:layouts Related to the layouting and positioning of the elements (mO,bT) bug Something isn't working

Comments

@hunger
Copy link
Member

hunger commented Feb 24, 2025

Bug Description

The following slint code displays a blue rectangle. When you comment out the debug(...) in line 3, the rectangle vanishes.

I hope the example is pretty minimal :-)

Reproducible Code (if applicable)

component StringWidget inherits VerticalLayout {
    init => {
        debug("INIT", self.preferred-height);
    }

    Rectangle {
        height: 100px;
        width: 100px;
        background: blue;
    }
}

export component Test inherits Window {
    xxx := Rectangle {
        property <bool> open: true;
        
        VerticalLayout {
            Rectangle {
                clip: true;
                height: xxx.open ? self.preferred-height : 0px;

                StringWidget {
                }
            }
        }
    }
}

Environment Details

  • Slint Version: master
  • Platform/OS: Linux
  • Programming Language: Slint
  • Backend/Renderer: FemtoVG

I can also reproduce the issue in slintpad version 1.9.2.

Product Impact

No response

@hunger hunger added bug Something isn't working need triaging Issue that the owner of the area still need to triage labels Feb 24, 2025
@ogoffart ogoffart changed the title Debug print changes behavior in slint code Reading layout properties changes behavior in slint code Feb 24, 2025
@ogoffart ogoffart added a:layouts Related to the layouting and positioning of the elements (mO,bT) and removed need triaging Issue that the owner of the area still need to triage labels Feb 24, 2025
@ogoffart
Copy link
Member

ogoffart commented Feb 24, 2025

Smaller testcase:

component StringWidget inherits VerticalLayout {
    init => {
        self.preferred-height;   // **** Comment this line to observe a difference
    }

    Rectangle {
        height: 100px;
        width: 100px;
        background: blue;
    }
}

export component Test inherits Window {
    Rectangle {
        height: self.preferred-height ;
        clip: true;
        StringWidget { }
    }
   
}

Note that if StringWidget ends up inlining (eg, writing StringWidget { Rectangle{} }) it also changes the behavior.
I think the issue here is that the access to self.preferred-height force the property to be materialized and then it is visible when computing constraints in the default_geometry pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:layouts Related to the layouting and positioning of the elements (mO,bT) bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants