rose_pine.rs

  1use std::ops::Range;
  2
  3use crate::{
  4    color::{hsla, rgb, Hsla},
  5    ThemeColors,
  6};
  7
  8pub struct RosePineThemes {
  9    pub default: RosePinePalette,
 10    pub dawn: RosePinePalette,
 11    pub moon: RosePinePalette,
 12}
 13
 14#[derive(Clone, Copy, Debug)]
 15pub struct RosePinePalette {
 16    pub base: Hsla,
 17    pub surface: Hsla,
 18    pub overlay: Hsla,
 19    pub muted: Hsla,
 20    pub subtle: Hsla,
 21    pub text: Hsla,
 22    pub love: Hsla,
 23    pub gold: Hsla,
 24    pub rose: Hsla,
 25    pub pine: Hsla,
 26    pub foam: Hsla,
 27    pub iris: Hsla,
 28    pub highlight_low: Hsla,
 29    pub highlight_med: Hsla,
 30    pub highlight_high: Hsla,
 31}
 32
 33impl RosePinePalette {
 34    pub fn default() -> RosePinePalette {
 35        RosePinePalette {
 36            base: rgb(0x191724),
 37            surface: rgb(0x1f1d2e),
 38            overlay: rgb(0x26233a),
 39            muted: rgb(0x6e6a86),
 40            subtle: rgb(0x908caa),
 41            text: rgb(0xe0def4),
 42            love: rgb(0xeb6f92),
 43            gold: rgb(0xf6c177),
 44            rose: rgb(0xebbcba),
 45            pine: rgb(0x31748f),
 46            foam: rgb(0x9ccfd8),
 47            iris: rgb(0xc4a7e7),
 48            highlight_low: rgb(0x21202e),
 49            highlight_med: rgb(0x403d52),
 50            highlight_high: rgb(0x524f67),
 51        }
 52    }
 53
 54    pub fn moon() -> RosePinePalette {
 55        RosePinePalette {
 56            base: rgb(0x232136),
 57            surface: rgb(0x2a273f),
 58            overlay: rgb(0x393552),
 59            muted: rgb(0x6e6a86),
 60            subtle: rgb(0x908caa),
 61            text: rgb(0xe0def4),
 62            love: rgb(0xeb6f92),
 63            gold: rgb(0xf6c177),
 64            rose: rgb(0xea9a97),
 65            pine: rgb(0x3e8fb0),
 66            foam: rgb(0x9ccfd8),
 67            iris: rgb(0xc4a7e7),
 68            highlight_low: rgb(0x2a283e),
 69            highlight_med: rgb(0x44415a),
 70            highlight_high: rgb(0x56526e),
 71        }
 72    }
 73
 74    pub fn dawn() -> RosePinePalette {
 75        RosePinePalette {
 76            base: rgb(0xfaf4ed),
 77            surface: rgb(0xfffaf3),
 78            overlay: rgb(0xf2e9e1),
 79            muted: rgb(0x9893a5),
 80            subtle: rgb(0x797593),
 81            text: rgb(0x575279),
 82            love: rgb(0xb4637a),
 83            gold: rgb(0xea9d34),
 84            rose: rgb(0xd7827e),
 85            pine: rgb(0x286983),
 86            foam: rgb(0x56949f),
 87            iris: rgb(0x907aa9),
 88            highlight_low: rgb(0xf4ede8),
 89            highlight_med: rgb(0xdfdad9),
 90            highlight_high: rgb(0xcecacd),
 91        }
 92    }
 93}
 94
 95pub fn default() -> ThemeColors {
 96    theme_colors(&RosePinePalette::default())
 97}
 98
 99pub fn moon() -> ThemeColors {
100    theme_colors(&RosePinePalette::moon())
101}
102
103pub fn dawn() -> ThemeColors {
104    theme_colors(&RosePinePalette::dawn())
105}
106
107fn theme_colors(p: &RosePinePalette) -> ThemeColors {
108    ThemeColors {
109        base: scale_sl(p.base, (0.8, 0.8), (1.2, 1.2)),
110        surface: scale_sl(p.surface, (0.8, 0.8), (1.2, 1.2)),
111        overlay: scale_sl(p.overlay, (0.8, 0.8), (1.2, 1.2)),
112        muted: scale_sl(p.muted, (0.8, 0.8), (1.2, 1.2)),
113        subtle: scale_sl(p.subtle, (0.8, 0.8), (1.2, 1.2)),
114        text: scale_sl(p.text, (0.8, 0.8), (1.2, 1.2)),
115        highlight_low: scale_sl(p.highlight_low, (0.8, 0.8), (1.2, 1.2)),
116        highlight_med: scale_sl(p.highlight_med, (0.8, 0.8), (1.2, 1.2)),
117        highlight_high: scale_sl(p.highlight_high, (0.8, 0.8), (1.2, 1.2)),
118        success: scale_sl(p.foam, (0.8, 0.8), (1.2, 1.2)),
119        warning: scale_sl(p.gold, (0.8, 0.8), (1.2, 1.2)),
120        error: scale_sl(p.love, (0.8, 0.8), (1.2, 1.2)),
121        inserted: scale_sl(p.foam, (0.8, 0.8), (1.2, 1.2)),
122        deleted: scale_sl(p.love, (0.8, 0.8), (1.2, 1.2)),
123        modified: scale_sl(p.rose, (0.8, 0.8), (1.2, 1.2)),
124    }
125}
126
127/// Produces a range by multiplying the saturation and lightness of the base color by the given
128/// start and end factors.
129fn scale_sl(base: Hsla, (start_s, start_l): (f32, f32), (end_s, end_l): (f32, f32)) -> Range<Hsla> {
130    let start = hsla(base.h, base.s * start_s, base.l * start_l, base.a);
131    let end = hsla(base.h, base.s * end_s, base.l * end_l, base.a);
132    Range { start, end }
133}