1use piet::{kurbo::Rect, Color, RenderContext};
2
3use crate::{widget_size::WidgetSizeVars, Renderable};
4
5pub struct PlainBox {
6 pub color: Color,
7 pub size: WidgetSizeVars,
8}
9
10impl PlainBox {
11 pub fn new(color: Color) -> Self {
12 Self {
13 color,
14 size: WidgetSizeVars::new(),
15 }
16 }
17}
18
19impl Renderable for PlainBox {
20 fn render<C: piet::RenderContext>(&self, ctx: &mut C, layout: &cassowary::Solver) {
21 let width = layout.get_value(self.size.main_width);
22 let height = layout.get_value(self.size.main_height);
23 ctx.fill(
24 Rect {
25 x0: 0.0,
26 y0: 0.0,
27 x1: width,
28 y1: height,
29 },
30 &self.color,
31 );
32 }
33
34 fn layout<C: RenderContext>(&self, _: &mut C, solver: &mut cassowary::Solver) {
35 self.add_zero_protrusion_constraints(solver);
36 }
37
38 fn size(&self) -> &WidgetSizeVars {
39 &self.size
40 }
41}