1use densa_core::Color;
2use densa_draw::Canvas;
3use densa_ui::{PaintCx, Widget};
4
5use crate::paint::outline;
6
7#[derive(Debug, Default)]
10pub struct Panel {
11 color: Option<Color>,
12 transparent: bool,
13 border: bool,
14}
15
16impl Panel {
17 pub fn new() -> Self {
19 Self::default()
20 }
21
22 pub fn transparent() -> Self {
24 Self {
25 transparent: true,
26 ..Self::default()
27 }
28 }
29
30 #[must_use]
32 pub fn with_color(mut self, color: Color) -> Self {
33 self.color = Some(color);
34 self.transparent = false;
35 self
36 }
37
38 #[must_use]
40 pub fn with_border(mut self) -> Self {
41 self.border = true;
42 self
43 }
44}
45
46impl Widget for Panel {
47 fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>) {
48 if !self.transparent {
49 let color = self.color.unwrap_or(cx.theme().surface);
50 canvas.fill_rect(cx.rect(), color);
51 }
52 if self.border {
53 outline(canvas, cx.rect(), cx.px(1.0).round(), cx.theme().border);
54 }
55 }
56}