diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-11 10:29:27 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-11 10:29:27 +0200 |
| commit | 6e47e69d45d30481e98c4fba5542c195b0fb830e (patch) | |
| tree | 1de845fb49efae19d7044be353c0d1886ae3e1b0 /src/time.rs | |
| parent | 7fa4f497f77471fa145881d759afe0b521971e04 (diff) | |
| download | rutikmer-6e47e69d45d30481e98c4fba5542c195b0fb830e.tar.gz rutikmer-6e47e69d45d30481e98c4fba5542c195b0fb830e.tar.bz2 rutikmer-6e47e69d45d30481e98c4fba5542c195b0fb830e.zip | |
Added text factory
Diffstat (limited to 'src/time.rs')
| -rw-r--r-- | src/time.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/time.rs b/src/time.rs index eba7507..791ff2e 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,7 +1,4 @@ use std::time::{SystemTime, Duration}; -use sdl2::ttf; -use sdl2::render::{Texture, TextureCreator}; -use sdl2::pixels::Color; #[derive(PartialEq)] pub enum State { @@ -38,23 +35,18 @@ impl Timer { pub fn idle(&mut self) { self.state = State::Idle; } +} + +use std::fmt; - pub fn to_texture<'a, T>( - &'a self, - font: &ttf::Font, - tex_creator: &'a TextureCreator<T>, - bg: &Color - ) -> Texture - { +impl fmt::Display for Timer { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let current = if self.state == State::Active { self.time.elapsed().unwrap() } else { self.result }.as_millis(); - let s = format!("{}.{}", current / 1000, current % 1000); - - let surface = font.render(&s).shaded(Color::RGB(255, 255, 255), *bg).unwrap(); - tex_creator.create_texture_from_surface(&surface).unwrap() + write!(f, "{}.{}", current / 1000, current % 1000) } } |
