git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

tests/lattice_probe.rs (2.5K)

 1 use cce_ui::scene::layout::Rect;
 2 use cce_ui::scene::paint::{PaintCtx, Prim};
 3 
 4 #[test]
 5 fn lattice_survives_tessellation_inside_a_clip() {
 6     let mut pc = PaintCtx::new();
 7     let clip = Rect { x: 40.0, y: 40.0, width: 600.0, height: 300.0 };
 8     pc.clip(clip, |pc| {
 9         pc.lattice(clip, (85.0, 43.0), (60.0, 60.0), (71.0, 31.0), 6.0, 6.0);
10         pc.groove((40.0, 100.0), (640.0, 100.0), 2.0, 2.0, clip);
11     });
12     let dl = pc.finish();
13     let kinds: Vec<String> = dl.items.iter().map(|i| format!("{:?}", std::mem::discriminant(&i.prim))).collect();
14     let n_lattice = dl.items.iter().filter(|i| matches!(i.prim, Prim::Lattice { .. })).count();
15     assert_eq!(n_lattice, 1, "display list: {kinds:?}");
16     let (verts, batches, _, _) = cce_ui::backend::window_runner::tessellate_display_list(&dl, 1280.0, 720.0, 2.0);
17     let modes: Vec<f32> = batches.iter().filter_map(|b| b.plate.as_ref().map(|p| p.mode)).collect();
18     eprintln!("verts={} batches={} plate modes={modes:?}", verts.len(), batches.len());
19     assert!(modes.contains(&13.0), "no lattice batch; modes={modes:?}");
20 }
21 
22 #[test]
23 fn graph_emits_grout_and_axes() {
24     use cce_ui::widget::GraphController;
25     let mut g = cce_ui::widget::Graph::new();
26     g.set_grid_sizes(71.0, 31.0);
27     g.set_skipped_sizes(12.0, 14.0);
28     g.set_grid_origin(50.0, 50.0);
29     g.set_show_network_grid(true);
30     // The designer hard-codes a uniform background; that must not hide the relief.
31     g.set_uniform_background(true);
32     let mut pc = PaintCtx::new();
33     let rect = Rect { x: 40.0, y: 40.0, width: 600.0, height: 300.0 };
34     g.paint_grid(rect, &mut pc);
35     let dl = pc.finish();
36     let n_grout = dl.items.iter().filter(|i| matches!(i.prim, Prim::Grout { .. })).count();
37     let n_quad = dl.items.iter().filter(|i| matches!(i.prim, Prim::Quad { .. })).count();
38     assert_eq!((n_grout, n_quad), (1, 2), "one grout draw + two axis lines");
39 }
40 
41 #[test]
42 fn grout_tessellates_to_a_mode_15_batch_in_its_colour() {
43     let mut pc = PaintCtx::new();
44     let clip = Rect { x: 40.0, y: 40.0, width: 600.0, height: 300.0 };
45     pc.clip(clip, |pc| pc.grout(clip, (85.0, 43.0), (60.0, 60.0), (71.0, 31.0), 15.5, [0.5, 0.5, 0.5, 0.1]));
46     let dl = pc.finish();
47     let (verts, batches, _, _) = cce_ui::backend::window_runner::tessellate_display_list(&dl, 1280.0, 720.0, 2.0);
48     let modes: Vec<f32> = batches.iter().filter_map(|b| b.plate.as_ref().map(|p| p.mode)).collect();
49     assert_eq!(modes, vec![15.0]);
50     assert_eq!(verts.len(), 6);
51     assert!(verts.iter().all(|v| (v.color[3] - 0.1).abs() < 1e-6), "cover quad carries the grout colour");
52 }