ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ScrollController.hpp File Reference

Overflow handling, scrolling input, and scrollbar rendering for a node. More...

#include "Common.hpp"
#include "CoreTypes.hpp"
#include "ScrollState.hpp"

Go to the source code of this file.

Classes

struct  ZenitUI::ScrollController
 Per-node overflow, scrolling and scrollbar state machine. More...

Detailed Description

Overflow handling, scrolling input, and scrollbar rendering for a node.

Every Layout embeds one ScrollController (as scroll_). The controller only does work when the node's style has at least one non-visible overflow axis. Its responsibilities:

  • Track the content size measured by Layout::measure.
  • Grow the arrange space beyond the viewport when content overflows.
  • Translate the subtree by (appliedOffset - state.offset) whenever the offset changes, avoiding a full re-arrange.
  • Translate wheel input into inertial velocity; drag on the scrollbar thumb into direct offset changes.
  • Draw the scrollbars, when Overflow::Scroll or (Overflow::Auto and content overflows).

The division of labor between the controller and Layout is:

  • Layout::measure sets contentSize via scroll_.contentSize.
  • Layout::arrange calls needsFullArrange, computeArrangeSpace, applyOffsetDelta, and updateMaxScroll.
  • Layout::update calls tickInput and resetIfOverflowChanged.
  • Layout::draw calls drawScrollbar.