Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variations in Theme::from_source_color #18

Closed
allan2 opened this issue Mar 15, 2024 · 1 comment
Closed

Variations in Theme::from_source_color #18

allan2 opened this issue Mar 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@allan2
Copy link
Contributor

allan2 commented Mar 15, 2024

Issue

#5 related

I was looking into the variations in theme outputs and this is what I've learned:

  1. This crates's Theme::from_source_color is similar to Material Theme Builder's, but not identical. Mismatched colors comparing to Material Theme Builder #5 (comment)
  2. The JS themeFromSourceColor is based on CorePalette.of(source).
  3. This crate's CorePalette is correct, matching C++ and JS implementations.
  4. The JS themeFromSourceColor is not the same as Material Theme Builder or this crate's.

Proposed

  1. Document the behaviour above theme_from_source_color.
  2. Offer a version of theme_from_source_color that behaves like the JS implementation (where primary is CorePalette::of(source).primary.tone(40).

In my testing, I have already written a lot of the code to do the second version. It would be a scheme based on MaterialLightColorSchemeFromPalette:

impl SchemeFromPalette {
    /// Generates a light colour scheme from a core palette.
    ///
    /// This has less fields than [`Scheme`].
    pub fn light(argb: Argb) -> Self {
        let palette = CorePalette::of(argb);

        Self {
            primary: palette.primary.tone(40),
            on_primary: palette.primary.tone(100),
            primary_container: palette.primary.tone(90),
            on_primary_container: palette.primary.tone(10),
            secondary: palette.secondary.tone(40),
            on_secondary: palette.secondary.tone(100),
            secondary_container: palette.secondary.tone(90),
            on_secondary_container: palette.secondary.tone(10),
            tertiary: palette.tertiary.tone(40),
            on_tertiary: palette.tertiary.tone(100),
            tertiary_container: palette.tertiary.tone(90),
            on_tertiary_container: palette.tertiary.tone(10),
            error: palette.error.tone(40),
            on_error: palette.error.tone(100),
            error_container: palette.error.tone(90),
            on_error_container: palette.error.tone(10),
            background: palette.neutral.tone(99),
            on_background: palette.neutral.tone(10),
            surface: palette.neutral.tone(99),
            on_surface: palette.neutral.tone(10),
            surface_variant: palette.neutral_variant.tone(90),
            on_surface_variant: palette.neutral_variant.tone(30),
            outline: palette.neutral_variant.tone(50),
            outline_variant: palette.neutral_variant.tone(80),
            shadow: palette.neutral.tone(0),
            scrim: palette.neutral.tone(0),
            inverse_surface: palette.neutral.tone(20),
            inverse_on_surface: palette.neutral.tone(95),
            inverse_primary: palette.primary.tone(80),
        }
    }
@Aiving Aiving added the enhancement New feature or request label Mar 16, 2024
@Aiving
Copy link
Owner

Aiving commented May 1, 2024

closed in 0.3.0

@Aiving Aiving closed this as completed May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants