Checkpoint
This commit is contained in:
parent
09866ec3e9
commit
4740d6ed61
4 changed files with 43 additions and 52 deletions
|
@ -765,7 +765,7 @@ impl LanguageRegistry {
|
||||||
let mut state = self.state.write();
|
let mut state = self.state.write();
|
||||||
state.theme = Some(theme.clone());
|
state.theme = Some(theme.clone());
|
||||||
for language in &state.languages {
|
for language in &state.languages {
|
||||||
language.set_theme(&theme.editor.syntax);
|
language.set_theme(&theme.syntax);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1066,7 +1066,7 @@ impl LanguageRegistryState {
|
||||||
|
|
||||||
fn add(&mut self, language: Arc<Language>) {
|
fn add(&mut self, language: Arc<Language>) {
|
||||||
if let Some(theme) = self.theme.as_ref() {
|
if let Some(theme) = self.theme.as_ref() {
|
||||||
language.set_theme(&theme.editor.syntax);
|
language.set_theme(&theme.syntax);
|
||||||
}
|
}
|
||||||
self.languages.push(language);
|
self.languages.push(language);
|
||||||
self.version += 1;
|
self.version += 1;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{Theme, ThemeRegistry};
|
use crate::{Theme, ThemeRegistry};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui2::{FontFeatures, SharedString, Font, AppContext, Pixels, px, FontWeight, FontStyle};
|
use gpui2::{px, AppContext, Font, FontFeatures, FontStyle, FontWeight, Pixels};
|
||||||
use schemars::{
|
use schemars::{
|
||||||
gen::SchemaGenerator,
|
gen::SchemaGenerator,
|
||||||
schema::{InstanceType, Schema, SchemaObject},
|
schema::{InstanceType, Schema, SchemaObject},
|
||||||
|
@ -15,21 +15,21 @@ use util::ResultExt as _;
|
||||||
const MIN_FONT_SIZE: Pixels = px(6.0);
|
const MIN_FONT_SIZE: Pixels = px(6.0);
|
||||||
const MIN_LINE_HEIGHT: f32 = 1.0;
|
const MIN_LINE_HEIGHT: f32 = 1.0;
|
||||||
|
|
||||||
#[derive(Clone, JsonSchema)]
|
#[derive(Clone)]
|
||||||
pub struct ThemeSettings {
|
pub struct ThemeSettings {
|
||||||
pub buffer_font: Font,
|
pub buffer_font: Font,
|
||||||
pub buffer_font_size: Pixels,
|
pub buffer_font_size: Pixels,
|
||||||
pub buffer_line_height: BufferLineHeight,
|
pub buffer_line_height: BufferLineHeight,
|
||||||
#[serde(skip)]
|
|
||||||
pub theme: Arc<Theme>,
|
pub theme: Arc<Theme>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AdjustedBufferFontSize(pub f32);
|
#[derive(Default)]
|
||||||
|
pub struct AdjustedBufferFontSize(Option<Pixels>);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct ThemeSettingsContent {
|
pub struct ThemeSettingsContent {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub buffer_font_family: Option<SharedString>,
|
pub buffer_font_family: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub buffer_font_size: Option<f32>,
|
pub buffer_font_size: Option<f32>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
@ -37,7 +37,7 @@ pub struct ThemeSettingsContent {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub buffer_font_features: Option<FontFeatures>,
|
pub buffer_font_features: Option<FontFeatures>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub theme: Option<SharedString>,
|
pub theme: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
|
||||||
|
@ -60,13 +60,12 @@ impl BufferLineHeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThemeSettings {
|
impl ThemeSettings {
|
||||||
pub fn buffer_font_size(&self, cx: &AppContext) -> f32 {
|
pub fn buffer_font_size(&self, cx: &mut AppContext) -> Pixels {
|
||||||
if cx.has_global::<AdjustedBufferFontSize>() {
|
let font_size = *cx
|
||||||
cx.global::<AdjustedBufferFontSize>().0
|
.default_global_mut::<AdjustedBufferFontSize>()
|
||||||
} else {
|
.0
|
||||||
self.buffer_font_size
|
.get_or_insert(self.buffer_font_size.into());
|
||||||
}
|
font_size.max(MIN_FONT_SIZE)
|
||||||
.max(MIN_FONT_SIZE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn line_height(&self) -> f32 {
|
pub fn line_height(&self) -> f32 {
|
||||||
|
@ -74,33 +73,32 @@ impl ThemeSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn adjusted_font_size(size: f32, cx: &AppContext) -> f32 {
|
pub fn adjusted_font_size(size: Pixels, cx: &mut AppContext) -> Pixels {
|
||||||
if let Some(adjusted_size) = cx.try_global::<AdjustedBufferFontSize>() {
|
if let Some(adjusted_size) = cx.default_global_mut::<AdjustedBufferFontSize>().0 {
|
||||||
let buffer_font_size = settings2::get::<ThemeSettings>(cx).buffer_font_size;
|
let buffer_font_size = settings2::get::<ThemeSettings>(cx).buffer_font_size;
|
||||||
let delta = adjusted_size - buffer_font_size;
|
let delta = adjusted_size - buffer_font_size;
|
||||||
size + delta
|
size + delta
|
||||||
} else {
|
} else {
|
||||||
size
|
size
|
||||||
}.max(MIN_FONT_SIZE)
|
}
|
||||||
|
.max(MIN_FONT_SIZE)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn adjust_font_size(cx: &mut AppContext, f: fn(&mut Pixels)) {
|
pub fn adjust_font_size(cx: &mut AppContext, f: fn(&mut Pixels)) {
|
||||||
if !cx.has_global::<AdjustedBufferFontSize>() {
|
let buffer_font_size = settings2::get::<ThemeSettings>(cx).buffer_font_size;
|
||||||
let buffer_font_size = settings2::get::<ThemeSettings>(cx).buffer_font_size;
|
let adjusted_size = cx
|
||||||
cx.set_global(AdjustedBufferFontSize(buffer_font_size));
|
.default_global_mut::<AdjustedBufferFontSize>()
|
||||||
}
|
|
||||||
let mut delta = cx.global_mut::<AdjustedBufferFontSize>();
|
|
||||||
f(&mut delta.0);
|
|
||||||
delta.0 = delta
|
|
||||||
.0
|
.0
|
||||||
.max(MIN_FONT_SIZE - settings2::get::<ThemeSettings>(cx).buffer_font_size);
|
.get_or_insert(buffer_font_size);
|
||||||
cx.refresh_windows();
|
f(adjusted_size);
|
||||||
|
*adjusted_size = (*adjusted_size).max(MIN_FONT_SIZE - buffer_font_size);
|
||||||
|
cx.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset_font_size(cx: &mut AppContext) {
|
pub fn reset_font_size(cx: &mut AppContext) {
|
||||||
if cx.has_global::<AdjustedBufferFontSize>() {
|
if cx.has_global::<AdjustedBufferFontSize>() {
|
||||||
cx.remove_global::<AdjustedBufferFontSize>();
|
cx.global_mut::<AdjustedBufferFontSize>().0 = None;
|
||||||
cx.refresh_windows();
|
cx.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,43 +116,31 @@ impl settings2::Setting for ThemeSettings {
|
||||||
|
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
buffer_font: Font {
|
buffer_font: Font {
|
||||||
family: defaults.buffer_font_family.clone().unwrap(),
|
family: defaults.buffer_font_family.clone().unwrap().into(),
|
||||||
features: defaults.buffer_font_features.clone().unwrap(),
|
features: defaults.buffer_font_features.clone().unwrap(),
|
||||||
weight: FontWeight::default(),
|
weight: FontWeight::default(),
|
||||||
style: FontStyle::default(),
|
style: FontStyle::default(),
|
||||||
},
|
},
|
||||||
buffer_font_size: defaults.buffer_font_size.unwrap(),
|
buffer_font_size: defaults.buffer_font_size.unwrap().into(),
|
||||||
buffer_line_height: defaults.buffer_line_height.unwrap(),
|
buffer_line_height: defaults.buffer_line_height.unwrap(),
|
||||||
theme: themes.get(defaults.theme.as_ref().unwrap()).unwrap(),
|
theme: themes.get(defaults.theme.as_ref().unwrap().clone()).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for value in user_values.into_iter().copied().cloned() {
|
for value in user_values.into_iter().copied().cloned() {
|
||||||
let font_cache = cx.font_cache();
|
|
||||||
let mut family_changed = false;
|
|
||||||
if let Some(value) = value.buffer_font_family {
|
if let Some(value) = value.buffer_font_family {
|
||||||
this.buffer_font_family_name = value;
|
this.buffer_font.family = value.into();
|
||||||
family_changed = true;
|
|
||||||
}
|
}
|
||||||
if let Some(value) = value.buffer_font_features {
|
if let Some(value) = value.buffer_font_features {
|
||||||
this.buffer_font_features = value;
|
this.buffer_font.features = value;
|
||||||
family_changed = true;
|
|
||||||
}
|
|
||||||
if family_changed {
|
|
||||||
if let Some(id) = font_cache
|
|
||||||
.load_family(&[&this.buffer_font_family_name], &this.buffer_font_features)
|
|
||||||
.log_err()
|
|
||||||
{
|
|
||||||
this.buffer_font_family = id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(value) = &value.theme {
|
if let Some(value) = &value.theme {
|
||||||
if let Some(theme) = themes.get(value).log_err() {
|
if let Some(theme) = themes.get(value.clone()).log_err() {
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
merge(&mut this.buffer_font_size, value.buffer_font_size);
|
merge(&mut this.buffer_font_size, value.buffer_font_size.map(Into::into));
|
||||||
merge(&mut this.buffer_line_height, value.buffer_line_height);
|
merge(&mut this.buffer_line_height, value.buffer_line_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ mod themes;
|
||||||
pub use registry::*;
|
pub use registry::*;
|
||||||
pub use settings::*;
|
pub use settings::*;
|
||||||
|
|
||||||
use gpui2::{Hsla, SharedString};
|
use gpui2::{HighlightStyle, Hsla, SharedString};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Theme {
|
pub struct Theme {
|
||||||
|
@ -78,12 +78,13 @@ pub struct Theme {
|
||||||
pub player: [PlayerTheme; 8],
|
pub player: [PlayerTheme; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone)]
|
||||||
pub struct SyntaxTheme {
|
pub struct SyntaxTheme {
|
||||||
pub comment: Hsla,
|
pub comment: Hsla,
|
||||||
pub string: Hsla,
|
pub string: Hsla,
|
||||||
pub function: Hsla,
|
pub function: Hsla,
|
||||||
pub keyword: Hsla,
|
pub keyword: Hsla,
|
||||||
|
pub highlights: Vec<(String, HighlightStyle)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
|
@ -93,7 +94,6 @@ pub struct PlayerTheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ThemeMetadata {
|
pub struct ThemeMetadata {
|
||||||
pub id: usize,
|
|
||||||
pub name: SharedString,
|
pub name: SharedString,
|
||||||
pub is_light: bool,
|
pub is_light: bool,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
use gpui2::rgba;
|
use gpui2::rgba;
|
||||||
|
|
||||||
use crate::{PlayerTheme, SyntaxTheme, Theme};
|
use crate::{PlayerTheme, SyntaxTheme, Theme, ThemeMetadata};
|
||||||
|
|
||||||
pub fn one_dark() -> Theme {
|
pub fn one_dark() -> Theme {
|
||||||
Theme {
|
Theme {
|
||||||
|
metadata: ThemeMetadata {
|
||||||
|
name: "One Dark".into(),
|
||||||
|
is_light: false,
|
||||||
|
},
|
||||||
transparent: rgba(0x00000000).into(),
|
transparent: rgba(0x00000000).into(),
|
||||||
mac_os_traffic_light_red: rgba(0xec695eff).into(),
|
mac_os_traffic_light_red: rgba(0xec695eff).into(),
|
||||||
mac_os_traffic_light_yellow: rgba(0xf4bf4eff).into(),
|
mac_os_traffic_light_yellow: rgba(0xf4bf4eff).into(),
|
||||||
|
@ -36,6 +40,7 @@ pub fn one_dark() -> Theme {
|
||||||
string: rgba(0xa1c181ff).into(),
|
string: rgba(0xa1c181ff).into(),
|
||||||
function: rgba(0x73ade9ff).into(),
|
function: rgba(0x73ade9ff).into(),
|
||||||
keyword: rgba(0xb477cfff).into(),
|
keyword: rgba(0xb477cfff).into(),
|
||||||
|
highlights: Vec::new(),
|
||||||
},
|
},
|
||||||
status_bar: rgba(0x3b414dff).into(),
|
status_bar: rgba(0x3b414dff).into(),
|
||||||
title_bar: rgba(0x3b414dff).into(),
|
title_bar: rgba(0x3b414dff).into(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue