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.93k stars 565 forks source link

`@linear-gradient` macro broken in ternary operator #1235

Closed levrik closed 2 years ago

levrik commented 2 years ago

When using the @linear-gradient macro in the 2nd position of the ternary operator, just the first color value found is being used.

Rectangle { 
    background: true ? @linear-gradient(90deg, #fff 0%, #000 100%) : #000;
}

image

Rectangle { 
    background: false ? #000 : @linear-gradient(90deg, #fff 0%, #000 100%);
}

image

I simplified the code a lot for demonstration purposes.

These 2 codeblocks can be just copied into Window of https://slint-ui.com/releases/0.2.2/editor/ to reproduce.

I could work around by moving the gradients into a global and just reference it from inside the ternary operator. Looks like a bug in the parser to me.

Edit: Above statement isn't true. It's also not working when using a global.

ogoffart commented 2 years ago

Thanks for the report. Looks like the ternary operator always convert to the type of the first operand when both ways are possible.

Will look into it.

levrik commented 2 years ago

@ogoffart Ah, this makes sense. Thanks a lot! I've worked around by ensuring that the gradient always comes first for now.