use fission_core::{
hit_test::hit_test_with_scroll, LayoutPoint, LayoutRect, LayoutSize, LayoutSnapshot, Runtime,
};
use fission_ir::{CoreIR, FlexDirection, LayoutOp, NodeId, Op};
use fission_layout::LayoutNodeGeometry;
#[test]
fn test_scroll_hit_test_logic() {
let scroll_id = NodeId::derived(0, &[1]);
let column_id = NodeId::derived(0, &[2]);
let button_id = NodeId::derived(0, &[3]);
let mut ir = CoreIR::new();
ir.set_root(scroll_id);
ir.add_node(
scroll_id,
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![column_id],
);
let mut semantics = fission_ir::Semantics::default();
semantics.focusable = true;
ir.add_node(column_id, Op::Semantics(semantics.clone()), vec![]);
ir.add_node(button_id, Op::Semantics(semantics), vec![]);
let mut snapshot = LayoutSnapshot::new(LayoutSize::new(100.0, 100.0));
snapshot.nodes.insert(
scroll_id,
LayoutNodeGeometry {
rect: LayoutRect::new(0.0, 0.0, 100.0, 100.0),
content_size: LayoutSize::new(100.0, 200.0),
},
);
snapshot.nodes.insert(
column_id,
LayoutNodeGeometry {
rect: LayoutRect::new(0.0, 0.0, 100.0, 200.0),
content_size: LayoutSize::new(100.0, 200.0),
},
);
snapshot.nodes.insert(
button_id,
LayoutNodeGeometry {
rect: LayoutRect::new(0.0, 150.0, 100.0, 20.0),
content_size: LayoutSize::new(100.0, 20.0),
},
);
let mut runtime = Runtime::default();
let _hit = hit_test_with_scroll(
&ir,
&snapshot,
&runtime.runtime_state.scroll,
LayoutPoint::new(50.0, 60.0),
);
runtime.runtime_state.scroll.set_offset(scroll_id, 100.0);
let _hit = hit_test_with_scroll(
&ir,
&snapshot,
&runtime.runtime_state.scroll,
LayoutPoint::new(50.0, 60.0),
);
}