slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

Infinite Window Resize Bug #4333

Closed scout0773 closed 10 months ago

scout0773 commented 10 months ago

Just messing around with slint ui and Rust. Found this weird bug that I haven't seen mentioned elsewhere so maybe I'm the first one to experience it, not sure. Down below is my appwindow.slint file, and after running cargo run everything works fine until you try to resize the window. It starts to extend to the right side of my screen infinitely. Here's a video of what happens: https://streamable.com/rges9v Working on a Macbook Air M2 by the way so I don't know how relevant that'll be.

import { Button, VerticalBox, LineEdit, CheckBox } from "std-widgets.slint";

export component AppWindow inherits Window {
    VerticalLayout {
        padding: 10px;
        spacing: 10px;
        Text {
            text: "IronPass";
            horizontal-alignment: center;
            font-size: 24px;
            font-weight: 900;
        }

        CheckBox {
            width: parent.width;
            height: 15px;
            text: "Uppercase";
        }

        CheckBox {
            width: parent.width;
            height: 15px;
            text: "Lowercase";
        }

        CheckBox {
            width: parent.width;
            height: 15px;
            text: "Numbers";
        }

        CheckBox {
            width: parent.width;
            height: 15px;
            text: "Special characters";
        }
    }
}
ogoffart commented 10 months ago

Thanks a lot for filling an issue!

This is the same issue as https://github.com/slint-ui/slint/issues/2902

width: parent.width; cause the CheckBox's size constraints to be the same size of the layout. But the layout need to add some space for the padding. So the size constrinats of the layout becomes bigger than its current size, and on the next frame the window is resized to accomodate for that. The fix here is to remove the width: parent.width; as the layout does that automatically anyway. We should ideally detect such loop at compile time: https://github.com/slint-ui/slint/pull/3997

Closing as duplicated of https://github.com/slint-ui/slint/issues/2902 , but thanks anyway for reporting.