mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
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:
parent
a1f0693599
commit
4f0c9a3e31
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -2597,15 +2597,18 @@ impl Snapshot {
|
||||
}
|
||||
|
||||
impl EditorStyle {
|
||||
#[cfg(any(test, feature ="test-support"))]
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn test(font_cache: &FontCache) -> Self {
|
||||
let font_family_name = "Monaco";
|
||||
let font_family_name = Arc::from("Monaco");
|
||||
let font_properties = Default::default();
|
||||
let family_id = font_cache.load_family(&[font_family_name]).unwrap();
|
||||
let font_id = font_cache.select_font(family_id, &font_properties).unwrap();
|
||||
let font_family_id = font_cache.load_family(&[&font_family_name]).unwrap();
|
||||
let font_id = font_cache
|
||||
.select_font(font_family_id, &font_properties)
|
||||
.unwrap();
|
||||
Self {
|
||||
text: TextStyle {
|
||||
font_family_name: font_family_name.into(),
|
||||
font_family_name,
|
||||
font_family_id,
|
||||
font_id,
|
||||
font_size: 14.,
|
||||
color: Color::from_u32(0xff0000ff),
|
||||
@ -2718,7 +2721,29 @@ impl workspace::Item for Buffer {
|
||||
Editor::for_buffer(
|
||||
handle,
|
||||
settings.clone(),
|
||||
move |_| settings.borrow().theme.editor.clone(),
|
||||
move |cx| {
|
||||
let settings = settings.borrow();
|
||||
let font_cache = cx.font_cache();
|
||||
let font_family_id = settings.buffer_font_family;
|
||||
let font_family_name = cx.font_cache().family_name(font_family_id).unwrap();
|
||||
let font_properties = Default::default();
|
||||
let font_id = font_cache
|
||||
.select_font(font_family_id, &font_properties)
|
||||
.unwrap();
|
||||
let font_size = settings.buffer_font_size;
|
||||
|
||||
let mut theme = settings.theme.editor.clone();
|
||||
theme.text = TextStyle {
|
||||
color: theme.text.color,
|
||||
font_family_name,
|
||||
font_family_id,
|
||||
font_id,
|
||||
font_size,
|
||||
font_properties,
|
||||
underline: false,
|
||||
};
|
||||
theme
|
||||
},
|
||||
cx,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user