1use super::{Style, Pixel};
2
3#[derive(Clone, PartialEq, Debug, Default)]
4pub struct Pixels<S: Style>(Vec<Pixel<S>>);
5
6impl<S: Style> Pixels<S> {
7 pub fn next(mut self, style: S, s: char) -> Self {
8 self.0.push(Pixel {
9 style,
10 text: Some(s),
11 });
12 self
13 }
14 pub fn string(mut self, style: S, s: &str) -> Self {
15 for c in s.chars() {
16 self.0.push(Pixel {
17 style,
18 text: Some(c),
19 });
20 }
21 self
22 }
23 pub fn get_mut(&mut self, index: usize) -> Option<&mut Pixel<S>> {
24 self.0.get_mut(index)
25 }
26 pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Pixel<S>> + '_ {
27 self.0.iter_mut()
28 }
29 pub fn iter(&self) -> impl Iterator<Item = &Pixel<S>> + '_ {
30 self.0.iter()
31 }
32}
33
34impl<S: Style> From<Vec<Pixel<S>>> for Pixels<S> {
35 fn from(s: Vec<Pixel<S>>) -> Self {
36 Self { 0: s }
37 }
38}
39impl<S: Style> From<Pixels<S>> for Vec<Pixel<S>> {
40 fn from(s: Pixels<S>) -> Self {
41 s.0
42 }
43}