Browse Source

Removed fonts by name (use only paths)

raster
Bergmann89 3 years ago
parent
commit
3dbba8a9c0
2 changed files with 8 additions and 40 deletions
  1. +7
    -39
      space-crush/src/app/misc/text.rs
  2. +1
    -1
      space-crush/src/app/render/debug.rs

+ 7
- 39
space-crush/src/app/misc/text.rs View File

@@ -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
}


+ 1
- 1
space-crush/src/app/render/debug.rs View File

@@ -25,7 +25,7 @@ impl Debug {
let text = cache
.new_text()
.scale(12.0)
.font_name("DroidSansMono.ttf")
.font("resources/fonts/DroidSansMono.ttf")
.color(0.7, 0.7, 0.7, 1.0)
.position(5.0, 5.0)
.text(format!("Space Crush v{}\n", env!("CARGO_PKG_VERSION")))


Loading…
Cancel
Save