GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
examples/trigger_near_roll_warning.rs (4.1K)
1 //! Deliberately fires the debug-build "near-roll carve lost grouping" warning
2 //! (`near_roll_fallback_reason` in `backend/window_runner.rs`), so the loud
3 //! path can be seen working: a window plate opens the grouping window, a later
4 //! Bevel plate overlaps where the carve will go, and a full-ring recess hugging
5 //! the left roll is then rejected by the occlusion rule — groupable geometry,
6 //! still-open enclosing plate, shaded region in the roll band, dynamic
7 //! rejection. Expect one line on stderr:
8 //!
9 //! plate-carve: near-roll recess (2,110 260x60) lost grouping — a later
10 //! plate overlaps the carve's shaded region; ...
11 //!
12 //! Debug builds only (`cargo run -p cce-ui --example trigger_near_roll_warning`
13 //! inside a Wayland session — a cce-shadow instance works); a release build
14 //! compiles the warning out and prints nothing. Exits by itself after a few
15 //! frames.
16
17 use cce_ui::engine::{Application, EngineState, LogicalPosition, LogicalSize, WindowSettings};
18 use cce_ui::scene::layout::Rect;
19 use cce_ui::scene::paint::{DisplayList, PaintCtx};
20 use cce_ui::widget::{ElementState, KeyEvent, MouseButton, MouseScrollDelta};
21 use wayland_client::QueueHandle;
22
23 struct TriggerApp {
24 ticks: u32,
25 }
26
27 impl Application for TriggerApp {
28 type Message = ();
29
30 fn new(
31 _qh: &QueueHandle<EngineState<Self>>,
32 _sender: calloop::channel::Sender<Self::Message>,
33 ) -> Self {
34 Self { ticks: 0 }
35 }
36
37 fn settings(&self) -> WindowSettings {
38 WindowSettings {
39 title: "near-roll trigger".into(),
40 app_id: "cce-trigger-near-roll".into(),
41 width: 800,
42 height: 600,
43 fullscreen: false,
44 min_size: None,
45 }
46 }
47
48 fn update(&mut self, _msg: (), _needs_rebuild: &mut bool, _exit: &mut bool) {}
49
50 fn tick(&mut self, _dt: f32, needs_rebuild: &mut bool) {
51 // Keep rendering a few frames so the first real present definitely
52 // carried the display list, then leave. (The warning itself prints
53 // once regardless of how many frames run.)
54 self.ticks += 1;
55 *needs_rebuild = true;
56 if self.ticks > 20 {
57 std::process::exit(0);
58 }
59 }
60
61 fn display_list(&mut self, size: LogicalSize, _scale: f64) -> Option<DisplayList> {
62 let mut pc = PaintCtx::new();
63 let (w, h) = (size.width as f32, size.height as f32);
64 let roll = cce_ui::layout::bevel_width();
65
66 // 1. The window plate — opens the carve-grouping window.
67 pc.plate(
68 Rect { x: 0.0, y: 0.0, width: w, height: h },
69 (12.0, 12.0, 12.0, 12.0),
70 [0.13, 0.13, 0.16, 1.0],
71 roll,
72 );
73 // 2. A later plate overlapping where the carve goes: the occlusion
74 // rule must reject grouping (the carve's shading would land beneath
75 // these pixels in the window plate's earlier draw).
76 pc.bevel(
77 Rect { x: 40.0, y: 100.0, width: 200.0, height: 80.0 },
78 (6.0, 6.0, 6.0, 6.0),
79 [0.20, 0.20, 0.25, 1.0],
80 3.0,
81 );
82 // 3. Full-ring untinted recess hugging the left edge: its shaded
83 // region (rect inflated by depth/2 + 2) reaches into the window
84 // plate's roll band, so the fallback is the loud case.
85 pc.recess(
86 Rect { x: 2.0, y: 110.0, width: 260.0, height: 60.0 },
87 (6.0, 6.0, 6.0, 6.0),
88 6.0,
89 );
90 Some(pc.finish())
91 }
92
93 fn display_list_text(&self) -> bool {
94 true
95 }
96
97 fn handle_pointer_move(&mut self, _pos: LogicalPosition, _needs_rebuild: &mut bool) {}
98 fn handle_mouse_input(
99 &mut self,
100 _button: MouseButton,
101 _state: ElementState,
102 _pos: LogicalPosition,
103 _needs_rebuild: &mut bool,
104 ) -> Option<()> {
105 None
106 }
107 fn handle_mouse_wheel(
108 &mut self,
109 _delta: &MouseScrollDelta,
110 _pos: LogicalPosition,
111 _needs_rebuild: &mut bool,
112 ) {
113 }
114 fn handle_key_input(&mut self, _event: &KeyEvent, _needs_rebuild: &mut bool) -> Option<()> {
115 None
116 }
117 }
118
119 fn main() {
120 cce_ui::engine::run::<TriggerApp>();
121 }