Skip to Content
ExamplesScroll Sync

Scroll Sync

This example demonstrates one of Ansiq’s clearest reactive UI patterns: one signal driving multiple views.

It demonstrates:

  • ScrollView
  • Scrollbar
  • shared scroll state
  • focus-aware scrolling
The state flow inside Scroll Sync
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
Terminal shot of 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

  1. Focus can move between ScrollView and Scrollbar, but the offset is still one shared value
  2. The footer is not extra state; it is another view derived from that offset
  3. This example shows how to avoid the classic “two scroll positions drift apart” bug
  1. ScrollView
  2. Scrollbar
  3. State, Focus, Input
  4. Reactive Graph vs UI Tree
Last updated on