cadmus_core/view/
filler.rs1use super::{Bus, Event, Hub, Id, RenderQueue, View, ID_FEEDER};
2use crate::color::Color;
3use crate::context::Context;
4use crate::font::Fonts;
5use crate::framebuffer::Framebuffer;
6use crate::geom::Rectangle;
7
8pub struct Filler {
9 id: Id,
10 pub rect: Rectangle,
11 children: Vec<Box<dyn View>>,
12 color: Color,
13}
14
15impl Filler {
16 pub fn new(rect: Rectangle, color: Color) -> Filler {
17 Filler {
18 id: ID_FEEDER.next(),
19 rect,
20 children: Vec::new(),
21 color,
22 }
23 }
24}
25
26impl View for Filler {
27 #[cfg_attr(feature = "otel", tracing::instrument(skip(self, _evt, _hub, _bus, _rq, _context), fields(event = ?_evt), ret(level=tracing::Level::TRACE)))]
28 fn handle_event(
29 &mut self,
30 _evt: &Event,
31 _hub: &Hub,
32 _bus: &mut Bus,
33 _rq: &mut RenderQueue,
34 _context: &mut Context,
35 ) -> bool {
36 false
37 }
38
39 #[cfg_attr(feature = "otel", tracing::instrument(skip(self, fb, _fonts), fields(rect = ?rect)))]
40 fn render(&self, fb: &mut dyn Framebuffer, rect: Rectangle, _fonts: &mut Fonts) {
41 if let Some(r) = self.rect.intersection(&rect) {
42 fb.draw_rectangle(&r, self.color);
43 }
44 }
45
46 fn render_rect(&self, rect: &Rectangle) -> Rectangle {
47 rect.intersection(&self.rect).unwrap_or(self.rect)
48 }
49
50 fn rect(&self) -> &Rectangle {
51 &self.rect
52 }
53
54 fn rect_mut(&mut self) -> &mut Rectangle {
55 &mut self.rect
56 }
57
58 fn children(&self) -> &Vec<Box<dyn View>> {
59 &self.children
60 }
61
62 fn children_mut(&mut self) -> &mut Vec<Box<dyn View>> {
63 &mut self.children
64 }
65
66 fn id(&self) -> Id {
67 self.id
68 }
69}