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.53k stars 600 forks source link

Feature: Additional slint color type methods #4735

Closed flukejones closed 8 months ago

flukejones commented 8 months ago

More often than not I'm finding I need to make callbacks to be able to do other kinds of manipulations for slint color type. For example:

    ui.global::<AuraPageData>().on_blend_colour(|c1, c2, f| {
        let c1: RgbaColor<f32> = RgbaColor::from(c1);
        let c2: RgbaColor<f32> = RgbaColor::from(c2);
        RgbaColor {
            alpha: 0.0,
            red: c1.red + (c2.red - c1.red) * f,
            green: c1.green + (c2.green - c1.green) * f,
            blue: c1.blue + (c2.blue - c1.blue) * f,
        }.into()
    });

It would also be very handy to have direct access to a <color>.red() so that some other kinds of ops can be done in slint code itself, plus being able to pull individual channels out.

flukejones commented 8 months ago

Something else I'd really like to see is a conversion to/from hex string as this would enable hex input for colour pickers.

tronical commented 8 months ago

Sounds like a good idea to me (color channel accessors).

tronical commented 8 months ago

Duplicate of #911

flukejones commented 8 months ago

I'll close in favour of the linked issue.

tronical commented 8 months ago

Since we support a conversion from hex to a color in the language itself, it seems like it might make sense to also offer this as a run-time API. I've created a separate ticket for it (as the description of this relates to #911 ): https://github.com/slint-ui/slint/issues/4745

tronical commented 8 months ago

Ah, our paths crossed - thanks for closing :)