From c71e522b4ea1b48865ceb5db3ee1d6a0803813ed Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Thu, 16 Nov 2023 11:37:46 -0500 Subject: [PATCH] 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 85f8a8fbc4b290c8fc7f913a44fbe0f767341510..08d85dd723cc13ca98b0b239a199b263f738d99a 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 8e7bd5876f7d69c3254464ff9d32b31ad5877037..0063bf2ce4274de298ec8d5a2a2a5c4d2574219a 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 5e3329ffa149b1f744f7031162c7235961c42a96..c705617db04f2a554c4853ceac370087ecc52edf 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;