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

Math Postfix expressions on numbers #5328

Closed ogoffart closed 1 month ago

ogoffart commented 3 months ago

We should support for postfix (memeber) functions on number for math expressions:

So we could write things like

foo.clamp(0, 1)
foo.max(bar)
foo.floor()
foo.round()
foo.abs()
foo.sin()
ogoffart commented 3 months ago

In order to implement this, we need to add lookup to the integer types in this trait implementation: https://github.com/slint-ui/slint/blob/b80f4552bda04fe61af287929a327c1f56906e0b/internal/compiler/lookup.rs#L917 Then add a NumberExpression similar to StringExpression in that file.

WilstonOreo commented 3 months ago

This looks useful, especially for the clamp function! The clamp function, like min/max could support other types than float/int though, e.g. a duration or length.

Btw: I really like how things in lookup.rs are implemented!