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.12k stars 578 forks source link

SlintPad: Size not updated on property assignment #6377

Open Enyium opened 6 days ago

Enyium commented 6 days ago

Consider this SlintPad demo:

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

export component Demo {
    preferred-width: 0;
    preferred-height: 0;

    property <string> prop: "a";

    VerticalBox {
        alignment: start;

        Text {
            text: root.prop;
        }

        Button {
            text: "assign";

            clicked => {
                root.prop = "abcdefghijklmnopqrstuvwxzy0123456789";
            }
        }
    }
}
hunger commented 6 days ago

Yes, that happens.

The problem is that there is no way to know when something changed size or position. So there is not reliable way to update the selection rectangle :-/

tronical commented 6 days ago

Demo's minimum-width changes. Is that not detectable?

In the snippet it works for me on the layout:

   VerticalBox {
        changed min-width => {
            debug("new min-width \{self.min-width/1px}");
        }
...

We do have an implementation of the layout_info for the component container, don't we? So maybe what's the previewed component here (Demo) can be observed?

hunger commented 6 days ago

I am interested in changes to the size of the selected element, not the window. In this case one will change the other, but that is not true in general.

tronical commented 6 days ago

Since you're retrieving the size and position via the interpreter's API (element_positions, etc.), maybe in case you want to track changes, use a PropertyTracker? Or if you expose a call to such functions directly in Slint, then storing that in a property in Slint should update automatically (and work with changed XXX =>).

ogoffart commented 5 days ago

I am interested in changes to the size of the selected element, not the window. In this case one will change the other, but that is not true in general.

I think the problem here is not the selected element, it is the constraint of the Window not being respected.

Eg, after clicking the button in the slintpad link from the description, i see this: image but the text is bigger than that and so is the minimum size, and trying to resize the component shows that.

The problem is that there is no way to know when something changed size or position.

There are ways. Especially now with changed callback. In native code there is PropertyTracker.

So there is not reliable way to update the selection rectangle :-/

Yes there are ways, but this is anyway not what this issue is about.