use fission_core::{
hit_test::hit_test_with_scroll, LayoutPoint, LayoutRect, LayoutSize, LayoutSnapshot, Runtime,
};
use fission_ir::{CoreIR, FlexDirection, LayoutOp, NodeId, Op, PaintOp};
use fission_layout::LayoutNodeGeometry;
#[test]
fn test_nested_scroll_hit_test() {
let scroll_a = NodeId::derived(0, &[1]);
let scroll_b = NodeId::derived(0, &[2]);
let button_c = NodeId::derived(0, &[3]);
let mut ir = CoreIR::new();
ir.set_root(scroll_a);
ir.add_node(
scroll_a,
Op::Layout(LayoutOp::Scroll {
direction: FlexDirection::Column,
show_scrollbar: true,
width: Some(100.0),
height: Some(100.0),
min_width: None,
max_width: None,
min_height: None,
max_height: None,
padding: [0.0; 4],
flex_grow: 0.0,
flex_shrink: 0.0,
}),
vec![scroll_b],
);
ir.add_node(
scroll_b,
Op::Layout(LayoutOp::Scroll {
direction: FlexDirection::Column,
show_scrollbar: true,
width: Some(100.0),
height: Some(100.0),
min_width: None,
max_width: None,
min_height: None,
max_height: None,
padding: [0.0; 4],
flex_grow: 0.0,
flex_shrink: 0.0,
}),
vec![button_c],
);
ir.add_node(
button_c,
Op::Paint(PaintOp::DrawRect {
fill: None,
stroke: None,
corner_radius: 0.0,
shadow: None,
}),
vec![],
);
let mut snapshot = LayoutSnapshot::new(LayoutSize::new(800.0, 600.0));
snapshot.nodes.insert(
scroll_a,
LayoutNodeGeometry {
rect: LayoutRect::new(0.0, 0.0, 100.0, 100.0),
content_size: LayoutSize::new(100.0, 1000.0),
},
);
snapshot.nodes.insert(
scroll_b,
LayoutNodeGeometry {
rect: LayoutRect::new(0.0, 150.0, 100.0, 100.0),
content_size: LayoutSize::new(100.0, 1000.0),
},
);
snapshot.nodes.insert(
button_c,
LayoutNodeGeometry {
rect: LayoutRect::new(0.0, 200.0, 100.0, 20.0),
content_size: LayoutSize::new(100.0, 20.0),
},
);
let mut runtime = Runtime::default();
runtime.runtime_state.scroll.set_offset(scroll_a, 120.0);
runtime.runtime_state.scroll.set_offset(scroll_b, 40.0);
let hit = hit_test_with_scroll(
&ir,
&snapshot,
&runtime.runtime_state.scroll,
LayoutPoint::new(50.0, 40.0),
);
assert_eq!(hit, Some(button_c));
}