From c71e522b4ea1b48865ceb5db3ee1d6a0803813ed Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 16 Nov 2023 11:37:46 -0500 Subject: [PATCH 1/6] Allow users to set UI font properties in their settings Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- assets/settings/default.json | 9 +++++++++ crates/editor2/src/editor.rs | 2 +- crates/theme2/src/settings.rs | 17 ++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 85f8a8fbc4..08d85dd723 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -35,6 +35,15 @@ // "custom": 2 // }, "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 // which gives the same size as all other panes. "active_pane_magnification": 1.0, diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 8e7bd5876f..0063bf2ce4 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -9387,7 +9387,7 @@ impl Render for Editor { font_size: rems(0.875).into(), font_weight: FontWeight::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, } } diff --git a/crates/theme2/src/settings.rs b/crates/theme2/src/settings.rs index 5e3329ffa1..c705617db0 100644 --- a/crates/theme2/src/settings.rs +++ b/crates/theme2/src/settings.rs @@ -34,6 +34,10 @@ pub struct ThemeSettingsContent { #[serde(default)] pub ui_font_size: Option, #[serde(default)] + pub ui_font_family: Option, + #[serde(default)] + pub ui_font_features: Option, + #[serde(default)] pub buffer_font_family: Option, #[serde(default)] pub buffer_font_size: Option, @@ -120,10 +124,10 @@ impl settings::Settings for ThemeSettings { let themes = cx.default_global::>(); 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 { - family: "Helvetica".into(), - features: Default::default(), + family: defaults.ui_font_family.clone().unwrap().into(), + features: defaults.ui_font_features.clone().unwrap(), weight: Default::default(), style: Default::default(), }, @@ -149,6 +153,13 @@ impl settings::Settings for ThemeSettings { 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(theme) = themes.get(value).log_err() { this.active_theme = theme; From b2f9c454b0215a8387e8c50c270eabb577896a41 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 16 Nov 2023 11:38:04 -0500 Subject: [PATCH 2/6] Change the default buffer font size to 16 Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- assets/settings/default.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 08d85dd723..0b87808e22 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -23,7 +23,7 @@ // "calt": false }, // The default font size for text in the editor - "buffer_font_size": 15, + "buffer_font_size": 16, // Set the buffer's line height. // May take 3 values: // 1. Use a line height that's comfortable for reading (1.618) From 38d0fdc09aafbeb9388396fd149fd47d568f59e4 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 16 Nov 2023 11:42:23 -0500 Subject: [PATCH 3/6] Remove todo Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/editor2/src/editor.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 0063bf2ce4..c4788ebd71 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -9379,18 +9379,16 @@ impl Render for Editor { fn render(&mut self, cx: &mut ViewContext) -> Self::Element { let settings = ThemeSettings::get_global(cx); let text_style = match self.mode { - EditorMode::SingleLine => { - TextStyle { - color: cx.theme().colors().text, - font_family: settings.ui_font.family.clone(), // todo!() - font_features: settings.ui_font.features, - font_size: rems(0.875).into(), - font_weight: FontWeight::NORMAL, - font_style: FontStyle::Normal, - line_height: relative(1.).into(), - underline: None, - } - } + EditorMode::SingleLine => TextStyle { + color: cx.theme().colors().text, + font_family: settings.ui_font.family.clone(), + font_features: settings.ui_font.features, + font_size: rems(0.875).into(), + font_weight: FontWeight::NORMAL, + font_style: FontStyle::Normal, + line_height: relative(1.).into(), + underline: None, + }, EditorMode::AutoHeight { max_lines } => todo!(), From 08dddf0b262605d9d5a75c20c31521fdd5f7eaab Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 16 Nov 2023 13:13:03 -0500 Subject: [PATCH 4/6] Revert change to default buffer font size --- assets/settings/default.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 0b87808e22..08d85dd723 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -23,7 +23,7 @@ // "calt": false }, // The default font size for text in the editor - "buffer_font_size": 16, + "buffer_font_size": 15, // Set the buffer's line height. // May take 3 values: // 1. Use a line height that's comfortable for reading (1.618) From fa9f4a935554758ee9a3f17485ba3b50ebe913af Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 16 Nov 2023 13:43:36 -0500 Subject: [PATCH 5/6] Init rem_size in the workspace at the start of the render Co-Authored-By: Mikayla Maki --- crates/workspace2/src/workspace2.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index f28675661d..e09624bd2c 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -3614,7 +3614,16 @@ impl Render for Workspace { fn render(&mut self, cx: &mut ViewContext) -> Self::Element { let mut context = KeyContext::default(); 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()) .key_context(context) From ffd092a098c54a8b8c4f8f497038b9f6e626d93f Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 16 Nov 2023 15:30:50 -0500 Subject: [PATCH 6/6] Add ui_font_* for tests --- crates/settings2/src/settings_file.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/settings2/src/settings_file.rs b/crates/settings2/src/settings_file.rs index 6f2c8d374f..fc4ad5882e 100644 --- a/crates/settings2/src/settings_file.rs +++ b/crates/settings2/src/settings_file.rs @@ -16,6 +16,9 @@ pub fn test_settings() -> String { .unwrap(); util::merge_non_null_json_value_into( serde_json::json!({ + "ui_font_family": "Courier", + "ui_font_features": {}, + "ui_font_size": 14, "buffer_font_family": "Courier", "buffer_font_features": {}, "buffer_font_size": 14,