use std::collections::HashMap;
pub enum TextAlign {
Left,
Center,
Right,
AutoFit, }
pub struct TextItem {
pub content: String,
pub position: (usize, usize),
pub size: usize,
pub color: u32,
pub align: TextAlign, }
impl super::Window {
pub fn show_text(
&mut self,
id: &str,
content: &str,
position: (usize, usize),
size: usize,
color: u32,
align: TextAlign, ) {
self.texts.insert(id.to_string(), TextItem {
content: content.to_string(),
position,
size,
color,
align,
});
}
pub fn update_text(&mut self, id: &str, content: &str) {
if let Some(text_item) = self.texts.get_mut(id) {
text_item.content = content.to_string();
}
}
pub fn remove_text(&mut self, id: &str) {
self.texts.remove(id);
}
}
pub fn get_font_map() -> HashMap<char, [[u8; 5]; 5]> {
let mut map = HashMap::new();
map.insert('A', [
[0,1,1,1,0],
[1,0,0,0,1],
[1,1,1,1,1],
[1,0,0,0,1],
[1,0,0,0,1],
]);
map.insert('B', [
[1,1,1,1,0],
[1,0,0,0,1],
[1,1,1,1,0],
[1,0,0,0,1],
[1,1,1,1,0],
]);
map.insert('C', [
[0,1,1,1,1],
[1,0,0,0,0],
[1,0,0,0,0],
[1,0,0,0,0],
[0,1,1,1,1],
]);
map.insert('D', [
[1,1,1,0,0],
[1,0,0,1,0],
[1,0,0,0,1],
[1,0,0,1,0],
[1,1,1,0,0],
]);
map.insert('E', [
[1,1,1,1,1],
[1,0,0,0,0],
[1,1,1,1,0],
[1,0,0,0,0],
[1,1,1,1,1],
]);
map.insert('F', [
[1,1,1,1,1],
[1,0,0,0,0],
[1,1,1,1,0],
[1,0,0,0,0],
[1,0,0,0,0],
]);
map.insert('G', [
[0,1,1,1,1],
[1,0,0,0,0],
[1,0,1,1,1],
[1,0,0,0,1],
[0,1,1,1,1],
]);
map.insert('H', [
[1,0,0,0,1],
[1,0,0,0,1],
[1,1,1,1,1],
[1,0,0,0,1],
[1,0,0,0,1],
]);
map.insert('I', [
[1,1,1,1,1],
[0,0,1,0,0],
[0,0,1,0,0],
[0,0,1,0,0],
[1,1,1,1,1],
]);
map.insert('J', [
[0,0,0,1,1],
[0,0,0,0,1],
[0,0,0,0,1],
[1,0,0,0,1],
[0,1,1,1,0],
]);
map.insert('K', [
[1,0,0,0,1],
[1,0,0,1,0],
[1,1,1,0,0],
[1,0,0,1,0],
[1,0,0,0,1],
]);
map.insert('L', [
[1,0,0,0,0],
[1,0,0,0,0],
[1,0,0,0,0],
[1,0,0,0,0],
[1,1,1,1,1],
]);
map.insert('M', [
[1,0,0,0,1],
[1,1,0,1,1],
[1,0,1,0,1],
[1,0,0,0,1],
[1,0,0,0,1],
]);
map.insert('N', [
[1,0,0,0,1],
[1,1,0,0,1],
[1,0,1,0,1],
[1,0,0,1,1],
[1,0,0,0,1],
]);
map.insert('O', [
[0,1,1,1,0],
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,0,0,1],
[0,1,1,1,0],
]);
map.insert('P', [
[1,1,1,1,0],
[1,0,0,0,1],
[1,1,1,1,0],
[1,0,0,0,0],
[1,0,0,0,0],
]);
map.insert('Q', [
[0,1,1,1,0],
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,0,1,0],
[0,1,1,0,1],
]);
map.insert('R', [
[1,1,1,1,0],
[1,0,0,0,1],
[1,1,1,1,0],
[1,0,0,1,0],
[1,0,0,0,1],
]);
map.insert('S', [
[0,1,1,1,1],
[1,0,0,0,0],
[0,1,1,1,0],
[0,0,0,0,1],
[1,1,1,1,0],
]);
map.insert('T', [
[1,1,1,1,1],
[0,0,1,0,0],
[0,0,1,0,0],
[0,0,1,0,0],
[0,0,1,0,0],
]);
map.insert('U', [
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,0,0,1],
[0,1,1,1,0],
]);
map.insert('V', [
[1,0,0,0,1],
[1,0,0,0,1],
[0,1,0,1,0],
[0,1,0,1,0],
[0,0,1,0,0],
]);
map.insert('W', [
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,1,0,1],
[1,1,0,1,1],
[1,0,0,0,1],
]);
map.insert('X', [
[1,0,0,0,1],
[0,1,0,1,0],
[0,0,1,0,0],
[0,1,0,1,0],
[1,0,0,0,1],
]);
map.insert('Y', [
[1,0,0,0,1],
[0,1,0,1,0],
[0,0,1,0,0],
[0,0,1,0,0],
[0,0,1,0,0],
]);
map.insert('Z', [
[1,1,1,1,1],
[0,0,0,1,0],
[0,0,1,0,0],
[0,1,0,0,0],
[1,1,1,1,1],
]);
map.insert('0', [
[0,1,1,1,0],
[1,0,0,0,1],
[1,0,0,1,1],
[1,0,1,0,1],
[0,1,1,1,0],
]);
map.insert('1', [
[0,0,1,0,0],
[0,1,1,0,0],
[1,0,1,0,0],
[0,0,1,0,0],
[1,1,1,1,0],
]);
map.insert('2', [
[0,1,1,1,0],
[1,0,0,0,1],
[0,0,0,1,0],
[0,0,1,0,0],
[1,1,1,1,1],
]);
map.insert('3', [
[1,1,1,1,0],
[0,0,0,0,1],
[0,0,1,1,0],
[0,0,0,0,1],
[1,1,1,1,0],
]);
map.insert('4', [
[0,0,1,1,0],
[0,1,0,1,0],
[1,0,0,1,0],
[1,1,1,1,1],
[0,0,0,1,0],
]);
map.insert('5', [
[1,1,1,1,1],
[1,0,0,0,0],
[1,1,1,1,0],
[0,0,0,0,1],
[1,1,1,1,0],
]);
map.insert('6', [
[0,1,1,1,0],
[1,0,0,0,0],
[1,1,1,1,0],
[1,0,0,0,1],
[0,1,1,1,0],
]);
map.insert('7', [
[1,1,1,1,1],
[0,0,0,0,1],
[0,0,0,1,0],
[0,0,1,0,0],
[0,0,1,0,0],
]);
map.insert('8', [
[0,1,1,1,0],
[1,0,0,0,1],
[0,1,1,1,0],
[1,0,0,0,1],
[0,1,1,1,0],
]);
map.insert('9', [
[0,1,1,1,0],
[1,0,0,0,1],
[0,1,1,1,1],
[0,0,0,0,1],
[0,1,1,1,0],
]);
map.insert(' ', [
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
]);
map.insert('.', [
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,1,0,0],
[0,0,1,0,0],
]);
map.insert(',', [
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,1,0,0],
[0,1,0,0,0],
]);
map.insert('!', [
[0,0,1,0,0],
[0,0,1,0,0],
[0,0,1,0,0],
[0,0,0,0,0],
[0,0,1,0,0],
]);
map.insert('?', [
[0,1,1,1,0],
[1,0,0,0,1],
[0,0,0,1,0],
[0,0,0,0,0],
[0,0,1,0,0],
]);
map
}