Build workspace editor TextStyle from font fields in settings

We'll specify values in the theme but we'll only end up using the color for these editors.
This commit is contained in:
Nathan Sobo
2021-09-16 14:43:19 -06:00
parent a1f0693599
commit 4f0c9a3e31
3 changed files with 40 additions and 12 deletions
+4 -4
View File
@@ -17,7 +17,7 @@ use std::{
pub struct FamilyId(usize);
struct Family {
name: String,
name: Arc<str>,
font_ids: Vec<FontId>,
}
@@ -49,7 +49,7 @@ impl FontCache {
}))
}
pub fn family_name(&self, family_id: FamilyId) -> Result<String> {
pub fn family_name(&self, family_id: FamilyId) -> Result<Arc<str>> {
self.0
.read()
.families
@@ -62,7 +62,7 @@ impl FontCache {
for name in names {
let state = self.0.upgradable_read();
if let Some(ix) = state.families.iter().position(|f| f.name == *name) {
if let Some(ix) = state.families.iter().position(|f| f.name.as_ref() == *name) {
return Ok(FamilyId(ix));
}
@@ -81,7 +81,7 @@ impl FontCache {
}
state.families.push(Family {
name: String::from(*name),
name: Arc::from(*name),
font_ids,
});
return Ok(family_id);
+5 -2
View File
@@ -1,5 +1,6 @@
use crate::{
color::Color,
font_cache::FamilyId,
json::{json, ToJson},
text_layout::RunStyle,
FontCache,
@@ -22,6 +23,7 @@ pub type GlyphId = u32;
pub struct TextStyle {
pub color: Color,
pub font_family_name: Arc<str>,
pub font_family_id: FamilyId,
pub font_id: FontId,
pub font_size: f32,
pub font_properties: Properties,
@@ -85,11 +87,12 @@ impl TextStyle {
font_cache: &FontCache,
) -> anyhow::Result<Self> {
let font_family_name = font_family_name.into();
let family_id = font_cache.load_family(&[&font_family_name])?;
let font_id = font_cache.select_font(family_id, &font_properties)?;
let font_family_id = font_cache.load_family(&[&font_family_name])?;
let font_id = font_cache.select_font(font_family_id, &font_properties)?;
Ok(Self {
color,
font_family_name,
font_family_id,
font_id,
font_size,
font_properties,