controller_tween/
controller_tween.rs

1use virtualizer_adapter::{Controller, Easing};
2
3fn main() {
4    // Example: TanStack-like controller driving tween scrolling without holding any UI objects.
5    //
6    // An adapter would:
7    // - start a tween (e.g. in response to "scroll to index" command)
8    // - call tick(now_ms) in a frame loop / timer
9    // - apply the returned offset to the real scroll container (if any)
10    // - render using the virtualizer state
11    let mut c = Controller::new(virtualizer::VirtualizerOptions::new(10_000, |_| 1));
12    c.virtualizer_mut().set_viewport_size(20);
13    c.virtualizer_mut().set_scroll_offset(0);
14
15    let target = c.start_tween_to_index(
16        2_000,
17        virtualizer::Align::Center,
18        0,
19        240,
20        Easing::SmoothStep,
21    );
22    println!("target_offset={target}");
23
24    let mut now_ms = 0u64;
25    loop {
26        now_ms += 16;
27        if let Some(off) = c.tick(now_ms) {
28            if now_ms % 80 == 0 {
29                println!(
30                    "t={now_ms} off={off} visible={:?}",
31                    c.virtualizer().visible_range()
32                );
33            }
34        } else {
35            break;
36        }
37    }
38
39    println!(
40        "done: off={} range={:?}",
41        c.virtualizer().scroll_offset(),
42        c.virtualizer().virtual_range()
43    );
44}