slint-ui / slint

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

When I set the absolute position, the x doesn't change #4242

Closed boluoyu closed 8 months ago

boluoyu commented 8 months ago
export component MyRec inherits Window {
    Rectangle {
        width: 300px;
        height: 300px;
        border-width: 3px;
        border-color: red;

       rec1:= Rectangle {

            width: 100px;
            height: 100px;
            border-width: 3px;
            border-color: yellow;
            background: red;
        }
        TouchArea {

            clicked => {
                debug("before:", rec1.absolute-position,rec1.x,rec1.y);
                rec1.absolute-position.x = 0px;
                rec1.absolute-position.y = 0px;
                debug("after:", rec1.absolute-position,rec1.x,rec1.y);

            }
        }

    }
}

Is this a bug?

ogoffart commented 8 months ago

Thanks for opening an issue.

The absolute-position property is actually a read-only property.
However due to a bug (already fixed in master by https://github.com/slint-ui/slint/pull/4148), we wouldn't report error. But the next version will report an error.

It is not possible to change the position of an item by changing its absolute position.

What you can do is to assign the x and y property and substract the paren's absolute position. For example:

rec1.x = 0px - rec0.absolute-position.x;
rec1.y = 0px - rec0.absolute-position.y;

Where rec0 is the parent Rectangle

boluoyu commented 8 months ago

Thank you very much. I'll try