Add ui_font settings and set default rem size accordingly (#3346)

[[PR Description]]
- Adds ui_font_family, ui_font_features, ui_font_size to settings and
default settings
- Use the new ui font settings to set the rem size when the workspace is
created.

Release Notes:

- N/A
This commit is contained in:
Nate Butler 2023-11-16 15:40:33 -05:00 committed by GitHub
commit a526f23c81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 16 deletions

View file

@ -35,6 +35,15 @@
// "custom": 2 // "custom": 2
// }, // },
"buffer_line_height": "comfortable", "buffer_line_height": "comfortable",
// The name of a font to use for rendering text in the UI
"ui_font_family": "Zed Mono",
// The OpenType features to enable for text in the UI
"ui_font_features": {
// Disable ligatures:
"calt": false
},
// The default font size for text in the UI
"ui_font_size": 14,
// The factor to grow the active pane by. Defaults to 1.0 // The factor to grow the active pane by. Defaults to 1.0
// which gives the same size as all other panes. // which gives the same size as all other panes.
"active_pane_magnification": 1.0, "active_pane_magnification": 1.0,

View file

@ -9379,18 +9379,16 @@ impl Render for Editor {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let settings = ThemeSettings::get_global(cx); let settings = ThemeSettings::get_global(cx);
let text_style = match self.mode { let text_style = match self.mode {
EditorMode::SingleLine => { EditorMode::SingleLine => TextStyle {
TextStyle {
color: cx.theme().colors().text, color: cx.theme().colors().text,
font_family: settings.ui_font.family.clone(), // todo!() font_family: settings.ui_font.family.clone(),
font_features: settings.ui_font.features, font_features: settings.ui_font.features,
font_size: rems(0.875).into(), font_size: rems(0.875).into(),
font_weight: FontWeight::NORMAL, font_weight: FontWeight::NORMAL,
font_style: FontStyle::Normal, font_style: FontStyle::Normal,
line_height: relative(1.3).into(), // TODO relative(settings.buffer_line_height.value()), line_height: relative(1.).into(),
underline: None, underline: None,
} },
}
EditorMode::AutoHeight { max_lines } => todo!(), EditorMode::AutoHeight { max_lines } => todo!(),

View file

@ -16,6 +16,9 @@ pub fn test_settings() -> String {
.unwrap(); .unwrap();
util::merge_non_null_json_value_into( util::merge_non_null_json_value_into(
serde_json::json!({ serde_json::json!({
"ui_font_family": "Courier",
"ui_font_features": {},
"ui_font_size": 14,
"buffer_font_family": "Courier", "buffer_font_family": "Courier",
"buffer_font_features": {}, "buffer_font_features": {},
"buffer_font_size": 14, "buffer_font_size": 14,

View file

@ -34,6 +34,10 @@ pub struct ThemeSettingsContent {
#[serde(default)] #[serde(default)]
pub ui_font_size: Option<f32>, pub ui_font_size: Option<f32>,
#[serde(default)] #[serde(default)]
pub ui_font_family: Option<String>,
#[serde(default)]
pub ui_font_features: Option<FontFeatures>,
#[serde(default)]
pub buffer_font_family: Option<String>, pub buffer_font_family: Option<String>,
#[serde(default)] #[serde(default)]
pub buffer_font_size: Option<f32>, pub buffer_font_size: Option<f32>,
@ -120,10 +124,10 @@ impl settings::Settings for ThemeSettings {
let themes = cx.default_global::<ThemeRegistry>(); let themes = cx.default_global::<ThemeRegistry>();
let mut this = Self { let mut this = Self {
ui_font_size: defaults.ui_font_size.unwrap_or(16.).into(), ui_font_size: defaults.ui_font_size.unwrap().into(),
ui_font: Font { ui_font: Font {
family: "Helvetica".into(), family: defaults.ui_font_family.clone().unwrap().into(),
features: Default::default(), features: defaults.ui_font_features.clone().unwrap(),
weight: Default::default(), weight: Default::default(),
style: Default::default(), style: Default::default(),
}, },
@ -149,6 +153,13 @@ impl settings::Settings for ThemeSettings {
this.buffer_font.features = value; this.buffer_font.features = value;
} }
if let Some(value) = value.ui_font_family {
this.ui_font.family = value.into();
}
if let Some(value) = value.ui_font_features {
this.ui_font.features = value;
}
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).log_err() {
this.active_theme = theme; this.active_theme = theme;

View file

@ -3614,7 +3614,16 @@ impl Render for Workspace {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let mut context = KeyContext::default(); let mut context = KeyContext::default();
context.add("Workspace"); context.add("Workspace");
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
let (ui_font, ui_font_size) = {
let theme_settings = ThemeSettings::get_global(cx);
(
theme_settings.ui_font.family.clone(),
theme_settings.ui_font_size.clone(),
)
};
cx.set_rem_size(ui_font_size);
self.add_workspace_actions_listeners(div()) self.add_workspace_actions_listeners(div())
.key_context(context) .key_context(context)