#time #velocity

nightly libscroll

Scrollview event handling library

12 releases

0.2.4 Apr 27, 2020
0.2.3 Apr 27, 2020
0.1.6 Feb 13, 2020
0.1.4 Jan 27, 2020
0.1.0 Dec 30, 2019
Download history 5/week @ 2023-06-12 28/week @ 2023-06-19 23/week @ 2023-06-26 14/week @ 2023-07-03 6/week @ 2023-07-10 9/week @ 2023-07-17 9/week @ 2023-07-24 5/week @ 2023-07-31 8/week @ 2023-08-07 22/week @ 2023-08-14 4/week @ 2023-08-21 16/week @ 2023-08-28 34/week @ 2023-09-04 7/week @ 2023-09-11 6/week @ 2023-09-18 11/week @ 2023-09-25

58 downloads per month
Used in libscroll-re

MIT license

54KB
909 lines

libscroll [WIP]

A drop-in solution to add smooth, responsive, scrolling to any view. Takes in individual input events, outputs a simple pan amount.

Main library interface is implemented in src/lib.rs

Usage:

  1. Allocate a scrollview with Scrollview::new(), the returned scrollview is the object to which all following directions are applied (through method calls)
  2. Use set_geometry with the size of both the content of the scrollview and the size of the viewport at the current time
  3. Use set_avg_frametime based on current FPS or some other metric to allow position prediction. If this information isn't available, a safe default is 0ms, but this will introduce additional perceptible lag
  4. If render and event loop are separate, split them here. Place the scrollview in an Arc<Mutex<>> to ensure atomic access. Note: scrollviews may be made atomic and internally mutable in the future. This change should not alter backwards compatibility, but should improve usability for this use case

Within event loop:

  1. Take any outstanding events from platform driver/provider (SDL, Libinput, Wayland event provider) and use push_event() to add them to the internal queue.
  2. Loop back to 1

Within render loop:

  1. Call set_next_frame_predict() to set approximately how long it will be from now until content is rendered to screen, or 0 if unsure (at cost of additional latency)
  2. Call step_frame() to both account for any newly emplaced events, and to advance any ongoing animations by one tick
  3. If animating() is true, use either get_position_absolute() or get_position_relative() to see where to move the viewport, or by how much. These calls are idempotent and non-mutating. Call them whenever is convenient after step_frame()

That's it! Everything else is handled behind the scenes

Dependencies

~2MB
~30K SLoC