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
use crate::widget::*;

/// A widget to fill/wipe all available space (with painter background) before drawing the content.
///
/// The widget wraps the inner content widget.
///
/// ```rust
/// # use termit::prelude::*;
/// let content = " text "; // or any other Widget
/// let ui = Fill::new(content);
/// ```
///
#[derive(Debug, Default)]
pub struct Fill<W> {
    content: W,
}

impl<W> Fill<W> {
    pub fn new(widget: W) -> Self {
        Fill { content: widget }
    }
    pub fn content(&self) -> &W {
        &self.content
    }
    pub fn content_mut(&mut self) -> &mut W {
        &mut self.content
    }
}
impl<W> AnchorPlacementEnabled for Fill<W> {}
impl<W, M, A: AppEvent> Widget<M, A> for Fill<W>
where
    W: Widget<M, A>,
{
    fn update(
        &mut self,
        model: &mut M,
        input: &Event<A>,
        screen: &mut Screen,
        painter: &Painter,
    ) -> Window {
        if matches!(input, Event::Refresh(_)) {
            painter.fill(screen);
        }

        self.content.update_asserted(model, input, screen, painter);

        painter.scope()
    }
}