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.58k stars 604 forks source link

Support for `rem` values in `min()`/`max()` #6697

Open Enyium opened 2 weeks ago

Enyium commented 2 weeks ago

min()/max() already support some type heterogeneity: You can use px with phx. However, to specify one of the values as a rem value, you have to multiply with root.default-font-size:

export component AppWindow inherits Window {
    property <length> size: 50px;

    Rectangle {
        min-width: max(20 /*rem*/ * root.default-font-size, root.size);
        background: skyblue;
    }
}

Is there a chance that rem values can be mixed with px/phx in min()/max() (and maybe others like clamp() and mod())? It would look like this:

export component AppWindow inherits Window {
    property <length> size: 50px;

    Rectangle {
        min-width: max(20rem, root.size);
        background: skyblue;
    }
}
ogoffart commented 2 weeks ago

Indeed, the Type::Rem is not handled in https://github.com/slint-ui/slint/blob/2d944b242c895c4f666fb21fce02298bd64afc25/internal/compiler/builtin_macros.rs#L84

I think actually min/max should ideally work with any number type (there is no easy way to check for that, one way is ty.as_unit_product().is_some()