Skip to content

feat(scroll): implement smooth mouse-wheel scrolling & viewport clamping - #14

Merged
rahadbhuiya merged 1 commit into
mainfrom
feat/smooth-scroll-viewport-clamping
Nov 3, 2026
Merged

rahadbhuiya merged 1 commit into
mainfrom
feat/smooth-scroll-viewport-clamping

Conversation

@rahadbhuiya

Copy link
Copy Markdown
Owner

Summary

Resolves #3 by introducing smooth mouse-wheel scrolling with momentum easing, viewport boundary clamping, and total document height calculation.

Key Changes

  • Smooth Scrolling State in Tab: Added target_scroll_y and scroll_velocity to Tab to track inertia and target offsets.
  • Interpolation & Velocity Decay: Implemented apply_wheel_delta(), tick_scroll() (with friction decay and lerp easing toward target), and clamp_scroll() in src/ui/tab.rs.
  • Document Height Calculation: Added LayoutBox::total_document_height() in src/layout/tree.rs to measure the complete rendered page height.
  • Window Event Loop Integration: Handled WindowEvent::MouseWheel (supporting both LineDelta and PixelDelta) in src/main.rs, computing dynamic max_scroll = (document_height - viewport_height).max(0.0).
  • Frame-by-Frame Animation Tick: Wired tick_scroll() into WindowEvent::RedrawRequested to request continuous redraw frames until velocity settles.
  • Navigation Reset: Ensured tab navigation and URL changes reset scroll position and velocity cleanly to 0.
  • Unit Tests: Added 7 comprehensive unit tests in src/ui/tab.rs verifying clamp bounds, lerp progression, settling conditions, velocity decay, and navigation reset.

Closes #3.

…mping (#3)

- Add target_scroll_y and scroll_velocity fields to Tab for smooth momentum scrolling
- Implement apply_wheel_delta, tick_scroll (lerp interpolation & velocity decay), and clamp_scroll
- Add total_document_height on LayoutBox to determine maximum scrollable viewport boundary
- Intercept WindowEvent::MouseWheel handling LineDelta and PixelDelta in main event loop
- Advance scroll easing and request follow-up redraw frames on RedrawRequested
- Add 7 automated unit tests for scroll bounds, lerp settling, and velocity decay
- Update ROADMAP.md tracking and test suite count
- Closes #3
@rahadbhuiya
rahadbhuiya merged commit ba29bdc into main Nov 3, 2026
1 check passed
@rahadbhuiya
rahadbhuiya deleted the feat/smooth-scroll-viewport-clamping branch November 3, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Smooth Mouse-Wheel Scrolling & Viewport Clamping

1 participant