use densa_core::Color;
use densa_draw::Canvas;
use densa_ui::{PaintCx, Widget};
use crate::paint::outline;
#[derive(Debug, Default)]
pub struct Panel {
color: Option<Color>,
transparent: bool,
border: bool,
}
impl Panel {
pub fn new() -> Self {
Self::default()
}
pub fn transparent() -> Self {
Self {
transparent: true,
..Self::default()
}
}
#[must_use]
pub fn with_color(mut self, color: Color) -> Self {
self.color = Some(color);
self.transparent = false;
self
}
#[must_use]
pub fn with_border(mut self) -> Self {
self.border = true;
self
}
}
impl Widget for Panel {
fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>) {
if !self.transparent {
let color = self.color.unwrap_or(cx.theme().surface);
canvas.fill_rect(cx.rect(), color);
}
if self.border {
outline(canvas, cx.rect(), cx.px(1.0).round(), cx.theme().border);
}
}
}