aboutsummaryrefslogtreecommitdiff
path: root/src/text.rs
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-11 10:29:27 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-11 10:29:27 +0200
commit6e47e69d45d30481e98c4fba5542c195b0fb830e (patch)
tree1de845fb49efae19d7044be353c0d1886ae3e1b0 /src/text.rs
parent7fa4f497f77471fa145881d759afe0b521971e04 (diff)
downloadrutikmer-6e47e69d45d30481e98c4fba5542c195b0fb830e.tar.gz
rutikmer-6e47e69d45d30481e98c4fba5542c195b0fb830e.tar.bz2
rutikmer-6e47e69d45d30481e98c4fba5542c195b0fb830e.zip
Added text factory
Diffstat (limited to 'src/text.rs')
-rw-r--r--src/text.rs45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/text.rs b/src/text.rs
index 10ca700..a27ca49 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -2,27 +2,42 @@ use sdl2::ttf;
use sdl2::render::{Texture, TextureCreator};
use sdl2::pixels::Color;
-struct Factory<'a, T> {
- font: ttf::Font<'a, 'a>,
+const WHITE: Color = Color::RGB(255, 255, 255);
+
+pub struct Factory<'a, T> {
+ font: &'a ttf::Font<'a, 'a>,
creator: &'a TextureCreator<T>,
bg: Color,
}
-impl Factory<'a, T> {
- pub fn new(font: &ttf::Font<'a, 'a>, creator: &'a TextureCreator<T>, bg: Color) -> Factory {
+impl<'a, T> Factory<'a, T> {
+ pub fn new(font: &'a ttf::Font,
+ creator: &'a TextureCreator<T>,
+ bg: Color
+ ) -> Factory<'a, T>
+ {
Factory { font, creator, bg }
}
-}
-pub fn to_texture<'a, T>(
- s: &'a String,
- font: &ttf::Font,
- tex_creator: &'a TextureCreator<T>,
- bg: &Color
-) -> Texture<'a>
-{
- let surface = font.render(s).shaded(Color::RGB(255, 255, 255), *bg).unwrap();
- tex_creator.create_texture_from_surface(&surface).unwrap()
+ pub fn from_string(&self, s: &String) -> Texture
+ {
+ let surface = self.font.render(s).shaded(WHITE, self.bg).unwrap();
+ self.creator.create_texture_from_surface(&surface).unwrap()
+ }
+
+ pub fn set_bg(&mut self, bg: Color) {
+ self.bg = bg;
+ }
}
-// pub fn width(s: &String
+
+// pub trait TextTexture {
+// fn to_texture<T>(&self, factory: &Factory<T>) -> Texture;
+// }
+//
+// impl TextTexture for String {
+// fn to_texture<T>(&self, factory: &Factory<T>) -> Texture {
+// let surface = factory.font.render(self).shaded(WHITE, factory.bg).unwrap();
+// factory.creator.create_texture_from_surface(&surface).unwrap()
+// }
+// }