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.43k stars 595 forks source link

Nullish coalescing operator (??) or somehow handling `void` #6666

Open TheColorRed opened 4 hours ago

TheColorRed commented 4 hours ago

I am looking for something like a Nullish coalescing operator (??) (syntax taken from JavaScript). When trying to compare void I get the following error:

Cannot convert void to length

I would like a way to to set a value to something default if the value is void or some type of nullish value, maybe either like this or using a ternary operator that just falls back to the else portion.

width: some-variable ?? 100%;

Here is what I tried:

export struct UIProject {
    zoom: float,
    image-width: length,
}

export global AppState {
    in-out property <[UIProject]> projects;
}

export component Stage inherits ScrollView {
    property <float> zoom: AppState.projects[AppState.active-project].zoom;
    property <length> image-width: AppState.projects[AppState.active-project].image-width;
    property <length> display-width: image-width * zoom;
    Rectangle {
        width: zoom > 0 ? display-width : 100%;
    }
}
TheColorRed commented 3 hours ago

After doing some research, it looks like the issue is with the 100% at least in this case. changing the 100% to 100px the error goes away. However, a px size is not what I am looking for.

Cannot convert percent to length