pixel_widgets/widget/
dummy.rs

1use crate::draw::Primitive;
2use crate::layout::{Rectangle, Size};
3use crate::node::{GenericNode, IntoNode, Node};
4use crate::style::Stylesheet;
5use crate::widget::Widget;
6
7/// Dummy widget that has a custom widget name
8pub struct Dummy {
9    widget: &'static str,
10}
11
12impl Dummy {
13    /// Construct a new `Dummy` with a widget name
14    pub fn new(widget: &'static str) -> Self {
15        Self { widget }
16    }
17
18    /// Sets the widget name for this dummy
19    pub fn widget(mut self, widget: &'static str) -> Self {
20        self.widget = widget;
21        self
22    }
23}
24
25impl Default for Dummy {
26    fn default() -> Self {
27        Dummy { widget: "" }
28    }
29}
30
31impl<'a, T: 'a> Widget<'a, T> for Dummy {
32    type State = ();
33
34    fn mount(&self) {}
35
36    fn widget(&self) -> &'static str {
37        self.widget
38    }
39
40    fn len(&self) -> usize {
41        0
42    }
43
44    fn visit_children(&mut self, _: &mut dyn FnMut(&mut dyn GenericNode<'a, T>)) {}
45
46    fn size(&self, _: &(), style: &Stylesheet) -> (Size, Size) {
47        (style.width, style.height)
48    }
49
50    fn draw(&mut self, _: &mut (), layout: Rectangle, _: Rectangle, style: &Stylesheet) -> Vec<Primitive<'a>> {
51        style.background.render(layout).into_iter().collect()
52    }
53}
54
55impl<'a, T: 'a> IntoNode<'a, T> for Dummy {
56    fn into_node(self) -> Node<'a, T> {
57        Node::from_widget(self)
58    }
59}