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.98k stars 568 forks source link

Preview and compiler disagree on the validity of this code #6301

Open rscarson opened 3 hours ago

rscarson commented 3 hours ago

value.round() works as expected in preview mode, but the compiler reports main.slint:95: Cannot access the field 'round' of float

export component LabeledSlider inherits LabeledField {
    in-out property <string> units;
    in-out property <int> value;
    in-out property <int> minimum;
    in-out property <int> maximum;

    callback changed(int);

    label: value + " " + units;

    v := Slider {
        minimum: root.minimum;
        maximum: root.maximum;

        width: root.width;

        changed => {
            root.value = v.value.round();
        }
    }
}
ogoffart commented 3 hours ago

That .round() was added in Slint 1.8. What version of the preview do you use and what version of Slint library used by the compiler. You may need to change the version number in your Cargo.toml