Scroll Sync
This example demonstrates one of Ansiq’s clearest reactive UI patterns: one signal driving multiple views.
It demonstrates:
ScrollViewScrollbar- shared scroll state
- focus-aware scrolling
1one offset signal stores the current scroll position
2ScrollView reads and updates that offset
3Scrollbar reads and updates the same offset
4the footer text derives from that same state
5runtime keeps all three regions synchronized
Run:
cargo run -p ansiq-examples --example scroll_sync
The real scroll_sync example, showing linked ScrollView and Scrollbar state.
Widgets to study alongside this example
What this example actually teaches
The key lesson is not just how to draw a scrollbar. It is:
- how one reactive value can drive multiple widgets
- why scroll position should be explicit state rather than hidden inside one callback
- why this kind of coupling fits a retained runtime well
You can think of this as the scrolling equivalent of the List selection example.
What to observe at runtime
- Focus can move between
ScrollViewandScrollbar, but the offset is still one shared value - The footer is not extra state; it is another view derived from that offset
- This example shows how to avoid the classic “two scroll positions drift apart” bug
Recommended companion reading
Last updated on