|
|
@@ -63,16 +63,7 @@ impl TextManager { |
|
|
|
TextCache::new(self) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn font_by_name(&self, name: &str) -> Result<FontArc, Error> { |
|
|
|
if let Some(font) = self.0.borrow().fonts.get(name) { |
|
|
|
return Ok(font.clone()); |
|
|
|
} |
|
|
|
|
|
|
|
let path = format!("resources/fonts/{}", name); |
|
|
|
self.font_by_path(&path) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn font_by_path(&self, path: &str) -> Result<FontArc, Error> { |
|
|
|
pub fn font(&self, path: &str) -> Result<FontArc, Error> { |
|
|
|
if let Some(font) = self.0.borrow().fonts.get(path) { |
|
|
|
return Ok(font.clone()); |
|
|
|
} |
|
|
@@ -165,26 +156,14 @@ impl TextCache { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn font_by_name(&self, name: &str) -> Result<FontId, Error> { |
|
|
|
let mut inner = self.0.borrow_mut(); |
|
|
|
|
|
|
|
if let Some(id) = inner.fonts.get(name) { |
|
|
|
return Ok(*id); |
|
|
|
} |
|
|
|
|
|
|
|
let font = inner.manager.font_by_name(name)?; |
|
|
|
|
|
|
|
inner.add_font(font) |
|
|
|
} |
|
|
|
|
|
|
|
fn font_by_path(&self, path: &str) -> Result<FontId, Error> { |
|
|
|
fn font(&self, path: &str) -> Result<FontId, Error> { |
|
|
|
let mut inner = self.0.borrow_mut(); |
|
|
|
|
|
|
|
if let Some(id) = inner.fonts.get(path) { |
|
|
|
return Ok(*id); |
|
|
|
} |
|
|
|
|
|
|
|
let font = inner.manager.font_by_path(path)?; |
|
|
|
let font = inner.manager.font(path)?; |
|
|
|
|
|
|
|
inner.add_font(font) |
|
|
|
} |
|
|
@@ -415,9 +394,8 @@ pub struct TextBuilder { |
|
|
|
|
|
|
|
enum BuilderItem { |
|
|
|
Position(f32, f32), |
|
|
|
FontName(String), |
|
|
|
FontPath(String), |
|
|
|
Color(Vector4f), |
|
|
|
Font(String), |
|
|
|
Text(String), |
|
|
|
Scale(f32), |
|
|
|
} |
|
|
@@ -472,8 +450,7 @@ impl TextBuilder { |
|
|
|
BuilderItem::Position(x, y) => position = Some((x, y)), |
|
|
|
BuilderItem::Color(c) => color = c, |
|
|
|
BuilderItem::Scale(s) => scale = s, |
|
|
|
BuilderItem::FontName(name) => font_id = Some(self.cache.font_by_name(&name)?), |
|
|
|
BuilderItem::FontPath(path) => font_id = Some(self.cache.font_by_path(&path)?), |
|
|
|
BuilderItem::Font(path) => font_id = Some(self.cache.font(&path)?), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -491,20 +468,11 @@ impl TextBuilder { |
|
|
|
self |
|
|
|
} |
|
|
|
|
|
|
|
pub fn font_name<S>(mut self, name: S) -> Self |
|
|
|
where |
|
|
|
S: Display, |
|
|
|
{ |
|
|
|
self.items.push(BuilderItem::FontName(name.to_string())); |
|
|
|
|
|
|
|
self |
|
|
|
} |
|
|
|
|
|
|
|
pub fn font_path<S>(mut self, path: S) -> Self |
|
|
|
pub fn font<S>(mut self, path: S) -> Self |
|
|
|
where |
|
|
|
S: Display, |
|
|
|
{ |
|
|
|
self.items.push(BuilderItem::FontPath(path.to_string())); |
|
|
|
self.items.push(BuilderItem::Font(path.to_string())); |
|
|
|
|
|
|
|
self |
|
|
|
} |
|
|
|