StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use pathfinder_geometry::vector::vec2f; |
| 2 | |
| 3 | use crate::rendering; |
| 4 | |
| 5 | use super::*; |
| 6 | |
| 7 | #[test] |
| 8 | fn test_hit_rect_recording() { |
| 9 | let mut scene = Scene::new(1., rendering::Config::default()); |
| 10 | assert_eq!(ZIndex::new(0), scene.z_index()); |
| 11 | |
| 12 | scene.draw_rect_with_hit_recording(RectF::new(vec2f(0., 0.), vec2f(100., 100.))); |
| 13 | assert_eq!(ZIndex::new(0), scene.z_index()); |
| 14 | assert!(!scene.is_covered(Point::new(10., 10., ZIndex::new(0)))); |
| 15 | |
| 16 | scene.start_layer(ClipBounds::ActiveLayer); |
| 17 | scene.draw_rect_with_hit_recording(RectF::new(vec2f(50., 50.), vec2f(100., 100.))); |
| 18 | assert_eq!(ZIndex::new(1), scene.z_index()); |
| 19 | assert!(!scene.is_covered(Point::new(10., 10., ZIndex::new(0)))); |
| 20 | assert!(scene.is_covered(Point::new(60., 60., ZIndex::new(0)))); |
| 21 | |
| 22 | scene.start_layer(ClipBounds::ActiveLayer); |
| 23 | scene.draw_rect_with_hit_recording(RectF::new(vec2f(0., 0.), vec2f(100., 100.))); |
| 24 | assert_eq!(ZIndex::new(2), scene.z_index()); |
| 25 | assert!(scene.is_covered(Point::new(10., 10., ZIndex::new(0)))); |
| 26 | assert!(scene.is_covered(Point::new(60., 60., ZIndex::new(1)))); |
| 27 | } |
| 28 | |
| 29 | #[test] |
| 30 | fn test_nested_clip_bounds_with_intersection() { |
| 31 | let mut scene = Scene::new(1., rendering::Config::default()); |
| 32 | |
| 33 | let bounds1 = RectF::new(Vector2F::zero(), Vector2F::new(10., 10.)); |
| 34 | scene.start_layer(ClipBounds::BoundedBy(bounds1)); |
| 35 | |
| 36 | let bounds2 = RectF::new(Vector2F::new(5., 5.), Vector2F::new(10., 10.)); |
| 37 | scene.start_layer(ClipBounds::BoundedByActiveLayerAnd(bounds2)); |
| 38 | |
| 39 | assert_eq!( |
| 40 | scene.active_layer().clip_bounds, |
| 41 | Some(RectF::new(Vector2F::new(5., 5.), Vector2F::new(5., 5.))) |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | #[test] |
| 46 | fn test_nested_clip_bounds_with_no_intersection() { |
| 47 | let mut scene = Scene::new(1., rendering::Config::default()); |
| 48 | |
| 49 | let bounds1 = RectF::new(Vector2F::zero(), Vector2F::new(10., 10.)); |
| 50 | scene.start_layer(ClipBounds::BoundedBy(bounds1)); |
| 51 | |
| 52 | let bounds2 = RectF::new(Vector2F::new(100., 100.), Vector2F::new(10., 10.)); |
| 53 | scene.start_layer(ClipBounds::BoundedByActiveLayerAnd(bounds2)); |
| 54 | |
| 55 | // We should have explicit bounds for this layer. (None represents a lack |
| 56 | // of clipping, not clipping they layer down to nothingness.) |
| 57 | assert!(scene.active_layer().clip_bounds.is_some()); |
| 58 | // The clip bounds should have an area of zero. |
| 59 | assert!(scene.active_layer().clip_bounds.unwrap().is_empty()); |
| 60 | } |
| 61 | |
| 62 | #[test] |
| 63 | fn test_click_through_layer_does_not_cover_lower_layers() { |
| 64 | let mut scene = Scene::new(1., rendering::Config::default()); |
| 65 | |
| 66 | scene.start_layer(ClipBounds::ActiveLayer); |
| 67 | scene.set_active_layer_click_through(); |
| 68 | scene.draw_rect_with_hit_recording(RectF::new(vec2f(0., 0.), vec2f(100., 100.))); |
| 69 | |
| 70 | assert!(!scene.is_covered(Point::new(10., 10., ZIndex::new(0)))); |
| 71 | } |
| 72 |