diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-25 13:25:07 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-25 13:25:07 +0200 |
| commit | c2126083c928b54f7cd6436ab38d38b20498a18b (patch) | |
| tree | e0c6ed62754cc37042ae96debb6c5a66af1fa975 /src/text.rs | |
| parent | 86044397b8fac9298295cc22b40413d8f37025e3 (diff) | |
| download | rutikmer-c2126083c928b54f7cd6436ab38d38b20498a18b.tar.gz rutikmer-c2126083c928b54f7cd6436ab38d38b20498a18b.tar.bz2 rutikmer-c2126083c928b54f7cd6436ab38d38b20498a18b.zip | |
Removing fancy text/ui, Added basic fixed size layout
Diffstat (limited to 'src/text.rs')
| -rw-r--r-- | src/text.rs | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/src/text.rs b/src/text.rs deleted file mode 100644 index e62db3d..0000000 --- a/src/text.rs +++ /dev/null @@ -1,64 +0,0 @@ -use sdl2::ttf; -use sdl2::render::{Canvas, Texture, TextureCreator}; -use sdl2::pixels::Color; -use sdl2::rect::Rect; - -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, - font_size: u32, -} - -impl<'a, T> Factory<'a, T> { - pub fn new(font: &'a ttf::Font, - creator: &'a TextureCreator<T>, - bg: Color, - font_size: u32 - ) -> Factory<'a, T> - { - Factory { font, creator, bg, font_size } - } - - pub fn from_string(&self, s: &str) -> 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; - } -} - -struct Frame<'a> { - width: u32, - height: u32, - texture: Texture<'a>, -} - -impl<'a> Frame<'a> { - fn new<T>(s: &'a str, factory: &'a Factory<T>) -> Frame<'a> { - Frame{ - width: s.len() as u32 * factory.font_size, - height: factory.font_size, - texture: factory.from_string(s) - } - } - - fn to_rect(&self, x: i32, y: i32) -> Rect { - Rect::new(x, y, self.width, self.height) - } -} - -trait Framable { - fn to_frame<'a>(&'a self) -> Frame<'a>; - - fn put_canvas<T: sdl2::render::RenderTarget>(&self, canvas: &mut Canvas<T>, x: i32, y: i32) { - let frame = self.to_frame(); - let rect = frame.to_rect(x, y); - canvas.copy(&frame.texture, None, rect); - } -} |
