GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
examples/carve_union_demo.rs (3.5K)
1 //! A visual check of [`cce_ui::scene::paint::Prim::CarveUnion`] against the
2 //! per-box overlays it replaces. Left column: an L and a plus drawn as ONE
3 //! union carve (recess above, boss below). Right column: the same L and plus
4 //! drawn as one recess/boss per box — the crossing walls and stacked shading
5 //! the union exists to remove. Run inside a Wayland session (a cce-shadow
6 //! instance works): `cargo run --release -p cce-ui --example carve_union_demo`.
7
8 use cce_ui::engine::{Application, EngineState, LogicalPosition, LogicalSize, WindowSettings};
9 use cce_ui::scene::layout::Rect;
10 use cce_ui::scene::paint::{DisplayList, PaintCtx};
11 use cce_ui::widget::{ElementState, KeyEvent, MouseButton, MouseScrollDelta};
12 use wayland_client::QueueHandle;
13
14 struct DemoApp;
15
16 fn l_shape(x: f32, y: f32) -> Vec<(Rect, (f32, f32, f32, f32))> {
17 let r = (8.0, 8.0, 8.0, 8.0);
18 vec![
19 (Rect { x, y, width: 260.0, height: 70.0 }, r),
20 (Rect { x, y, width: 70.0, height: 200.0 }, r),
21 ]
22 }
23
24 fn plus_shape(x: f32, y: f32) -> Vec<(Rect, (f32, f32, f32, f32))> {
25 let r = (10.0, 10.0, 10.0, 10.0);
26 vec![
27 (Rect { x, y: y + 70.0, width: 220.0, height: 60.0 }, r),
28 (Rect { x: x + 80.0, y, width: 60.0, height: 200.0 }, r),
29 ]
30 }
31
32 impl Application for DemoApp {
33 type Message = ();
34
35 fn new(_qh: &QueueHandle<EngineState<Self>>, _sender: calloop::channel::Sender<()>) -> Self {
36 Self
37 }
38
39 fn settings(&self) -> WindowSettings {
40 WindowSettings {
41 title: "carve union demo".into(),
42 app_id: "cce-carve-union-demo".into(),
43 // CCE_DEMO_W / CCE_DEMO_H override the size — handy when the
44 // window doubles as a snap/tiling probe in a shadow session.
45 width: std::env::var("CCE_DEMO_W").ok().and_then(|v| v.parse().ok()).unwrap_or(760),
46 height: std::env::var("CCE_DEMO_H").ok().and_then(|v| v.parse().ok()).unwrap_or(560),
47 fullscreen: false,
48 min_size: None,
49 }
50 }
51
52 fn update(&mut self, _msg: (), _needs_rebuild: &mut bool, _exit: &mut bool) {}
53
54 fn tick(&mut self, _dt: f32, _needs_rebuild: &mut bool) {}
55
56 fn display_list(&mut self, size: LogicalSize, _scale: f64) -> Option<DisplayList> {
57 let mut pc = PaintCtx::new();
58 let (w, h) = (size.width as f32, size.height as f32);
59 pc.plate(
60 Rect { x: 0.0, y: 0.0, width: w, height: h },
61 (12.0, 12.0, 12.0, 12.0),
62 [0.42, 0.44, 0.50, 1.0],
63 cce_ui::layout::bevel_width(),
64 );
65 let wall = 10.0;
66 // Left column: unions.
67 pc.carve_union(l_shape(40.0, 40.0), wall, false);
68 pc.carve_union(plus_shape(60.0, 300.0), wall, true);
69 // Right column: one overlay per box — the look being replaced.
70 for (r, radii) in l_shape(420.0, 40.0) {
71 pc.recess(r, radii, wall);
72 }
73 for (r, radii) in plus_shape(440.0, 300.0) {
74 pc.boss(r, radii, wall);
75 }
76 Some(pc.finish())
77 }
78
79 fn display_list_text(&self) -> bool {
80 true
81 }
82
83 fn handle_pointer_move(&mut self, _pos: LogicalPosition, _needs_rebuild: &mut bool) {}
84 fn handle_mouse_input(&mut self, _b: MouseButton, _s: ElementState, _p: LogicalPosition, _r: &mut bool) -> Option<()> {
85 None
86 }
87 fn handle_mouse_wheel(&mut self, _d: &MouseScrollDelta, _p: LogicalPosition, _r: &mut bool) {}
88 fn handle_key_input(&mut self, _e: &KeyEvent, _r: &mut bool) -> Option<()> {
89 None
90 }
91 }
92
93 fn main() {
94 cce_ui::engine::run::<DemoApp>();
95 }