1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
use display::colour::Colour; use display::display::Display; use graphics::Graphic; pub struct Text { pos_x: isize, pos_y: isize, text: String, colour: Colour, background: Colour, } impl Text { pub fn new() -> Text { Text { pos_x: 0, pos_y: 0, text: String::new(), colour: Colour::Black, background: Colour::White, } } pub fn from( pos_x: isize, pos_y: isize, text: String, colour: Colour, background: Colour, ) -> Text { Text { pos_x, pos_y, text, colour, background, } } pub fn set_text(&mut self, text: String) { self.text = text; } } impl Graphic for Text { fn draw(&self, display: &mut Display) { let x = self.pos_x; let y = self.pos_y; let text = &self.text; let mut index = 0; for character in text.chars() { display.set_pixel(x + index, y, character, self.colour, self.background); index += 1; } } fn get_position(&self) -> (isize, isize) { (self.pos_x, self.pos_y) } fn set_position(&mut self, pos_x: isize, pos_y: isize) { self.pos_x = pos_x; self.pos_y = pos_y; } }