Is it possible to control the extended palette?

I want to create a custom theme and I want to alter the extended palette. Is this possible?

It depends on what you mean by “alter”.

The extended palette is generated from the Palette colors. There is no way to alter this logic, and it’s unclear what that would look like, but you could write your own generate function.

How would my generate function “plug-in” and work with the rest of Iced?

Ah, I see your point!

I think we could introduce a new constructor to theme::Custom:

impl Custom {
    pub fn new(palette: Palette) -> Self {
        Self::with_fn(palette, Palette::generate)
    }

    pub fn with_fn(
        palette: Palette,
        generate: impl FnOnce(Palette) -> palette::Extended,
    ) -> Self {
        Self { palette, extended: generate(palette) }
    }
}

I will look into it later!

2 Likes