From 204b99b0bef85cac5d5147518c5062b594e588b5 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 27 Sep 2021 17:40:34 +0100 Subject: [PATCH] change to use new theme --- core/src/buffer.rs | 13 ++-- core/src/code_action.rs | 19 +++++- core/src/completion.rs | 44 ++++++++++---- core/src/config.rs | 85 +++++++++++++++++++------- core/src/data.rs | 6 +- core/src/editor.rs | 119 +++++++++++++++++++++++++++---------- core/src/palette.rs | 30 +++++++--- core/src/source_control.rs | 51 +++++++++++++--- core/src/status.rs | 26 ++++++-- core/src/theme.rs | 36 +++++------ core/src/window.rs | 25 +++++--- defaults/dark-theme.toml | 33 ++++++++++ defaults/light-theme.toml | 49 ++++++--------- defaults/settings.toml | 2 +- 14 files changed, 381 insertions(+), 157 deletions(-) create mode 100644 defaults/dark-theme.toml diff --git a/core/src/buffer.rs b/core/src/buffer.rs index ae0ccc98..df4dcb43 100644 --- a/core/src/buffer.rs +++ b/core/src/buffer.rs @@ -8,7 +8,7 @@ Color, Command, Data, EventCtx, ExtEventSink, Target, UpdateCtx, WidgetId, WindowId, }; -use druid::{Env, PaintCtx}; +use druid::{Env, FontFamily, PaintCtx}; use git2::Repository; use language::{new_highlight_config, new_parser, LapceLanguage}; use lsp_types::SemanticTokensServerCapabilities; @@ -50,6 +50,7 @@ Transformer, }; +use crate::config::{Config, LapceTheme}; use crate::data::EditorKind; use crate::editor::EditorLocationNew; use crate::theme::OldLapceTheme; @@ -488,15 +489,19 @@ pub fn new_text_layout( line_content: &str, bounds: [f64; 2], theme: &Arc>, - env: &Env, + config: &Config, ) -> PietTextLayout { let line_content = line_content.replace('\t', " "); let styles = self.get_line_styles(line); let mut layout_builder = ctx .text() .new_text_layout(line_content) - .font(env.get(OldLapceTheme::EDITOR_FONT).family, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)); + .font(config.editor.font_family(), config.editor.font_size as f64) + .text_color( + config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ); for (start, end, style) in styles.iter() { if let Some(fg_color) = style.fg_color.as_ref() { if let Some(fg_color) = theme.get(fg_color) { diff --git a/core/src/code_action.rs b/core/src/code_action.rs index ba4fa6bf..369a6a17 100644 --- a/core/src/code_action.rs +++ b/core/src/code_action.rs @@ -13,6 +13,7 @@ use crate::{ buffer::EditType, command::{LapceCommand, LapceUICommand, LAPCE_UI_COMMAND}, + config::LapceTheme, data::{LapceMainSplitData, LapceTabData}, keypress::{KeyPressData, KeyPressFocus}, movement::{Movement, Selection}, @@ -261,7 +262,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { let blur_color = Color::grey8(180); let shadow_width = 5.0; ctx.blurred_rect(rect, shadow_width, &blur_color); - ctx.fill(rect, &env.get(OldLapceTheme::EDITOR_SELECTION_COLOR)); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::EDITOR_SELECTION), + ); let editor = data.main_split.active_editor(); let buffer = data.main_split.open_files.get(&editor.buffer).unwrap(); @@ -284,7 +289,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { text_layout.set_font( FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(14.0), ); - text_layout.set_text_color(OldLapceTheme::EDITOR_FOREGROUND); + text_layout.set_text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ); text_layout.rebuild_if_needed(ctx.text(), env); text_layout }) @@ -298,7 +307,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { data.main_split.current_code_actions as f64 * line_height, )) .with_size(Size::new(ctx.size().width, line_height)); - ctx.fill(line_rect, &env.get(OldLapceTheme::EDITOR_BACKGROUND)); + ctx.fill( + line_rect, + data.config + .get_color_unchecked(LapceTheme::EDITOR_BACKGROUND), + ); for (i, text_layout) in action_text_layouts.iter().enumerate() { text_layout.draw(ctx, Point::new(5.0, i as f64 * line_height + 5.0)); diff --git a/core/src/completion.rs b/core/src/completion.rs index aa6e562b..58d194ba 100644 --- a/core/src/completion.rs +++ b/core/src/completion.rs @@ -8,9 +8,9 @@ theme, widget::SvgData, Affine, BoxConstraints, Color, Command, Data, Env, Event, EventCtx, - ExtEventSink, FontWeight, Insets, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx, - Point, Rect, RenderContext, Size, Target, TextLayout, UpdateCtx, Vec2, Widget, - WidgetExt, WidgetId, WidgetPod, WindowId, + ExtEventSink, FontFamily, FontWeight, Insets, LayoutCtx, LifeCycle, + LifeCycleCtx, PaintCtx, Point, Rect, RenderContext, Size, Target, TextLayout, + UpdateCtx, Vec2, Widget, WidgetExt, WidgetId, WidgetPod, WindowId, }; use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; use itertools::Itertools; @@ -21,6 +21,7 @@ use crate::{ buffer::BufferId, command::{LapceUICommand, LAPCE_UI_COMMAND}, + config::LapceTheme, data::LapceTabData, movement::Movement, proxy::LapceProxy, @@ -601,10 +602,14 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { if data.completion.status != CompletionStatus::Inactive && data.completion.len() > 0 { - let blur_color = Color::grey8(180); let shadow_width = 5.0; let rect = self.content_size.to_rect(); - ctx.blurred_rect(rect, shadow_width, &blur_color); + ctx.blurred_rect( + rect, + shadow_width, + data.config + .get_color_unchecked(LapceTheme::LAPCE_DROPDOWN_SHADOW), + ); self.completion.paint(ctx, data, env); } } @@ -667,7 +672,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { let input = &data.completion.input; let items: &Vec = data.completion.current_items(); - ctx.fill(rect, &env.get(OldLapceTheme::LIST_BACKGROUND)); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::COMPLETION_BACKGROUND), + ); let start_line = (rect.y0 / line_height).floor() as usize; let end_line = (rect.y1 / line_height).ceil() as usize; @@ -682,7 +691,8 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { Rect::ZERO .with_origin(Point::new(0.0, line as f64 * line_height)) .with_size(Size::new(size.width, line_height)), - &env.get(OldLapceTheme::LIST_CURRENT), + data.config + .get_color_unchecked(LapceTheme::COMPLETION_CURRENT), ); } @@ -693,8 +703,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { if let Some((svg, color)) = completion_svg(item.item.kind, data.theme.clone()) { - let color = - color.unwrap_or(env.get(OldLapceTheme::EDITOR_FOREGROUND)); + let color = color.unwrap_or( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ); let rect = Size::new(line_height, line_height) .to_rect() .with_origin(Point::new(0.0, line_height * line as f64)); @@ -717,8 +730,17 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { let mut text_layout = ctx .text() .new_text_layout(content.to_string()) - .font(env.get(OldLapceTheme::EDITOR_FONT).family, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)); + .font( + FontFamily::new_unchecked( + data.config.editor.font_family.clone(), + ), + data.config.editor.font_size as f64, + ) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ); for i in &item.indices { let i = *i; text_layout = text_layout.range_attribute( diff --git a/core/src/config.rs b/core/src/config.rs index 19044c97..4ffb338b 100644 --- a/core/src/config.rs +++ b/core/src/config.rs @@ -1,18 +1,43 @@ use std::collections::HashMap; +use anyhow::Result; use druid::{theme, Color, Env, FontDescriptor, FontFamily, Key}; use serde::{Deserialize, Deserializer, Serialize}; use crate::{data::hex_to_color, state::LapceWorkspace}; const default_settings: &'static str = include_str!("../../defaults/settings.toml"); -const default_theme: &'static str = include_str!("../../defaults/light-theme.toml"); +const default_light_theme: &'static str = + include_str!("../../defaults/light-theme.toml"); +const default_dark_theme: &'static str = + include_str!("../../defaults/dark-theme.toml"); pub struct LapceTheme {} impl LapceTheme { + pub const LAPCE_WARN: &'static str = "lapce.warn"; + pub const LAPCE_ERROR: &'static str = "lapce.error"; + pub const LAPCE_ACTIVE_TAB: &'static str = "lapce.active_tab"; + pub const LAPCE_INACTIVE_TAB: &'static str = "lapce.inactive_tab"; + pub const LAPCE_DROPDOWN_SHADOW: &'static str = "lapce.dropdown_shadow"; + pub const EDITOR_BACKGROUND: &'static str = "editor.background"; pub const EDITOR_FOREGROUND: &'static str = "editor.foreground"; + pub const EDITOR_DIM: &'static str = "editor.dim"; + pub const EDITOR_CARET: &'static str = "editor.caret"; + pub const EDITOR_SELECTION: &'static str = "editor.selection"; + pub const EDITOR_CURRENT_LINE: &'static str = "editor.current_line"; + + pub const PALETTE_BACKGROUND: &'static str = "palette.background"; + pub const PALETTE_CURRENT: &'static str = "palette.current"; + + pub const COMPLETION_BACKGROUND: &'static str = "completion.background"; + pub const COMPLETION_CURRENT: &'static str = "completion.current"; + + pub const PANEL_BACKGROUND: &'static str = "panel.background"; + pub const PANEL_CURRENT: &'static str = "panel.current"; + + pub const STATUS_BACKGROUND: &'static str = "status.background"; } #[derive(Debug, Clone, Deserialize)] @@ -30,6 +55,12 @@ pub struct EditorConfig { pub line_height: usize, } +impl EditorConfig { + pub fn font_family(&self) -> FontFamily { + FontFamily::new_unchecked(self.font_family.clone()) + } +} + #[derive(Debug, Clone, Deserialize)] pub struct Config { pub lapce: LapceConfig, @@ -43,7 +74,7 @@ pub struct Config { impl Config { pub fn load(workspace: Option) -> Self { let mut settings_string = default_settings.to_string(); - let mut files = vec!["/Users/Lulu/.lapce/settings.toml".to_string()]; + let mut files = vec![]; if let Some(workspace) = workspace { match workspace.kind { crate::state::LapceWorkspaceType::Local => { @@ -65,27 +96,17 @@ pub fn load(workspace: Option) -> Self { let config: toml::Value = toml::from_str(&settings_string).unwrap(); let mut config: Config = config.try_into().unwrap(); - let theme_colors: HashMap = - toml::from_str(&default_theme).unwrap(); - let mut theme = HashMap::new(); - for (k, v) in theme_colors.iter() { - if v.starts_with("$") { - let var_name = &v[1..]; - if let Some(hex) = theme_colors.get(var_name) { - if let Ok(color) = hex_to_color(hex) { - theme.insert(k.clone(), color); - } - } - } else { - if let Ok(color) = hex_to_color(v) { - theme.insert(k.clone(), color); - } - } - } + config.theme = get_theme(default_light_theme).unwrap(); - config.theme = theme; - - let themes = HashMap::new(); + let mut themes = HashMap::new(); + themes.insert( + "Lapce Light".to_string(), + get_theme(default_light_theme).unwrap(), + ); + themes.insert( + "Lapce Dark".to_string(), + get_theme(default_dark_theme).unwrap(), + ); config.themes = themes; println!("{:?}", config); @@ -161,3 +182,23 @@ pub fn reload_env(&self, env: &mut Env) { // env.set(LapceTheme::LIST_CURRENT, Color::rgb8(219, 219, 220)); } } + +fn get_theme(content: &str) -> Result> { + let theme_colors: HashMap = toml::from_str(content)?; + let mut theme = HashMap::new(); + for (k, v) in theme_colors.iter() { + if v.starts_with("$") { + let var_name = &v[1..]; + if let Some(hex) = theme_colors.get(var_name) { + if let Ok(color) = hex_to_color(hex) { + theme.insert(k.clone(), color); + } + } + } else { + if let Ok(color) = hex_to_color(v) { + theme.insert(k.clone(), color); + } + } + } + Ok(theme) +} diff --git a/core/src/data.rs b/core/src/data.rs index 629ba0bc..fe1406a7 100644 --- a/core/src/data.rs +++ b/core/src/data.rs @@ -52,7 +52,7 @@ EnsureVisiblePosition, LapceCommand, LapceUICommand, LAPCE_UI_COMMAND, }, completion::{CompletionData, CompletionStatus, Snippet}, - config::Config, + config::{Config, LapceTheme}, editor::EditorLocationNew, find::Find, keypress::{KeyPressData, KeyPressFocus}, @@ -114,6 +114,7 @@ pub struct LapceWindowData { pub active_id: WidgetId, pub keypress: Arc, pub theme: Arc>, + pub config: Arc, } impl Data for LapceWindowData { @@ -131,12 +132,14 @@ pub fn new( let tab_id = WidgetId::next(); let tab = LapceTabData::new(tab_id, keypress.clone(), theme.clone(), None); tabs.insert(tab_id, tab); + let config = Arc::new(Config::load(None)); Self { tabs, active: 0, active_id: tab_id, keypress, theme, + config, } } } @@ -324,7 +327,6 @@ pub fn code_action_size(&self, text: &mut PietText, env: &Env) -> Size { text_layout.set_font( FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(14.0), ); - text_layout.set_text_color(OldLapceTheme::EDITOR_FOREGROUND); text_layout.rebuild_if_needed(text, env); text_layout }) diff --git a/core/src/editor.rs b/core/src/editor.rs index ae175265..0dd1aef4 100644 --- a/core/src/editor.rs +++ b/core/src/editor.rs @@ -1,3 +1,4 @@ +use crate::config::LapceTheme; use crate::data::{EditorType, LapceEditorData, LapceEditorLens, LapceTabData}; use crate::find::Find; use crate::scroll::LapceIdentityWrapper; @@ -308,7 +309,11 @@ fn layout( fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { let rects = ctx.region().rects().to_vec(); for rect in &rects { - ctx.fill(rect, &env.get(OldLapceTheme::EDITOR_BACKGROUND)); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::EDITOR_BACKGROUND), + ); } let start = std::time::SystemTime::now(); self.editor.paint(ctx, data, env); @@ -677,7 +682,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { ctx.is_focused(); let rects = ctx.region().rects().to_vec(); for rect in &rects { - ctx.fill(rect, &env.get(OldLapceTheme::EDITOR_BACKGROUND)); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::EDITOR_BACKGROUND), + ); } self.editor.paint(ctx, data, env); if self.display_gutter { @@ -749,11 +758,19 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { if !self.display { return; } - let blur_color = Color::grey8(180); let shadow_width = 5.0; let rect = ctx.size().to_rect(); - ctx.blurred_rect(rect, shadow_width, &blur_color); - ctx.fill(rect, &env.get(OldLapceTheme::EDITOR_BACKGROUND)); + ctx.blurred_rect( + rect, + shadow_width, + data.config + .get_color_unchecked(LapceTheme::LAPCE_DROPDOWN_SHADOW), + ); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::EDITOR_BACKGROUND), + ); let mut path = data.editor.buffer.clone(); let svg = file_svg_new( @@ -787,7 +804,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { .text() .new_text_layout(file_name) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); ctx.draw_text(&text_layout, Point::new(30.0, 7.0)); @@ -810,7 +831,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { .text() .new_text_layout(folder) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_COMMENT)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_DIM) + .clone(), + ) .build() .unwrap(); ctx.draw_text(&text_layout, Point::new(30.0 + x + 5.0, 7.0)); @@ -853,8 +878,11 @@ fn paint_code_actions_hint( (line_height - height) / 2.0 + line_height * line as f64 - data.editor.scroll_offset.y, )); - let color = env.get(OldLapceTheme::EDITOR_WARN); - ctx.draw_svg(&svg, rect, Some(&color)); + ctx.draw_svg( + &svg, + rect, + Some(data.config.get_color_unchecked(LapceTheme::LAPCE_WARN)), + ); } } } @@ -930,7 +958,11 @@ fn layout( fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { let rect = ctx.size().to_rect(); - ctx.fill(rect, &env.get(OldLapceTheme::EDITOR_BACKGROUND)); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::EDITOR_BACKGROUND), + ); let line_height = data.config.editor.line_height as f64; let scroll_offset = data.editor.scroll_offset; let start_line = (scroll_offset.y / line_height).floor() as usize; @@ -963,8 +995,15 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { let text_layout = ctx .text() .new_text_layout(content) - .font(env.get(OldLapceTheme::EDITOR_FONT).family, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .font( + data.config.editor.font_family(), + data.config.editor.font_size as f64, + ) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); ctx.draw_text(&text_layout, pos); @@ -1043,7 +1082,8 @@ fn paint_cursor_line( Rect::ZERO .with_origin(Point::new(0.0, line as f64 * line_height)) .with_size(Size::new(size.width, line_height)), - &env.get(OldLapceTheme::EDITOR_CURRENT_LINE_BACKGROUND), + data.config + .get_color_unchecked(LapceTheme::EDITOR_CURRENT_LINE), ); } @@ -1107,14 +1147,14 @@ fn paint_diagnostics( .unwrap_or(&DiagnosticSeverity::Information); let color = match severity { DiagnosticSeverity::Error => { - env.get(OldLapceTheme::EDITOR_ERROR) + data.config.get_color_unchecked(LapceTheme::LAPCE_ERROR) } DiagnosticSeverity::Warning => { - env.get(OldLapceTheme::EDITOR_WARN) + data.config.get_color_unchecked(LapceTheme::LAPCE_WARN) } - _ => env.get(OldLapceTheme::EDITOR_WARN), + _ => data.config.get_color_unchecked(LapceTheme::LAPCE_WARN), }; - ctx.fill(Rect::new(x0, y0, x1, y1), &color); + ctx.fill(Rect::new(x0, y0, x1, y1), color); } } } @@ -1125,7 +1165,11 @@ fn paint_diagnostics( .text() .new_text_layout(diagnostic.diagnositc.message.clone()) .font(FontFamily::SYSTEM_UI, 14.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); let text_size = text_layout.size(); @@ -1137,7 +1181,11 @@ fn paint_diagnostics( (start.line + 1) as f64 * line_height, )) .with_size(Size::new(size.width, text_size.height + 20.0)); - ctx.fill(rect, &env.get(OldLapceTheme::EDITOR_SELECTION_COLOR)); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::EDITOR_SELECTION), + ); let severity = diagnostic .diagnositc @@ -1146,14 +1194,14 @@ fn paint_diagnostics( .unwrap_or(&DiagnosticSeverity::Information); let color = match severity { DiagnosticSeverity::Error => { - env.get(OldLapceTheme::EDITOR_ERROR) + data.config.get_color_unchecked(LapceTheme::LAPCE_ERROR) } DiagnosticSeverity::Warning => { - env.get(OldLapceTheme::EDITOR_WARN) + data.config.get_color_unchecked(LapceTheme::LAPCE_WARN) } - _ => env.get(OldLapceTheme::EDITOR_WARN), + _ => data.config.get_color_unchecked(LapceTheme::LAPCE_WARN), }; - ctx.stroke(rect, &color, 1.0); + ctx.stroke(rect, color, 1.0); ctx.draw_text( &text_layout, Point::new(10.0, (start.line + 1) as f64 * line_height + 10.0), @@ -1207,7 +1255,8 @@ fn paint_snippet( let y1 = y0 + line_height; ctx.stroke( Rect::new(x0, y0, x1, y1).inflate(1.0, -0.5), - &env.get(OldLapceTheme::EDITOR_FOREGROUND), + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND), 1.0, ); } @@ -1254,7 +1303,7 @@ fn paint_cursor( width * char_width as f64, line_height, )), - &env.get(OldLapceTheme::EDITOR_CURSOR_COLOR), + data.config.get_color_unchecked(LapceTheme::EDITOR_CARET), ); } } @@ -1320,7 +1369,8 @@ fn paint_cursor( let y1 = y0 + line_height; ctx.fill( Rect::new(x0, y0, x1, y1), - &env.get(OldLapceTheme::EDITOR_SELECTION_COLOR), + data.config + .get_color_unchecked(LapceTheme::EDITOR_SELECTION), ); } @@ -1340,7 +1390,7 @@ fn paint_cursor( width * char_width as f64, line_height, )), - &env.get(OldLapceTheme::EDITOR_CURSOR_COLOR), + data.config.get_color_unchecked(LapceTheme::EDITOR_CARET), ); } } @@ -1397,8 +1447,8 @@ fn paint_cursor( let y1 = y0 + line_height; ctx.fill( Rect::new(x0, y0, x1, y1), - &env.get( - OldLapceTheme::EDITOR_SELECTION_COLOR, + data.config.get_color_unchecked( + LapceTheme::EDITOR_SELECTION, ), ); } @@ -1414,7 +1464,8 @@ fn paint_cursor( Point::new(x, y), Point::new(x, y + line_height), ), - &env.get(OldLapceTheme::EDITOR_CURSOR_COLOR), + data.config + .get_color_unchecked(LapceTheme::EDITOR_CARET), 2.0, ) } @@ -1713,7 +1764,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { line_content, [rect.x0, rect.x1], &data.theme, - env, + &data.config, ); ctx.draw_text( &text_layout, @@ -1729,7 +1780,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { .text() .new_text_layout(placeholder.to_string()) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_COMMENT)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_DIM) + .clone(), + ) .build() .unwrap(); ctx.draw_text(&text_layout, Point::new(0.0, 5.0)); diff --git a/core/src/palette.rs b/core/src/palette.rs index 92af42e2..6e2286e6 100644 --- a/core/src/palette.rs +++ b/core/src/palette.rs @@ -1138,7 +1138,6 @@ pub fn new(data: &PaletteData, preview_editor: &LapceEditorData) -> Self { let padding = 6.0; let input = NewPaletteInput::new() .padding((padding, padding, padding, padding * 2.0)) - .background(OldLapceTheme::EDITOR_BACKGROUND) .padding((padding, padding, padding, padding)) .lens(PaletteViewLens); let content = LapceIdentityWrapper::wrap( @@ -1280,11 +1279,19 @@ fn layout( } fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { - let blur_color = Color::grey8(180); let shadow_width = 5.0; let rect = self.content_size.to_rect(); - ctx.blurred_rect(rect, shadow_width, &blur_color); - ctx.fill(rect, &env.get(OldLapceTheme::LIST_BACKGROUND)); + ctx.blurred_rect( + rect, + shadow_width, + data.config + .get_color_unchecked(LapceTheme::LAPCE_DROPDOWN_SHADOW), + ); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::PALETTE_BACKGROUND), + ); self.input.paint(ctx, data, env); self.content.paint(ctx, data, env); @@ -1362,11 +1369,20 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &PaletteViewData, env: &Env) { .text() .new_text_layout(text) .font(FontFamily::SYSTEM_UI, 14.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); let line = text_layout.cursor_line_for_text_position(cursor); - ctx.stroke(line, &env.get(OldLapceTheme::EDITOR_FOREGROUND), 1.0); + ctx.stroke( + line, + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND), + 1.0, + ); ctx.draw_text(&text_layout, Point::new(0.0, 0.0)); } } @@ -1463,7 +1479,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &PaletteViewData, env: &Env) { Rect::ZERO .with_origin(Point::new(0.0, line as f64 * line_height)) .with_size(Size::new(size.width, line_height)), - &env.get(OldLapceTheme::LIST_CURRENT), + data.config.get_color_unchecked(LapceTheme::PALETTE_CURRENT), ); } diff --git a/core/src/source_control.rs b/core/src/source_control.rs index 8ac97d7a..b6c13d9f 100644 --- a/core/src/source_control.rs +++ b/core/src/source_control.rs @@ -16,6 +16,7 @@ use crate::{ command::{LapceCommand, LapceUICommand, LAPCE_UI_COMMAND}, + config::LapceTheme, data::{LapceEditorLens, LapceTabData}, editor::{LapceEditorContainer, LapceEditorView}, keypress::KeyPressFocus, @@ -260,8 +261,17 @@ fn layout( fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { let rect = ctx.size().to_rect(); - ctx.blurred_rect(rect, 5.0, &Color::grey8(180)); - ctx.fill(rect, &env.get(OldLapceTheme::LIST_BACKGROUND)); + ctx.blurred_rect( + rect, + 5.0, + data.config + .get_color_unchecked(LapceTheme::LAPCE_DROPDOWN_SHADOW), + ); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::PANEL_BACKGROUND), + ); self.split.paint(ctx, data, env); } } @@ -409,19 +419,31 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { let line_height = data.config.editor.line_height as f64; { - let blur_color = Color::grey8(180); let shadow_width = 5.0; let rect = Size::new(ctx.size().width, line_height) .to_rect() .with_origin(Point::new(0.0, 5.0)); - ctx.blurred_rect(rect, shadow_width, &blur_color); - ctx.fill(rect, &env.get(OldLapceTheme::LIST_BACKGROUND)); + ctx.blurred_rect( + rect, + shadow_width, + data.config + .get_color_unchecked(LapceTheme::LAPCE_DROPDOWN_SHADOW), + ); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::PANEL_BACKGROUND), + ); let text_layout = ctx .text() .new_text_layout("Changes") .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); ctx.draw_text(&text_layout, Point::new(5.0, 5.0 + 4.0)); @@ -437,7 +459,10 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { (data.source_control.file_list_index + 1) as f64 * line_height + 10.0, )); - ctx.fill(rect, &env.get(OldLapceTheme::LIST_CURRENT)); + ctx.fill( + rect, + data.config.get_color_unchecked(LapceTheme::PANEL_CURRENT), + ); } let rect = ctx.region().bounding_box(); @@ -500,7 +525,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { .text() .new_text_layout(file_name) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); ctx.draw_text(&text_layout, Point::new(line_height * 2.0, y + 4.0)); @@ -516,7 +545,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { .text() .new_text_layout(folder) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_COMMENT)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_DIM) + .clone(), + ) .build() .unwrap(); ctx.draw_text( diff --git a/core/src/status.rs b/core/src/status.rs index 23795582..0b56765e 100644 --- a/core/src/status.rs +++ b/core/src/status.rs @@ -11,6 +11,7 @@ use lsp_types::DiagnosticSeverity; use crate::command::{LapceUICommand, LAPCE_UI_COMMAND}; +use crate::config::LapceTheme; use crate::data::LapceTabData; use crate::state::Mode; use crate::theme::OldLapceTheme; @@ -83,8 +84,17 @@ fn paint( ) { let size = ctx.size(); let rect = size.to_rect(); - ctx.blurred_rect(rect, 5.0, &Color::grey8(180)); - ctx.fill(rect, &env.get(OldLapceTheme::LIST_BACKGROUND)); + ctx.blurred_rect( + rect, + 5.0, + data.config + .get_color_unchecked(LapceTheme::LAPCE_DROPDOWN_SHADOW), + ); + ctx.fill( + rect, + data.config + .get_color_unchecked(LapceTheme::STATUS_BACKGROUND), + ); let mut left = 0.0; let (mode, color) = match data.main_split.active_editor().cursor.get_mode() { @@ -97,7 +107,11 @@ fn paint( .text() .new_text_layout(mode) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_BACKGROUND)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_BACKGROUND) + .clone(), + ) .build() .unwrap(); let text_size = text_layout.size(); @@ -113,7 +127,11 @@ fn paint( data.main_split.error_count, data.main_split.warning_count )) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .text_color( + data.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); ctx.draw_text(&text_layout, Point::new(left + 10.0, 4.0)); diff --git a/core/src/theme.rs b/core/src/theme.rs index e3af187d..363efcbf 100644 --- a/core/src/theme.rs +++ b/core/src/theme.rs @@ -3,26 +3,18 @@ pub struct OldLapceTheme {} impl OldLapceTheme { - // pub const EDITOR_LINE_HEIGHT: Key = Key::new("lapce.editor_line_height"); - pub const PALETTE_BACKGROUND: Key = Key::new("lapce.palette_background"); - pub const PALETTE_INPUT_BACKGROUND: Key = - Key::new("lapce.palette_input_background"); - pub const PALETTE_INPUT_FOREROUND: Key = - Key::new("lapce.palette_input_foreground"); - pub const PALETTE_INPUT_BORDER: Key = - Key::new("lapce.palette_input_border"); - pub const EDITOR_FONT: Key = Key::new("lapce.eidtor_font"); - pub const EDITOR_COMMENT: Key = Key::new("lapce.eidtor_comment"); - pub const EDITOR_FOREGROUND: Key = Key::new("lapce.eidtor_foreground"); - pub const EDITOR_BACKGROUND: Key = Key::new("lapce.eidtor_background"); - pub const EDITOR_ERROR: Key = Key::new("lapce.eidtor_error"); - pub const EDITOR_WARN: Key = Key::new("lapce.eidtor_warn"); - pub const EDITOR_CURSOR_COLOR: Key = - Key::new("lapce.eidtor_cursor_color"); - pub const EDITOR_CURRENT_LINE_BACKGROUND: Key = - Key::new("lapce.eidtor_current_line_background"); - pub const EDITOR_SELECTION_COLOR: Key = - Key::new("lapce.editor_selection_color"); - pub const LIST_BACKGROUND: Key = Key::new("lapce.list_background"); - pub const LIST_CURRENT: Key = Key::new("lapce.list_current"); + // pub const EDITOR_FONT: Key = Key::new("lapce.eidtor_font"); + // pub const EDITOR_COMMENT: Key = Key::new("lapce.eidtor_comment"); + // pub const EDITOR_FOREGROUND: Key = Key::new("lapce.eidtor_foreground"); + // pub const EDITOR_BACKGROUND: Key = Key::new("lapce.eidtor_background"); + // pub const EDITOR_ERROR: Key = Key::new("lapce.eidtor_error"); + // pub const EDITOR_WARN: Key = Key::new("lapce.eidtor_warn"); + // pub const EDITOR_CURSOR_COLOR: Key = + // Key::new("lapce.eidtor_cursor_color"); + // pub const EDITOR_CURRENT_LINE_BACKGROUND: Key = + // Key::new("lapce.eidtor_current_line_background"); + // pub const EDITOR_SELECTION_COLOR: Key = + // Key::new("lapce.editor_selection_color"); + // pub const LIST_BACKGROUND: Key = Key::new("lapce.list_background"); + // pub const LIST_CURRENT: Key = Key::new("lapce.list_current"); } diff --git a/core/src/window.rs b/core/src/window.rs index ca3102a7..cfdeb613 100644 --- a/core/src/window.rs +++ b/core/src/window.rs @@ -1,6 +1,7 @@ use crate::{ command::LapceUICommand, command::LAPCE_UI_COMMAND, + config::LapceTheme, data::{LapceTabData, LapceTabLens, LapceWindowData}, editor::EditorUIState, explorer::{FileExplorer, FileExplorerState}, @@ -242,15 +243,13 @@ fn layout( } fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceWindowData, env: &Env) { - let rect = ctx.size().to_rect(); - ctx.fill(rect, &env.get(OldLapceTheme::EDITOR_BACKGROUND)); - let tab_height = 25.0; let size = ctx.size(); if self.tabs.len() > 1 { ctx.fill( Size::new(size.width, tab_height).to_rect(), - &env.get(OldLapceTheme::EDITOR_SELECTION_COLOR), + data.config + .get_color_unchecked(LapceTheme::LAPCE_INACTIVE_TAB), ); let color = env.get(theme::BORDER_LIGHT); let num = self.tabs.len(); @@ -262,7 +261,8 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceWindowData, env: &Env) { Rect::ZERO .with_origin(Point::new(section * i as f64, 0.0)) .with_size(Size::new(section, tab_height)), - &env.get(OldLapceTheme::EDITOR_BACKGROUND), + data.config + .get_color_unchecked(LapceTheme::LAPCE_ACTIVE_TAB), ); } let tab = data.tabs.get(&tab_id).unwrap(); @@ -284,7 +284,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceWindowData, env: &Env) { .text() .new_text_layout(dir) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .text_color( + tab.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); @@ -309,7 +313,8 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceWindowData, env: &Env) { Rect::ZERO .with_origin(Point::new(section * data.active as f64, 0.0)) .with_size(Size::new(section, tab_height)), - &env.get(OldLapceTheme::EDITOR_BACKGROUND), + data.config + .get_color_unchecked(LapceTheme::LAPCE_ACTIVE_TAB), ); let tab = data.tabs.get(&self.tabs[data.active].id()).unwrap(); @@ -331,7 +336,11 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceWindowData, env: &Env) { .text() .new_text_layout(dir) .font(FontFamily::SYSTEM_UI, 13.0) - .text_color(env.get(OldLapceTheme::EDITOR_FOREGROUND)) + .text_color( + tab.config + .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) + .clone(), + ) .build() .unwrap(); let text_width = text_layout.size().width; diff --git a/defaults/dark-theme.toml b/defaults/dark-theme.toml new file mode 100644 index 00000000..e931ba86 --- /dev/null +++ b/defaults/dark-theme.toml @@ -0,0 +1,33 @@ +white = "#ABB2BF" +black = "#282C34" +grey = "#3E4451" +light_grey = "#f2f2f2" +blue = "#61AFEF" +red = "#E06C75" +yellow = "#D19A66" +green = "#98C379" +purple = "#C678DD" + +"lapce.active_tab" = "$white" +"lapce.inactive_tab" = "$grey" +"lapce.error" = "$red" +"lapce.warn" = "$yellow" +"lapce.dropdown_shadow" = "#000000" + +"editor.background" = "$black" +"editor.foreground" = "$white" +"editor.dim" = "#A0A1A7" +"editor.caret" = "$blue" +"editor.selection" = "$grey" +"editor.current_line" = "$light_grey" + +"palette.background" = "#21252B" +"palette.current" = "#2C313A" + +"completion.background" = "#21252B" +"completion.current" = "#2C313A" + +"panel.background" = "#21252B" +"panel.current" = "#dbdbdc" + +"status.background" = "#21252B" diff --git a/defaults/light-theme.toml b/defaults/light-theme.toml index 13a77a67..b606e6fe 100644 --- a/defaults/light-theme.toml +++ b/defaults/light-theme.toml @@ -1,5 +1,6 @@ white = "#fafafa" black = "#383a42" +grey = "#E5E5E6" light_grey = "#f2f2f2" blue = "#526FFF" red = "#e51400" @@ -7,42 +8,26 @@ yellow = "#e9a700" green = "#50A14F" purple = "#A626A4" +"lapce.active_tab" = "$white" +"lapce.inactive_tab" = "$grey" +"lapce.error" = "$red" +"lapce.warn" = "$yellow" +"lapce.dropdown_shadow" = "#b4b4b4" + "editor.background" = "$white" "editor.foreground" = "$black" -"editor.line_highlight" = "#f2f2f2" +"editor.dim" = "#A0A1A7" "editor.caret" = "$blue" -"editor.selection" = "#E5E5E6" +"editor.selection" = "$grey" +"editor.current_line" = "$light_grey" -caret = "#526FFF" -comment = "#A0A1A7" -selection = "#E5E5E6" -error = "#e51400" -warn = "#e9a700" +"palette.background" = "#eaeaeb" +"palette.current" = "#dbdbdc" -"type.builtin" = "#0184bc" -builtinType = "#0184bc" +"completion.background" = "#eaeaeb" +"completion.current" = "#dbdbdc" -function = "#4078f2" -method = "#4078f2" -"function.method" = "#4078f2" +"panel.background" = "#eaeaeb" +"panel.current" = "#dbdbdc" -string = "#50A14F" - -constant = "#986801" - -selfKeyword = "#A626A4" -keyword = "#A626A4" - -number = "#c18401" -type = "#c18401" -typeAlias = "#c18401" -interface = "#c18401" -struct = "#c18401" -structure = "#c18401" -enum = "#c18401" -attribute = "#c18401" - -property = "#e45649" -enumMember = "#e45649" -"enum-member" = "#e45649" -field = "#e45649" +"status.background" = "#eaeaeb" diff --git a/defaults/settings.toml b/defaults/settings.toml index d367ea06..cc971fad 100644 --- a/defaults/settings.toml +++ b/defaults/settings.toml @@ -1,5 +1,5 @@ [lapce] -color-theme = "" +color-theme = "Lapce Dark" icon-theme = "" [editor]