diff --git a/gpui/src/elements/line_box.rs b/gpui/src/elements/line_box.rs index b6ce6d9e9544e274a60aa67783cad25577da2f9d..cf8f6ca605cf45272ab21b12a9f3f6810722a2bc 100644 --- a/gpui/src/elements/line_box.rs +++ b/gpui/src/elements/line_box.rs @@ -1,6 +1,5 @@ use crate::{ - font_cache::FamilyId, - fonts::Properties, + fonts::TextStyle, geometry::{ rect::RectF, vector::{vec2f, Vector2F}, @@ -12,19 +11,12 @@ use crate::{ pub struct LineBox { child: ElementBox, - family_id: FamilyId, - font_size: f32, - font_properties: Properties, + style: TextStyle, } impl LineBox { - pub fn new(family_id: FamilyId, font_size: f32, child: ElementBox) -> Self { - Self { - child, - family_id, - font_size, - font_properties: Properties::default(), - } + pub fn new(child: ElementBox, style: TextStyle) -> Self { + Self { child, style } } } @@ -37,27 +29,21 @@ impl Element for LineBox { constraint: SizeConstraint, cx: &mut LayoutContext, ) -> (Vector2F, Self::LayoutState) { - match cx + let line_height = cx .font_cache - .select_font(self.family_id, &self.font_properties) - { - Ok(font_id) => { - let line_height = cx.font_cache.line_height(font_id, self.font_size); - let character_height = cx.font_cache.ascent(font_id, self.font_size) - + cx.font_cache.descent(font_id, self.font_size); - let child_max = vec2f(constraint.max.x(), character_height); - let child_size = self.child.layout( - SizeConstraint::new(constraint.min.min(child_max), child_max), - cx, - ); - let size = vec2f(child_size.x(), line_height); - (size, (line_height - character_height) / 2.) - } - Err(error) => { - log::error!("can't find font for LineBox: {}", error); - (constraint.min, 0.0) - } - } + .line_height(self.style.font_id, self.style.font_size); + let character_height = cx + .font_cache + .ascent(self.style.font_id, self.style.font_size) + + cx.font_cache + .descent(self.style.font_id, self.style.font_size); + let child_max = vec2f(constraint.max.x(), character_height); + let child_size = self.child.layout( + SizeConstraint::new(constraint.min.min(child_max), child_max), + cx, + ); + let size = vec2f(child_size.x(), line_height); + (size, (line_height - character_height) / 2.) } fn paint( @@ -90,9 +76,7 @@ impl Element for LineBox { ) -> serde_json::Value { json!({ "bounds": bounds.to_json(), - "font_family": cx.font_cache.family_name(self.family_id).unwrap(), - "font_size": self.font_size, - "font_properties": self.font_properties.to_json(), + "style": self.style.to_json(), "child": self.child.debug(cx), }) } diff --git a/zed/src/editor/display_map.rs b/zed/src/editor/display_map.rs index e5f18b56dbdbd7f4c5dcdf79da4b0c3605f321d6..2758c030b3efc055ee450d058e8103460fc93563 100644 --- a/zed/src/editor/display_map.rs +++ b/zed/src/editor/display_map.rs @@ -531,9 +531,7 @@ mod tests { let settings = Settings { buffer_font_family: font_cache.load_family(&["Helvetica"]).unwrap(), - ui_font_family: font_cache.load_family(&["Helvetica"]).unwrap(), buffer_font_size: 12.0, - ui_font_size: 12.0, tab_size: 4, ..cx.read(Settings::test) }; diff --git a/zed/src/file_finder.rs b/zed/src/file_finder.rs index 76c2f71dc8c7a1a5c611c575d9c09f6a0cdd9992..3cf539909e2d5a6735ec72c943ef307694c5082f 100644 --- a/zed/src/file_finder.rs +++ b/zed/src/file_finder.rs @@ -162,11 +162,10 @@ impl FileFinder { .with_child( Container::new( LineBox::new( - settings.ui_font_family, - settings.ui_font_size, Svg::new("icons/file-16.svg") .with_color(style.label.text.color) .boxed(), + style.label.text.clone(), ) .boxed(), ) diff --git a/zed/src/settings.rs b/zed/src/settings.rs index dba30749b4c14422b829c13743b7187bbbc42bf1..1cadfdaa9c1f8fa7bc93449f590551ce0ebfe728 100644 --- a/zed/src/settings.rs +++ b/zed/src/settings.rs @@ -11,8 +11,6 @@ pub struct Settings { pub buffer_font_family: FamilyId, pub buffer_font_size: f32, pub tab_size: usize, - pub ui_font_family: FamilyId, - pub ui_font_size: f32, pub theme: Arc, } @@ -42,8 +40,6 @@ impl Settings { buffer_font_family: font_cache.load_family(&["Fira Code", "Monaco"])?, buffer_font_size: 14.0, tab_size: 4, - ui_font_family: font_cache.load_family(&["SF Pro", "Helvetica"])?, - ui_font_size: 12.0, theme, }) } diff --git a/zed/src/workspace/pane.rs b/zed/src/workspace/pane.rs index 1be0fccd583df1c1d11e9515e605378de78a5f1e..7e6e2592bc15729142a09950e4841178084d353d 100644 --- a/zed/src/workspace/pane.rs +++ b/zed/src/workspace/pane.rs @@ -179,8 +179,8 @@ impl Pane { let settings = self.settings.borrow(); let theme = &settings.theme; let line_height = cx.font_cache().line_height( - cx.font_cache().default_font(settings.ui_font_family), - settings.ui_font_size, + theme.workspace.tab.label.text.font_id, + theme.workspace.tab.label.text.font_size, ); let mut row = Flex::row(); diff --git a/zed/src/workspace/sidebar.rs b/zed/src/workspace/sidebar.rs index 8bb3f06fc1a013c8a59688e54aba0daee52446a6..242b557c39841687930413a3ab013b819e771403 100644 --- a/zed/src/workspace/sidebar.rs +++ b/zed/src/workspace/sidebar.rs @@ -61,9 +61,10 @@ impl Sidebar { pub fn render(&self, settings: &Settings, cx: &AppContext) -> ElementBox { let side = self.side; + let theme = &settings.theme; let line_height = cx.font_cache().line_height( - cx.font_cache().default_font(settings.ui_font_family), - settings.ui_font_size, + theme.workspace.tab.label.text.font_id, + theme.workspace.tab.label.text.font_size, ); Container::new(