ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ScrollController.hpp
Go to the documentation of this file.
1#pragma once
2
28
29#include "Common.hpp"
30#include "CoreTypes.hpp"
31#include "ScrollState.hpp"
32
33namespace ZenitUI
34{
35
39
40 class Layout;
41 struct ComputedStyle;
42
51 {
52 ScrollState state;
53 Vec2 contentSize{0, 0};
54 Vec2 appliedOffset{0, 0};
55 int dragAxis{0}; // 0 = none, 1 = vertical, 2 = horizontal
56 Overflow lastOverflowX{Overflow::Visible};
57 Overflow lastOverflowY{Overflow::Visible};
58 bool arrangeInitialized{false};
59 bool scrolling{false};
60 bool overflowInitialized{false};
61
65 bool needsFullArrange(const Layout &node, bool positionChanged) const;
66
70 Rect computeArrangeSpace(const Layout &node, Rect space) const;
71
77
81 void updateMaxScroll(const Layout &node, Rect space);
82
84 void reset();
85
89 void tickInput(Layout &node);
90
94 void drawScrollbar(const Layout &node, float parentOpacity) const;
95
99 Rect verticalThumb(const Layout &node) const;
100
102 Rect horizontalThumb(const Layout &node) const;
103
108
109 private:
111 static bool acceptsInput(Overflow o)
112 {
113 return o == Overflow::Scroll || o == Overflow::Auto;
114 }
116 bool acceptsAnyInput(const ComputedStyle &style) const;
117 };
118
120} // namespace ZenitUI
Centralized standard library includes used throughout ZenitUI.
Small value types shared by the layout, rendering and input layers.
Pure data: the scroll offset, bounds, inertia, and drag anchors.
The base node type: tree, style, layout, input, scroll, render.
Definition Layout.hpp:154
Overflow
CSS overflow modes for one axis.
Definition Style.hpp:579
Dense style: every property has a concrete value.
Definition Style.hpp:1036
Axis-aligned rectangle in screen coordinates.
Definition CoreTypes.hpp:46
Per-node overflow, scrolling and scrollbar state machine.
Definition ScrollController.hpp:51
void resetIfOverflowChanged(const Layout &node)
Detect overflow style changes and reset scroll state if any.
Rect computeArrangeSpace(const Layout &node, Rect space) const
Compute the space to pass to Layout::arrangeInto.
Rect verticalThumb(const Layout &node) const
Compute the vertical scrollbar thumb rectangle in screen space.
void reset()
Reset offset, bounds, velocity and scroll-activity flags.
void drawScrollbar(const Layout &node, float parentOpacity) const
Draw the vertical and/or horizontal scrollbars.
Rect horizontalThumb(const Layout &node) const
Compute the horizontal scrollbar thumb rectangle in screen space.
bool applyOffsetDelta(Layout &node)
Translate the subtree by the delta between state.offset and appliedOffset.
void updateMaxScroll(const Layout &node, Rect space)
Recompute state.maxScroll from contentSize and the node's rect.
void tickInput(Layout &node)
Process pointer and wheel input for this scroll container.
bool needsFullArrange(const Layout &node, bool positionChanged) const
true if a full re-arrange is needed before applying an offset delta.
Offset, bounds, velocity and drag anchors for one scroll container.
Definition ScrollState.hpp:34
2D vector with component-wise arithmetic.
Definition CoreTypes.hpp:25