Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Checkpoint
Nathan Sobo1ee70a014638
diff --git a/crates/gpui3/src/elements/text.rs b/crates/gpui3/src/elements/text.rsindex 6530a3c4230..e188370a6f3 100644--- a/crates/gpui3/src/elements/text.rs+++ b/crates/gpui3/src/elements/text.rs@@ -42,7 +42,9 @@ impl<S: 'static> Element for Text<S> {let text_system = cx.text_system().clone();let text_style = cx.text_style();let font_size = text_style.font_size * cx.rem_size();- let line_height = cx.text_system().line_height(font_size);+ let line_height = text_style+ .line_height+ .to_pixels(font_size.into(), cx.rem_size());let text = self.text.clone();let paint_state = Arc::new(Mutex::new(None));diff --git a/crates/gpui3/src/geometry.rs b/crates/gpui3/src/geometry.rsindex 9b4f04ab3f7..c587096e7c0 100644--- a/crates/gpui3/src/geometry.rs+++ b/crates/gpui3/src/geometry.rs@@ -572,6 +572,18 @@ pub enum DefiniteLength {Fraction(f32),}+impl DefiniteLength {+ pub fn to_pixels(&self, base_size: AbsoluteLength, rem_size: Pixels) -> Pixels {+ match self {+ DefiniteLength::Absolute(size) => size.to_pixels(rem_size),+ DefiniteLength::Fraction(fraction) => match base_size {+ AbsoluteLength::Pixels(px) => px * *fraction,+ AbsoluteLength::Rems(rems) => rems * rem_size * *fraction,+ },+ }+ }+}+impl Debug for DefiniteLength {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {match self {@@ -625,6 +637,11 @@ pub fn relative(fraction: f32) -> DefiniteLength {DefiniteLength::Fraction(fraction).into()}+/// Returns the Golden Ratio, i.e. `~(1.0 + sqrt(5.0)) / 2.0`.+pub fn phi() -> DefiniteLength {+ relative(1.61803398875)+}+pub fn rems(rems: f32) -> Rems {Rems(rems)}diff --git a/crates/gpui3/src/style.rs b/crates/gpui3/src/style.rsindex 2d1467d6a72..a8bac7ed782 100644--- a/crates/gpui3/src/style.rs+++ b/crates/gpui3/src/style.rs@@ -1,5 +1,5 @@use crate::{- rems, AbsoluteLength, Bounds, Corners, CornersRefinement, DefiniteLength, Edges,+ phi, rems, AbsoluteLength, Bounds, Corners, CornersRefinement, DefiniteLength, Edges,EdgesRefinement, Font, FontFeatures, FontStyle, FontWeight, Hsla, Length, Pixels, Point,PointRefinement, Rems, Result, RunStyle, SharedString, Size, SizeRefinement, ViewContext,WindowContext,@@ -100,6 +100,7 @@ pub struct TextStyle {pub font_family: SharedString,pub font_features: FontFeatures,pub font_size: Rems,+ pub line_height: DefiniteLength,pub font_weight: FontWeight,pub font_style: FontStyle,pub underline: Option<UnderlineStyle>,@@ -112,6 +113,7 @@ impl Default for TextStyle {font_family: SharedString::default(),font_features: FontFeatures::default(),font_size: rems(1.),+ line_height: phi(),font_weight: FontWeight::default(),font_style: FontStyle::default(),underline: None,diff --git a/crates/gpui3/src/text_system.rs b/crates/gpui3/src/text_system.rsindex f33ee9e0360..c65331a8da5 100644--- a/crates/gpui3/src/text_system.rs+++ b/crates/gpui3/src/text_system.rs@@ -99,19 +99,13 @@ impl TextSystem {let result =self.platform_text_system.advance(font_id, glyph_id)? / self.units_per_em(font)? as f32;- let result = result * font_size;- Ok(todo!())+ Ok(result * font_size)}pub fn units_per_em(&self, font: &Font) -> Result<u32> {self.read_metrics(font, |metrics| metrics.units_per_em as u32)}- pub fn line_height(&self, font_size: Pixels) -> Pixels {- todo!()- // self.font_cache.line_height(font_size)- }-pub fn cap_height(&self, font: &Font, font_size: Pixels) -> Result<Pixels> {self.read_metrics(font, |metrics| metrics.cap_height(font_size))}@@ -128,8 +122,12 @@ impl TextSystem {self.read_metrics(font, |metrics| metrics.descent(font_size))}- pub fn baseline_offset(&self, font: &Font, font_size: Pixels) -> Result<Pixels> {- let line_height = self.line_height(font_size);+ pub fn baseline_offset(+ &self,+ font: &Font,+ font_size: Pixels,+ line_height: Pixels,+ ) -> Result<Pixels> {let ascent = self.ascent(font, font_size)?;let descent = self.descent(font, font_size)?;let padding_top = (line_height - ascent - descent) / 2.;