use crate::{Position2D, SymbolStyles, DEFAULT_BG_U8, DEFAULT_FG_U8};
#[cfg(feature = "serde_support")]
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))]
pub struct Texel {
pub pos: Position2D,
pub symbol: char,
pub styles: SymbolStyles, pub fg: u8,
pub bg: u8,
}
pub type Texels = Vec<Texel>;
impl Texel {
pub fn moved_from(&self, pos: Position2D) -> Self {
let mut result = self.clone();
result.pos -= pos;
result
}
}
pub fn texels_from_str(s: &str, start: Position2D) -> Texels {
let mut result = Vec::with_capacity(s.len());
for (i, c) in s.chars().enumerate() {
result.push(Texel {
symbol: c,
pos: Position2D {
x: start.x + i as i32,
y: start.y,
},
styles: SymbolStyles::new(),
bg: DEFAULT_BG_U8,
fg: DEFAULT_FG_U8,
});
}
result
}
pub fn write_to_texels(s: &str, texels: &mut Texels, start_x: usize) -> bool {
if start_x + s.len() > texels.len() {
return false; }
for (i, c) in s.chars().enumerate() {
texels[start_x + i].symbol = c;
}
true
}