Phase 9: Advanced Layout#
Implement scrollable overflow regions with rendered scroll bars for overflow: scroll and overflow: auto.
Dependencies#
- Overflow clipping must be implemented first
- Event handling infrastructure already exists (mouse events, resize)
Current State#
overflow: scrollandoverflow: autoare parsed but only clip content (once overflow clipping is implemented)- No scroll offset tracking
- No scroll bar rendering
- No mouse wheel event handling for scroll
Requirements#
- Content overflow detection: Track when content dimensions exceed the box's padding area
- Scroll offset tracking: Each scrollable box maintains a
(scroll_x, scroll_y)offset - Scroll bar rendering:
- Vertical scroll bar on the right edge when content overflows vertically
- Horizontal scroll bar on the bottom edge when content overflows horizontally
- Scroll bar track and thumb (proportional to content/viewport ratio)
overflow: scrollalways shows scroll bars;overflow: autoshows only when content overflows
- Scroll bar interaction:
- Mouse wheel events adjust scroll offset
- Click-and-drag on scroll bar thumb
- Click on scroll bar track for page-up/page-down
- Scroll offset applied during rendering: Shift child content by the scroll offset when painting within a scrollable container
- Scroll bar dimensions: Reduce available content width/height by scroll bar thickness (typically 15px)
Files to Modify#
crates/layout/src/lib.rs— Track content overflow, reserve space for scroll barscrates/render/src/lib.rs— Render scroll bars, apply scroll offset to child paintingcrates/browser/src/main.rs— Handle mouse wheel events, update scroll statecrates/platform/src/appkit.rs— Forward scroll wheel events if not already handled
Tests#
overflow: scrollrenders scroll bars even when content fitsoverflow: autorenders scroll bars only when content overflows- Scroll offset correctly shifts rendered content
- Scroll bar thumb size is proportional to content/viewport ratio
- Content is clipped at the scroll container boundary
Acceptance Criteria#
overflow: scrollandoverflow: autoshow functional scroll bars- Mouse wheel scrolling works
- Scroll bar rendering is correct (track + proportional thumb)
- Content shifts correctly with scroll offset
- All tests pass, clippy clean, fmt clean