From 3dbba8a9c08a22e9d6b2c440162e81e6d2a4e415 Mon Sep 17 00:00:00 2001 From: Bergmann89 Date: Sun, 6 Dec 2020 14:48:05 +0100 Subject: [PATCH] Removed fonts by name (use only paths) --- space-crush/src/app/misc/text.rs | 46 +++++------------------------ space-crush/src/app/render/debug.rs | 2 +- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/space-crush/src/app/misc/text.rs b/space-crush/src/app/misc/text.rs index 7c090f8..e9b8c82 100644 --- a/space-crush/src/app/misc/text.rs +++ b/space-crush/src/app/misc/text.rs @@ -63,16 +63,7 @@ impl TextManager { TextCache::new(self) } - pub fn font_by_name(&self, name: &str) -> Result { - 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 { + pub fn font(&self, path: &str) -> Result { 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 { - 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 { + fn font(&self, path: &str) -> Result { 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(mut self, name: S) -> Self - where - S: Display, - { - self.items.push(BuilderItem::FontName(name.to_string())); - - self - } - - pub fn font_path(mut self, path: S) -> Self + pub fn font(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 } diff --git a/space-crush/src/app/render/debug.rs b/space-crush/src/app/render/debug.rs index fb6e8a1..64d1867 100644 --- a/space-crush/src/app/render/debug.rs +++ b/space-crush/src/app/render/debug.rs @@ -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")))