use denise::{Radius, Role};
use denise_render::Canvas;
use crate::widget::{PaintCtx, Widget};
#[derive(Clone, Copy, Debug)]
pub struct Panel {
pub fill: Option<Role>,
pub border: Option<Role>,
pub border_width: i32,
pub radius: Radius,
}
impl Default for Panel {
fn default() -> Self {
Self {
fill: Some(Role::Base200),
border: Some(Role::Base300),
border_width: 1,
radius: Radius::Box,
}
}
}
impl Panel {
pub const fn filled(role: Role) -> Self {
Self {
fill: Some(role),
border: None,
border_width: 0,
radius: Radius::Box,
}
}
pub const fn with_radius(mut self, radius: Radius) -> Self {
self.radius = radius;
self
}
pub const fn with_border(mut self, role: Role, width: i32) -> Self {
self.border = Some(role);
self.border_width = width;
self
}
}
impl<M: 'static> Widget<M> for Panel {
fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Canvas<'_>) {
let radius = ctx.theme.radius(self.radius);
if let Some(role) = self.fill {
canvas.fill_rounded_rect(ctx.bounds, radius, ctx.theme.color(role));
}
if let Some(role) = self.border
&& self.border_width > 0
{
canvas.stroke_rounded_rect(
ctx.bounds,
radius,
self.border_width,
ctx.theme.color(role),
);
}
}
}