mirror of https://github.com/lapce/lapce.git
decide color theme is light or dark
This commit is contained in:
parent
497e9505be
commit
e416688729
|
@ -1,6 +1,5 @@
|
|||
[color-theme]
|
||||
name = "Lapce Dark"
|
||||
color-preference = "dark"
|
||||
|
||||
[ui]
|
||||
font-family = ""
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[color-theme]
|
||||
name = "Lapce Light"
|
||||
color-preference = "light"
|
||||
|
||||
[ui]
|
||||
font-family = ""
|
||||
|
|
|
@ -56,7 +56,6 @@ trim-search-results-whitespace = true
|
|||
|
||||
[color-theme]
|
||||
name = ""
|
||||
color-preference = ""
|
||||
|
||||
[color-theme.base]
|
||||
white = "#ABB2BF"
|
||||
|
|
|
@ -565,7 +565,7 @@ pub struct ColorThemeConfig {
|
|||
#[serde(skip)]
|
||||
pub path: PathBuf,
|
||||
pub name: String,
|
||||
pub color_preference: String,
|
||||
pub high_contrast: Option<bool>,
|
||||
pub base: ThemeBaseConfig,
|
||||
pub syntax: IndexMap<String, String>,
|
||||
pub ui: IndexMap<String, String>,
|
||||
|
@ -998,16 +998,20 @@ fn resolve_colors(&mut self, default_config: Option<&LapceConfig>) {
|
|||
default_config.map(|c| &c.color.syntax),
|
||||
);
|
||||
|
||||
#[allow(clippy::wildcard_in_or_patterns)]
|
||||
{
|
||||
self.color.color_preference =
|
||||
match self.color_theme.color_preference.to_lowercase().as_str() {
|
||||
"highcontrastdark" => ThemeColorPreference::HighContrastDark,
|
||||
"highcontrastlight" => ThemeColorPreference::HighContrastLight,
|
||||
"light" => ThemeColorPreference::Light,
|
||||
"dark" | _ => ThemeColorPreference::Dark,
|
||||
};
|
||||
}
|
||||
let fg = self
|
||||
.get_color_unchecked(LapceTheme::EDITOR_FOREGROUND)
|
||||
.as_rgba();
|
||||
let bg = self
|
||||
.get_color_unchecked(LapceTheme::EDITOR_FOREGROUND)
|
||||
.as_rgba();
|
||||
let is_light = fg.0 + fg.1 + fg.2 > bg.0 + bg.1 + bg.2;
|
||||
let high_contrast = self.color_theme.high_contrast.unwrap_or(false);
|
||||
self.color.color_preference = match (is_light, high_contrast) {
|
||||
(true, true) => ThemeColorPreference::HighContrastLight,
|
||||
(false, true) => ThemeColorPreference::HighContrastDark,
|
||||
(true, false) => ThemeColorPreference::Light,
|
||||
(false, false) => ThemeColorPreference::Dark,
|
||||
};
|
||||
}
|
||||
|
||||
fn load_color_themes(
|
||||
|
|
|
@ -15,6 +15,7 @@ pub struct TitleData {
|
|||
pub widget_id: WidgetId,
|
||||
pub branches: BranchListData,
|
||||
}
|
||||
|
||||
impl TitleData {
|
||||
pub fn new(config: Arc<LapceConfig>) -> TitleData {
|
||||
let widget_id = WidgetId::next();
|
||||
|
@ -43,6 +44,7 @@ fn new(config: Arc<LapceConfig>, parent: WidgetId) -> Self {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyPressFocus for BranchListData {
|
||||
fn get_mode(&self) -> Mode {
|
||||
Mode::Insert
|
||||
|
|
|
@ -304,7 +304,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, _env: &Env) {
|
|||
|
||||
let title_layout = ctx
|
||||
.text()
|
||||
.new_text_layout(format!("Lapce {}", *meta::RELEASE,))
|
||||
.new_text_layout("Lapce")
|
||||
.font(
|
||||
data.config.ui.font_family(),
|
||||
data.config.ui.font_size() as f64,
|
||||
|
|
|
@ -184,7 +184,7 @@ fn update_remote(
|
|||
Size::new(size.height, size.height)
|
||||
.to_rect()
|
||||
.with_origin(Point::new(x + 5.0, 0.0))
|
||||
.inflate(-3.0, -3.0),
|
||||
.inflate(-5.0, -5.0),
|
||||
Some(
|
||||
data.config
|
||||
.get_color_unchecked(LapceTheme::EDITOR_BACKGROUND)
|
||||
|
@ -266,7 +266,7 @@ fn update_source_control(
|
|||
.with_origin(Point::new(x, 0.0));
|
||||
self.svgs.push((
|
||||
folder_svg,
|
||||
folder_rect.inflate(-8.5, -8.5),
|
||||
folder_rect.inflate(-10.5, -10.5),
|
||||
Some(
|
||||
data.config
|
||||
.get_color_unchecked(LapceTheme::LAPCE_ICON_ACTIVE)
|
||||
|
|
Loading…
Reference in New Issue