Polyphase Game Engine
Loading...
Searching...
No Matches
ScrollContainer.h
Go to the documentation of this file.
1#pragma once
2
4#include "AssetRef.h"
5
6class Quad;
7class Button;
8class Texture;
9
10enum class ScrollSizeMode : uint8_t
11{
12 FitWidth, // Content fills parent width, scrolls vertically
13 FitHeight, // Content fills parent height, scrolls horizontally
14 FitBoth, // Content fills both dimensions
15 None, // Content uses explicit size
16 Count
17};
18
19enum class ScrollbarMode : uint8_t
20{
21 Hidden, // Never show scrollbars
22 Auto, // Show only when needed
23 AlwaysVisible, // Always show
24 Count
25};
26
28{
29public:
30
32
33 virtual void Create() override;
34 virtual void GatherProperties(std::vector<Property>& props) override;
35 virtual void Tick(float deltaTime) override;
36 virtual void PreRender() override;
37
38 // Scroll Position
39 void SetScrollOffset(glm::vec2 offset);
40 glm::vec2 GetScrollOffset() const;
41 void SetScrollOffsetX(float x);
42 void SetScrollOffsetY(float y);
43 void ScrollToTop();
44 void ScrollToBottom();
45 void ScrollToLeft();
46 void ScrollToRight();
47
48 // Size Mode
49 void SetScrollSizeMode(ScrollSizeMode mode);
50 ScrollSizeMode GetScrollSizeMode() const;
51
52 // Scrollbar Configuration
53 void SetHorizontalScrollbarMode(ScrollbarMode mode);
54 ScrollbarMode GetHorizontalScrollbarMode() const;
55 void SetVerticalScrollbarMode(ScrollbarMode mode);
56 ScrollbarMode GetVerticalScrollbarMode() const;
57 void SetScrollbarWidth(float width);
58 float GetScrollbarWidth() const;
59
60 // Scroll Behavior
61 void SetScrollSpeed(float speed);
62 float GetScrollSpeed() const;
63 void SetMomentumEnabled(bool enabled);
64 bool IsMomentumEnabled() const;
65 void SetMomentumFriction(float friction);
66 float GetMomentumFriction() const;
67
68 // Query
69 bool CanScrollHorizontally() const;
70 bool CanScrollVertically() const;
71 glm::vec2 GetContentSize() const;
72 glm::vec2 GetMaxScrollOffset() const;
73 bool IsDragging() const;
74 bool IsScrolling() const;
75
76 // Child Input Priority
77 void SetChildInputPriority(bool priority);
78 bool GetChildInputPriority() const;
79
80 // Content Access
81 Widget* GetContentWidget();
82
83 // Visual Customization - Colors
84 void SetScrollbarColor(glm::vec4 color);
85 glm::vec4 GetScrollbarColor() const;
86 void SetScrollbarHoveredColor(glm::vec4 color);
87 glm::vec4 GetScrollbarHoveredColor() const;
88 void SetScrollbarTrackColor(glm::vec4 color);
89 glm::vec4 GetScrollbarTrackColor() const;
90
91 // Visual Customization - Textures
92 void SetScrollbarTexture(Texture* texture);
93 Texture* GetScrollbarTexture();
94 void SetTrackTexture(Texture* texture);
95 Texture* GetTrackTexture();
96
97 // Scroll Buttons
98 void SetShowScrollButtons(bool show);
99 bool GetShowScrollButtons() const;
100 void SetButtonSize(float size);
101 float GetButtonSize() const;
102 void SetUpButtonTexture(Texture* texture);
103 Texture* GetUpButtonTexture();
104 void SetDownButtonTexture(Texture* texture);
105 Texture* GetDownButtonTexture();
106 void SetLeftButtonTexture(Texture* texture);
107 Texture* GetLeftButtonTexture();
108 void SetRightButtonTexture(Texture* texture);
109 Texture* GetRightButtonTexture();
110 void SetButtonColor(glm::vec4 color);
111 glm::vec4 GetButtonColor() const;
112
113 // Access internal widgets
114 Quad* GetHScrollbar();
115 Quad* GetVScrollbar();
116 Quad* GetHTrack();
117 Quad* GetVTrack();
118 Button* GetUpButton();
119 Button* GetDownButton();
120 Button* GetLeftButton();
121 Button* GetRightButton();
122
123protected:
124
125 static bool HandlePropChange(Datum* datum, uint32_t index, const void* newValue);
126
127 void UpdateScrollbars();
128 void UpdateContentPosition();
129 void UpdateScrollButtons();
130 void ClampScrollOffset();
131 void HandleInput(float deltaTime);
132 void HandleMomentum(float deltaTime);
133 void HandleButtonInput();
134 bool ShouldShowHScrollbar() const;
135 bool ShouldShowVScrollbar() const;
136 bool IsPointerOverChildWidget(float x, float y) const;
137
138 // Scroll State
139 glm::vec2 mScrollOffset = glm::vec2(0.0f);
140 glm::vec2 mScrollVelocity = glm::vec2(0.0f);
141 glm::vec2 mDragStartOffset = glm::vec2(0.0f);
142 glm::vec2 mDragStartMouse = glm::vec2(0.0f);
143 glm::vec2 mLastMousePos = glm::vec2(0.0f);
144
145 // Size & Mode
149
150 // Scroll Behavior
151 float mScrollSpeed = 30.0f; // Pixels per scroll wheel notch
152 float mMomentumFriction = 5.0f; // Deceleration factor
153 bool mMomentumEnabled = true;
154
155 // Visual - Dimensions
156 float mScrollbarWidth = 8.0f;
157 float mButtonSize = 16.0f;
158 bool mShowScrollButtons = false;
159
160 // Visual - Colors
161 glm::vec4 mScrollbarColor = glm::vec4(0.5f, 0.5f, 0.5f, 0.8f);
162 glm::vec4 mScrollbarHoveredColor = glm::vec4(0.7f, 0.7f, 0.7f, 1.0f);
163 glm::vec4 mScrollbarTrackColor = glm::vec4(0.2f, 0.2f, 0.2f, 0.5f);
164 glm::vec4 mButtonColor = glm::vec4(0.4f, 0.4f, 0.4f, 1.0f);
165
166 // Visual - Textures
173
174 // State
175 bool mDragging = false;
176 bool mDraggingHScrollbar = false;
177 bool mDraggingVScrollbar = false;
178 bool mHScrollbarHovered = false;
179 bool mVScrollbarHovered = false;
180
181 // Input Behavior
182 bool mChildInputPriority = false; // If true, children receive input before scroll drag starts
183
184 // Cached content size (updated during PreRender)
185 glm::vec2 mCachedContentSize = glm::vec2(0.0f);
186
187 // Transient child widgets - Scrollbars
188 Quad* mHScrollbarTrack = nullptr;
189 Quad* mHScrollbarGrabber = nullptr;
190 Quad* mVScrollbarTrack = nullptr;
191 Quad* mVScrollbarGrabber = nullptr;
192
193 // Transient child widgets - Buttons
194 Button* mUpButton = nullptr;
195 Button* mDownButton = nullptr;
196 Button* mLeftButton = nullptr;
197 Button* mRightButton = nullptr;
198};
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
ScrollSizeMode
Definition ScrollContainer.h:11
ScrollbarMode
Definition ScrollContainer.h:20
Definition AssetRef.h:18
Definition Button.h:21
Definition Datum.h:164
virtual void Create()
Definition Node.cpp:220
virtual void Tick(float deltaTime)
Definition Node.cpp:558
Definition Quad.h:20
Definition ScrollContainer.h:28
TextureRef mRightButtonTexture
Definition ScrollContainer.h:172
TextureRef mTrackTexture
Definition ScrollContainer.h:168
TextureRef mUpButtonTexture
Definition ScrollContainer.h:169
DECLARE_NODE(ScrollContainer, Widget)
TextureRef mDownButtonTexture
Definition ScrollContainer.h:170
TextureRef mLeftButtonTexture
Definition ScrollContainer.h:171
TextureRef mScrollbarTexture
Definition ScrollContainer.h:167
Definition Texture.h:10
Definition Widget.h:53
static bool HandlePropChange(Datum *datum, uint32_t index, const void *newValue)
Definition Widget.cpp:45
virtual void GatherProperties(std::vector< Property > &outProps) override
Definition Widget.cpp:115
virtual void PreRender()
Definition Widget.cpp:226