theme.rs (4326B)
1 use egui::{style::Interaction, Color32, FontId, Style, Visuals}; 2 use notedeck::{ColorTheme, NotedeckTextStyle}; 3 use strum::IntoEnumIterator; 4 5 pub const PURPLE: Color32 = Color32::from_rgb(0xCC, 0x43, 0xC5); 6 const PURPLE_ALT: Color32 = Color32::from_rgb(0x82, 0x56, 0xDD); 7 //pub const DARK_BG: Color32 = egui::Color32::from_rgb(40, 44, 52); 8 pub const GRAY_SECONDARY: Color32 = Color32::from_rgb(0x8A, 0x8A, 0x8A); 9 const BLACK: Color32 = Color32::from_rgb(0x00, 0x00, 0x00); 10 const RED_700: Color32 = Color32::from_rgb(0xC7, 0x37, 0x5A); 11 const ORANGE_700: Color32 = Color32::from_rgb(0xF6, 0xB1, 0x4A); 12 13 // BACKGROUNDS 14 const SEMI_DARKER_BG: Color32 = Color32::from_rgb(0x39, 0x39, 0x39); 15 const DARKER_BG: Color32 = Color32::from_rgb(0x1F, 0x1F, 0x1F); 16 const DARK_BG: Color32 = Color32::from_rgb(0x2C, 0x2C, 0x2C); 17 const DARK_ISH_BG: Color32 = Color32::from_rgb(0x25, 0x25, 0x25); 18 const SEMI_DARK_BG: Color32 = Color32::from_rgb(0x44, 0x44, 0x44); 19 20 const LIGHTER_GRAY: Color32 = Color32::from_rgb(0xf8, 0xf8, 0xf8); 21 const LIGHT_GRAY: Color32 = Color32::from_rgb(0xc8, 0xc8, 0xc8); // 78% 22 const DARKER_GRAY: Color32 = Color32::from_rgb(0xa5, 0xa5, 0xa5); // 65% 23 const EVEN_DARKER_GRAY: Color32 = Color32::from_rgb(0x89, 0x89, 0x89); // 54% 24 25 pub fn desktop_dark_color_theme() -> ColorTheme { 26 ColorTheme { 27 // VISUALS 28 panel_fill: DARKER_BG, 29 extreme_bg_color: DARK_ISH_BG, 30 text_color: Color32::WHITE, 31 err_fg_color: RED_700, 32 warn_fg_color: ORANGE_700, 33 hyperlink_color: PURPLE, 34 selection_color: PURPLE_ALT, 35 36 // WINDOW 37 window_fill: DARK_ISH_BG, 38 window_stroke_color: DARK_BG, 39 40 // NONINTERACTIVE WIDGET 41 noninteractive_bg_fill: DARK_ISH_BG, 42 noninteractive_weak_bg_fill: DARK_BG, 43 noninteractive_bg_stroke_color: SEMI_DARKER_BG, 44 noninteractive_fg_stroke_color: GRAY_SECONDARY, 45 46 // INACTIVE WIDGET 47 inactive_bg_stroke_color: SEMI_DARKER_BG, 48 inactive_bg_fill: Color32::from_rgb(0x25, 0x25, 0x25), 49 inactive_weak_bg_fill: SEMI_DARK_BG, 50 } 51 } 52 53 pub fn mobile_dark_color_theme() -> ColorTheme { 54 ColorTheme { 55 panel_fill: Color32::BLACK, 56 noninteractive_weak_bg_fill: Color32::from_rgb(0x1F, 0x1F, 0x1F), 57 ..desktop_dark_color_theme() 58 } 59 } 60 61 pub fn light_color_theme() -> ColorTheme { 62 ColorTheme { 63 // VISUALS 64 panel_fill: Color32::WHITE, 65 extreme_bg_color: LIGHTER_GRAY, 66 text_color: BLACK, 67 err_fg_color: RED_700, 68 warn_fg_color: ORANGE_700, 69 hyperlink_color: PURPLE, 70 selection_color: PURPLE_ALT, 71 72 // WINDOW 73 window_fill: Color32::WHITE, 74 window_stroke_color: DARKER_GRAY, 75 76 // NONINTERACTIVE WIDGET 77 noninteractive_bg_fill: Color32::WHITE, 78 noninteractive_weak_bg_fill: LIGHTER_GRAY, 79 noninteractive_bg_stroke_color: LIGHT_GRAY, 80 noninteractive_fg_stroke_color: GRAY_SECONDARY, 81 82 // INACTIVE WIDGET 83 inactive_bg_stroke_color: EVEN_DARKER_GRAY, 84 inactive_bg_fill: LIGHT_GRAY, 85 inactive_weak_bg_fill: EVEN_DARKER_GRAY, 86 } 87 } 88 89 pub fn light_mode() -> Visuals { 90 notedeck::theme::create_themed_visuals(light_color_theme(), Visuals::light()) 91 } 92 93 pub fn dark_mode(mobile: bool) -> Visuals { 94 notedeck::theme::create_themed_visuals( 95 if mobile { 96 mobile_dark_color_theme() 97 } else { 98 desktop_dark_color_theme() 99 }, 100 Visuals::dark(), 101 ) 102 } 103 104 /// Create custom text sizes for any FontSizes 105 pub fn add_custom_style(is_mobile: bool, style: &mut Style) { 106 let font_size = if is_mobile { 107 notedeck::fonts::mobile_font_size 108 } else { 109 notedeck::fonts::desktop_font_size 110 }; 111 112 style.text_styles = NotedeckTextStyle::iter() 113 .map(|text_style| { 114 ( 115 text_style.text_style(), 116 FontId::new(font_size(&text_style), text_style.font_family()), 117 ) 118 }) 119 .collect(); 120 121 style.interaction = Interaction { 122 tooltip_delay: 0.1, 123 show_tooltips_only_when_still: false, 124 ..Interaction::default() 125 }; 126 127 #[cfg(debug_assertions)] 128 { 129 style.debug.show_interactive_widgets = true; 130 style.debug.debug_on_hover_with_all_modifiers = true; 131 } 132 }