widget gallery and compositor test bench
src/gallery_widgets.rs (3.4K)
1 //! Gallery-owned lookalikes of containers the toolkit no longer ships: the old Plate
2 //! (an exhibit) and the root plate (the child windows' background), reproducing their
3 //! colour rules, corner rounding, borders and labels on the narrow widget traits
4 //! wrapped in `Adapted<W>`.
5
6 use cce_ui::colors;
7 use cce_ui::scene::layout::Rect;
8 use cce_ui::scene::paint::{PaintCtx, PlateSpec};
9 use cce_ui::widget::*;
10
11 /// Exhibit lookalike of the old cce-ui `Plate`: config plate colour (else page colour)
12 /// at plate opacity, alpha negated under blur, plate corner radius, config border, and the
13 /// adapter's detached control label above it.
14 pub struct Plate {
15 blur: bool,
16 }
17
18 impl Plate {
19 pub fn new(x: f32, y: f32, w: f32, h: f32, blur: bool) -> Adapted<Plate> {
20 let mut plate = Adapted::new(Self { blur });
21 plate.set_rect(x, y, w, h);
22 plate
23 }
24
25 fn plate_color(&self) -> [f32; 4] {
26 let mut c = if let Some(c) = colors::plate_color() {
27 c
28 } else {
29 colors::page_low_color()
30 };
31 c[3] *= cce_ui::layout::plate_opacity();
32 if self.blur && colors::plate_blur() {
33 c[3] = -c[3].abs();
34 }
35 c
36 }
37
38 }
39
40 // The label is the adapter's detached control label, in the strip above the content rect
41 // `paint` fills — the one label convention every control follows.
42 impl cce_ui::widget::Layout for Plate {}
43
44 impl cce_ui::widget::Paint for Plate {
45 fn color(&self) -> [f32; 4] {
46 self.plate_color()
47 }
48
49 fn corner_style(&self, _rect: Rect) -> Option<(f32, (bool, bool, bool, bool))> {
50 let r = cce_ui::layout::plate_corner_radius();
51 let on = r > 0.0;
52 Some((r, (on, on, on, on)))
53 }
54
55 fn solid_border(&self) -> Option<([f32; 4], f32)> {
56 colors::plate_border_color().map(|bc| (bc, colors::plate_border_thickness()))
57 }
58
59 fn paint(&self, rect: Rect, pc: &mut PaintCtx) {
60 // Rounded background over the content rect, only while corners are on and the
61 // colour has alpha.
62 let radius = cce_ui::layout::plate_corner_radius();
63 let c = self.plate_color();
64 if radius > 0.0 && c[3].abs() > 0.001 {
65 pc.rounded_rect(rect, radius, (true, true, true, true), c);
66 }
67 }
68 }
69
70 impl cce_ui::widget::Input for Plate {}
71
72 /// Child-window background: the DE's standard root plate (cce-ui `PlateSpec::window` — the
73 /// root material at its opacity, the window silhouette on all four corners, the standard
74 /// rolled rim), immovable.
75 pub struct RootPlate;
76
77 impl RootPlate {
78 pub fn new(x: f32, y: f32, w: f32, h: f32) -> Adapted<RootPlate> {
79 let mut bp = Adapted::new(Self);
80 bp.set_rect(x, y, w, h);
81 bp
82 }
83 }
84
85 impl cce_ui::widget::Layout for RootPlate {}
86
87 impl cce_ui::widget::Paint for RootPlate {
88 /// The legacy fill read only: the geometry is the plate `paint` emits.
89 fn color(&self) -> [f32; 4] {
90 cce_ui::color::page_low_color()
91 }
92
93 fn corner_style(&self, _rect: Rect) -> Option<(f32, (bool, bool, bool, bool))> {
94 let r = cce_ui::color::root_plate_corner_radius();
95 let on = r > 0.1;
96 Some((r, (on, on, on, on)))
97 }
98
99 fn paint(&self, rect: Rect, pc: &mut PaintCtx) {
100 // The standard root plate (cce-ui PlateSpec::window), placed at this widget's
101 // rect — the child window's origin, so `root_at(rect)` IS `window(w, h)`.
102 pc.plate_spec(&PlateSpec::root_at(rect));
103 }
104 }
105
106 impl cce_ui::widget::Input for RootPlate {}