Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use editor's current font size to scale UI elements (#11844)
Thorsten Ball8bc41e150e2d
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 55f3f57176d..a1e3d6099c6 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -58,7 +58,7 @@ use std::{sync::Arc,};use sum_tree::Bias;-use theme::{ActiveTheme, PlayerColor, ThemeSettings};+use theme::{ActiveTheme, PlayerColor};use ui::prelude::*;use ui::{h_flex, ButtonLike, ButtonStyle, ContextMenu, Tooltip};use util::ResultExt;@@ -3388,11 +3388,7 @@ fn render_inline_blame_entry(.font_family(style.text.font().family).text_color(cx.theme().status().hint).line_height(style.text.line_height)- .child(- Icon::new(IconName::FileGit)- .color(Color::Hint)- .font_size(style.text.font_size),- )+ .child(Icon::new(IconName::FileGit).color(Color::Hint)).child(text).gap_2().hoverable_tooltip(move |_| tooltip.clone().into())@@ -3712,22 +3708,30 @@ impl EditorElement {fn rem_size(&self, cx: &WindowContext) -> Option<Pixels> {match self.editor.read(cx).mode {EditorMode::Full => {- let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;- let rem_size_scale = {- // Our default UI font size is 14px on a 16px base scale.- // This means the default UI font size is 0.875rems.- let default_font_size_scale = 14. / ui::BASE_REM_SIZE_IN_PX;-- // We then determine the delta between a single rem and the default font- // size scale.- let default_font_size_delta = 1. - default_font_size_scale;-- // Finally, we add this delta to 1rem to get the scale factor that- // should be used to scale up the UI.- 1. + default_font_size_delta- };+ let buffer_font_size = self.style.text.font_size;+ match buffer_font_size {+ AbsoluteLength::Pixels(pixels) => {+ let rem_size_scale = {+ // Our default UI font size is 14px on a 16px base scale.+ // This means the default UI font size is 0.875rems.+ let default_font_size_scale = 14. / ui::BASE_REM_SIZE_IN_PX;++ // We then determine the delta between a single rem and the default font+ // size scale.+ let default_font_size_delta = 1. - default_font_size_scale;++ // Finally, we add this delta to 1rem to get the scale factor that+ // should be used to scale up the UI.+ 1. + default_font_size_delta+ };- Some(buffer_font_size * rem_size_scale)+ Some(pixels * rem_size_scale)+ }+ AbsoluteLength::Rems(rems) => {+ println!("here!!!!");+ Some(rems.to_pixels(ui::BASE_REM_SIZE_IN_PX.into()))+ }+ }}// We currently use single-line and auto-height editors in UI contexts,// so we don't want to scale everything with the buffer font size, as itdiff --git a/crates/ui/src/components/icon.rs b/crates/ui/src/components/icon.rsindex 75eae2a4f0c..38920d7d228 100644--- a/crates/ui/src/components/icon.rs+++ b/crates/ui/src/components/icon.rs@@ -348,14 +348,6 @@ impl Icon {self}- pub fn font_size(self, font_size: AbsoluteLength) -> Self {- let rems = match font_size {- AbsoluteLength::Pixels(pixels) => rems_from_px(pixels.into()),- AbsoluteLength::Rems(rems) => rems,- };- self.custom_size(rems)- }-pub fn transform(mut self, transformation: Transformation) -> Self {self.transformation = transformation;self