anchor_prepend/
anchor_prepend.rs1use virtualizer_adapter::Controller;
2
3fn main() {
4 let mut c = Controller::new(virtualizer::VirtualizerOptions::new_with_key(
11 100,
12 |_| 1,
13 |i| 1000u64 + i as u64,
14 ));
15 c.virtualizer_mut().set_viewport_and_scroll_clamped(10, 50);
16
17 let anchor = c
18 .capture_first_visible_anchor()
19 .expect("visible range must not be empty");
20 println!(
21 "before prepend: off={} anchor={anchor:?}",
22 c.virtualizer().scroll_offset()
23 );
24
25 c.virtualizer_mut().set_count(110);
27 c.virtualizer_mut().set_get_item_key(|i| {
28 if i < 10 {
29 2000u64 + i as u64
30 } else {
31 1000u64 + (i - 10) as u64
32 }
33 });
34 let ok = c.apply_anchor(&anchor, |k| {
39 if (1000..1100).contains(k) {
40 Some((*k as usize - 1000) + 10)
41 } else if (2000..2010).contains(k) {
42 Some(*k as usize - 2000)
43 } else {
44 None
45 }
46 });
47
48 println!(
49 "after prepend: ok={ok} off={}",
50 c.virtualizer().scroll_offset()
51 );
52}