rosace_render/picture.rs
1use crate::draw_command::DrawCommand;
2
3/// An immutable, ordered list of [`DrawCommand`]s captured during one paint pass.
4///
5/// A `Picture` can be replayed many times (scrolling, animations) without calling
6/// any widget's `paint()` method again — this is the foundation of the cached
7/// repaint model.
8#[derive(Clone)]
9pub struct Picture {
10 pub commands: Vec<DrawCommand>,
11}
12
13/// Accumulates [`DrawCommand`]s during the paint pass, then produces a [`Picture`].
14///
15/// `PaintCtx` holds a `&mut PictureRecorder`. Every drawing helper on `PaintCtx`
16/// pushes a command here instead of writing pixels. After the full tree has been
17/// painted, call [`finish`] to seal the recording.
18pub struct PictureRecorder {
19 commands: Vec<DrawCommand>,
20}
21
22impl PictureRecorder {
23 pub fn new() -> Self {
24 Self { commands: Vec::new() }
25 }
26
27 #[inline]
28 pub fn push(&mut self, cmd: DrawCommand) {
29 self.commands.push(cmd);
30 }
31
32 pub fn finish(self) -> Picture {
33 Picture { commands: self.commands }
34 }
35}
36
37impl Default for PictureRecorder {
38 fn default() -> Self { Self::new() }
39}