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.56k stars 604 forks source link

Should outer default value of two-way binding really supersede inner non-default? #6402

Closed Enyium closed 1 month ago

Enyium commented 1 month ago

Consider this SlintPad demo (see comments):

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

component Inner {
    in-out property <string> prop: "inner";
}

export component Demo {
    //in-out property <string> prop: "outer"; // This should supersede.
    in-out property <string> prop; // Default shouldn't necessarily supersede.
    //in-out property <string> prop <=> el.prop; // With this, you also get the inner value. (Below binding must be commented out.)

    VerticalBox {
        alignment: start;

        el := Inner {
            prop <=> root.prop;
        }

        Text {
            text: "\"\{el.prop}\"";
        }
    }
}

This demo shows that the value of el.prop is an empty string instead of "inner". As far as I can see now, it isn't desirable for the implicit default value "" to supersede the inner more specific value. I definitely had a case where the superseding implicit defaults on component usages were intruding and undesired over the specific default from inside the component.

ogoffart commented 1 month ago

Yes, that's right, when setting a binding, the right hand side of the binding wins. I took the opportunity to update the documentation in https://github.com/slint-ui/slint/pull/6419

For context, this was done in https://github.com/slint-ui/slint/pull/1821 which explain the rational. (the behavior that you described was how it was first implemented)