Remove ui font fields from settings
This commit is contained in:
@@ -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),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
|
||||
@@ -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<Theme>,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user