A simple CPU rendered GUI IDE experience.
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::iter::{once, repeat};

use dsb::Cell;
use dsb::cell::Style;
use winit::keyboard::{Key, ModifiersState, NamedKey};

use crate::text::TextArea;

pub struct Bar {
    pub text: crate::text::TextArea,
    pub last_action: String,
}

impl Bar {
    pub fn write_to(
        &self,
        color: [u8; 3],
        bg: [u8; 3],
        (into, (w, _)): (&mut [Cell], (usize, usize)),
        oy: usize,
        fname: &str,
        state: &super::State,
        t: &TextArea,
    ) {
        let row = &mut into[oy * w..oy * w + w];
        row.fill(Cell {
            style: Style { color, bg, flags: Style::ITALIC },
            letter: None,
        });
        fn s(s: &str) -> impl Iterator<Item = (char, u8)> {
            s.chars().zip(repeat(0))
        }
        use super::State;
        match state {
            State::Default if super::ctrl() => {
                let x = s("C + { ")
                    .chain(once(('S', Style::BOLD)))
                    .chain(s("ave, "))
                    .chain(once(('Q', Style::BOLD)))
                    .chain(s("uit, "))
                    .chain(once(('V', Style::BOLD)))
                    .chain(s("aste }"));

                x.zip(row).for_each(|((x, z), y)| {
                    *y = Cell {
                        letter: Some(x),
                        style: Style { flags: z, ..y.style },
                        ..*y
                    }
                });
            }
            State::Default => {
                row[1.."gracilaria".len() + 1]
                    .iter_mut()
                    .zip("gracilaria".chars())
                    .for_each(|(x, y)| x.letter = Some(y));
                row[w / 2 - fname.len() / 2
                    ..w / 2 - fname.len() / 2 + fname.len()]
                    .iter_mut()
                    .zip(fname.chars())
                    .for_each(|(x, y)| x.letter = Some(y));
                row.iter_mut()
                    .rev()
                    .zip(self.last_action.chars().rev())
                    .for_each(|(x, y)| x.letter = Some(y));
            }
            State::InputFname(x) => {
                "write to file: "
                    .chars()
                    .zip(repeat(Style::BOLD | Style::ITALIC))
                    .chain(s(&x.rope.to_string()))
                    .zip(row)
                    .for_each(|((x, z), y)| {
                        *y = Cell {
                            letter: Some(x),
                            style: Style { flags: z, ..y.style },
                            ..*y
                        }
                    });
            }
            State::Selection(x) => {
                let [(x1, y1), (x2, y2)] = t.position(x.clone());
                format!("selection from ({x1}, {y1}) to ({x2}, {y2})")
                    .chars()
                    .rev()
                    .zip(row.iter_mut().rev())
                    .for_each(|(x, y)| y.letter = Some(x));
            }
            State::Save => unreachable!(),
            _ => {}
        }
    }
}