diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-10 20:55:43 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-10 20:55:43 +0200 |
| commit | 7fa4f497f77471fa145881d759afe0b521971e04 (patch) | |
| tree | 4cb813362075667db6dbec140dc2ce166dc4d894 /src/time.rs | |
| parent | 47d15d537c61b828e72113cc8d3d8da3db9a2efb (diff) | |
| download | rutikmer-7fa4f497f77471fa145881d759afe0b521971e04.tar.gz rutikmer-7fa4f497f77471fa145881d759afe0b521971e04.tar.bz2 rutikmer-7fa4f497f77471fa145881d759afe0b521971e04.zip | |
Added shuffle generator
Diffstat (limited to 'src/time.rs')
| -rw-r--r-- | src/time.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/time.rs b/src/time.rs index 2cdd768..eba7507 100644 --- a/src/time.rs +++ b/src/time.rs @@ -39,12 +39,22 @@ impl Timer { self.state = State::Idle; } - pub fn to_texture<'a, T>(&'a self, font: &ttf::Font, texture_creator: &'a TextureCreator<T>) -> Texture { - let rendered = if self.state == State::Active { self.time.elapsed().unwrap() } else { self.result }; - - let surface = font.render(&rendered.as_millis().to_string()) - .solid(Color::RGB(255, 255, 255)) - .unwrap(); - texture_creator.create_texture_from_surface(&surface).unwrap() + pub fn to_texture<'a, T>( + &'a self, + font: &ttf::Font, + tex_creator: &'a TextureCreator<T>, + bg: &Color + ) -> Texture + { + 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() } } |
