ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ZenitUI::ScrollState Struct Reference

Offset, bounds, velocity and drag anchors for one scroll container. More...

#include <ScrollState.hpp>

Public Member Functions

void clamp ()
 Clamp offset to [0, maxScroll] on both axes.
void reset ()
 Reset offset, bounds and velocity to zero.
void tickInertia (float dt)
 Advance the inertial offset by dt seconds.

Public Attributes

Vec2 offset {0.0f, 0.0f}
Vec2 maxScroll {0.0f, 0.0f}
Vec2 velocity {0.0f, 0.0f}
float dragStartMouseY {0.0f}
float dragStartOffsetY {0.0f}
float dragStartMouseX {0.0f}
float dragStartOffsetX {0.0f}

Static Public Attributes

static constexpr float WHEEL_IMPULSE = 400.0f
static constexpr float DECAY = 0.90f
static constexpr float VELOCITY_MIN = 5.0f

Detailed Description

Offset, bounds, velocity and drag anchors for one scroll container.

The offset is in content space (pixels scrolled). maxScroll is the maximum valid offset, computed by ScrollController::updateMaxScroll from the content size and the viewport size.

Inertia uses an exponential decay tuned for 60 Hz but made frame-rate-independent by raising the decay to dt * 60.

Member Function Documentation

◆ tickInertia()

void ZenitUI::ScrollState::tickInertia ( float dt)
inline

Advance the inertial offset by dt seconds.

Applies the current velocity to offset, then decays the velocity by pow(DECAY, dt * 60) so that behavior is frame-rate-independent. Velocity below VELOCITY_MIN snaps to zero to avoid infinite asymptotic motion. Clamps the result to [0, maxScroll].


The documentation for this struct was generated from the following file: