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
//! Contains the Display struct that represents the "display" in which to render
//! The Flyweight "images".
/// Represents a "display" window, in which to render Flyweight images. This
/// "display" window is then printed to the console window at a specified
/// coordinate to render a "frame" of motion in the "display".
pub struct Display {
/// The "display" as represented by a vector of vector of characters. Each
/// vector of characters represents a row.
pub display: Vec<Vec<char>>,
/// Width of the "display", in characters
pub width: usize,
/// Height of the "display", in characters
pub height: usize,
}
impl Display {
/// Create a "display" window in the given Display object, with the given
/// width and height.
///
/// # Parameters
/// - width
///
/// The width of the window, in characters.
/// - height
///
/// The height of the window, in characters.
///
/// # Returns
/// Returns an instance of the Display struct, ready for use.
pub fn new(width: usize, height: usize) -> Display {
let mut row: Vec<char> = Vec::new();
row.resize(width, ' ');
let mut display: Vec<Vec<char>> = Vec::new();
display.resize(height, row);
Display { display, width, height }
}
/// Clear the "display" to a background character, erasing whatever was
/// there before.
///
/// # Parameters
/// - fill_character
///
/// The character with which to fill the display.
pub fn clear_display(&mut self, fill_character: char) {
for row in 0..self.height {
for col in 0..self.width {
self.display[row][col] = fill_character;
}
}
}
}