geng_ui/widgets/
color_box.rs1use super::*;
2
3pub struct ColorBox {
4 pub color: Rgba<f32>,
5 pub size: vec2<f32>,
6}
7
8impl ColorBox {
9 pub fn new(color: Rgba<f32>) -> Self {
10 Self {
11 color,
12 size: vec2::ZERO,
13 }
14 }
15 pub fn divider(color: Rgba<f32>, size: f32) -> Self {
16 Self {
17 color,
18 size: vec2(size, size),
19 }
20 }
21}
22
23impl Widget for ColorBox {
24 fn draw(&mut self, cx: &mut DrawContext) {
25 cx.draw2d.draw2d(
26 cx.framebuffer,
27 &PixelPerfectCamera,
28 &draw2d::Quad::new(cx.position.map(|x| x as f32), self.color),
29 );
30 }
31
32 fn calc_constraints(&mut self, _children: &ConstraintsContext) -> Constraints {
33 Constraints {
34 min_size: self.size.map(|x| x as f64),
35 flex: vec2(0.0, 0.0),
36 }
37 }
38}