Maybe this is fixed in the updated syntax, but with the current version of 0.3.3 (using rust) issues exist in how/where properties are declared that determine if two-way bindings are possible in .slint files.
Regular properties work with two-way bindings as expected:
export Sample1 := Rectangle {
in-out property <string> myprop1;
in-out property <int> myprop2;
LineEdit { text <=> myprop1; }
SpinBox { value <=> myprop2; }
}
But if a struct is used things break:
export struct MyStruct := {
string_prop: string,
int_prop: int,
}
export Sample2 := Rectangle {
in-out property <MyStruct> myprops;
LineEdit { text <=> myprops.string_prop; } // gives: The expression in a two way binding must be a property reference
LineEdit { text: myprops.string_prop; } // One-way bindings work
}
There is a workaround for the struct problem using inheritance though (not sure if slint is intended to be used like this):
export FakeStruct := Rectangle {
in-out property <string> string_prop;
in-out propert <int> int_prop;
}
export Sample2a := FakeStruct {
LineEdit { text <=> string_prop; } // now that string_prop is inherited it works
}
Also the use of arrays (at least in for loops) may break things:
// This one works
export Sample3 := Rectangle {
in-out property <[string]> multiprop;
in-out property <[length]> widths;
for my_prop[idx] in multiprop : HorizontalLayout {
width: widths[idx];
Text { text: my_prop; }
}
}
// But this doesn't
export Sample3 := Rectangle {
in-out property <[string]> multiprop;
in-out property <[length]> widths;
for my_prop[idx] in multiprop : HorizontalLayout {
width: widths[idx];
Text { text <=> my_prop; } // gives: The expression in a two way binding must be a property reference
}
}
// And neither does this
export Sample3 := Rectangle {
in-out property <[string]> multiprop;
in-out property <[length]> widths;
in-out property <string> sometext;
for my_prop[idx] in multiprop : HorizontalLayout {
width <=> widths[idx]; // gives: The expression in a two way binding must be a property reference
Text { text <=> sometext; } // now works with non-array property
}
}
Would the above examples be expected to work? Feel free to point out any incorrect assumptions on my part or any part of the documentation that mentions or explains the observed behaviour that I might have missed.
Maybe this is fixed in the updated syntax, but with the current version of 0.3.3 (using rust) issues exist in how/where properties are declared that determine if two-way bindings are possible in .slint files.
Regular properties work with two-way bindings as expected:
But if a struct is used things break:
There is a workaround for the struct problem using inheritance though (not sure if slint is intended to be used like this):
Also the use of arrays (at least in for loops) may break things:
Would the above examples be expected to work? Feel free to point out any incorrect assumptions on my part or any part of the documentation that mentions or explains the observed behaviour that I might have missed.