/
scrollareawidget.h
191 lines (154 loc) · 5.52 KB
/
scrollareawidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/** @file scrollareawidget.h Scrollable area.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBAPPFW_SCROLLAREAWIDGET_H
#define LIBAPPFW_SCROLLAREAWIDGET_H
#include "../GuiWidget"
namespace de {
/**
* Scrollable area.
*
* Provides a RuleRectangle where child widgets can be placed.
*
* ScrollAreaWidget does not control its own position or size. The user must
* define its rectangle. The content rule rectangle is defined in relation to
* the widget's rectangle.
*
* The user must always define the size of the content area.
*
* ScrollAreaWidget can optionally independently draw a scroll indicator.
* However, the default behavior is that the user must call
* glMakeScrollIndicatorGeometry() to include the indicator geometry as part of
* the derived/owner widget.
*
* @ingroup guiWidgets
*/
class LIBAPPFW_PUBLIC ScrollAreaWidget : public GuiWidget
{
Q_OBJECT
public:
enum Origin {
Top, ///< Scroll position 0 is at the top.
Bottom ///< Scroll position 0 is at the bottom.
};
public:
ScrollAreaWidget(String const &name = "");
void setScrollBarColor(DotPath const &colorId);
void setOrigin(Origin origin);
Origin origin() const;
void setIndicatorUv(Rectanglef const &uv);
void setIndicatorUv(Vector2f const &uvPoint);
void setContentWidth(int width);
void setContentWidth(Rule const &width);
void setContentHeight(int height);
void setContentHeight(Rule const &height);
void setContentSize(Rule const &width, Rule const &height);
void setContentSize(Vector2i const &size);
void setContentSize(Vector2ui const &size);
void modifyContentWidth(int delta);
void modifyContentHeight(int delta);
int contentWidth() const;
int contentHeight() const;
RuleRectangle const &contentRule() const;
ScalarRule &scrollPositionX() const;
ScalarRule &scrollPositionY() const;
Rule const &maximumScrollX() const;
Rule const &maximumScrollY() const;
bool isScrolling() const;
Rectanglei viewport() const;
Vector2i viewportSize() const;
/**
* Returns the current scroll XY position, with 0 being the top/left corner
* and maximumScroll() being the bottom right position.
*/
Vector2i scrollPosition() const;
virtual Vector2i scrollPageSize() const;
/**
* Returns the maximum scroll position. The scrollMaxChanged() signal
* is emitted whenever the maximum changes.
*/
Vector2i maximumScroll() const;
/**
* Scrolls the view to a specified position. Position (0,0) means the top
* left corner is visible at the top left corner of the ScrollAreaWidget.
*
* @param to Scroll position.
* @param span Animation time span.
*/
void scroll(Vector2i const &to, TimeDelta span = 0);
void scrollX(int to, TimeDelta span = 0);
void scrollY(int to, TimeDelta span = 0);
bool isScrollable() const;
/**
* Determines if the history view is at the bottom, showing the latest entry.
*/
bool isAtBottom() const;
/**
* Enables or disables scrolling. By default, scrolling is enabled.
*
* @param enabled @c true to enable scrolling.
*/
void enableScrolling(bool enabled);
/**
* Enables or disables scrolling with Page Up/Down keys.
*
* @param enabled @c true to enable Page Up/Down.
*/
void enablePageKeys(bool enabled);
/**
* Enables or disables the drawing of the scroll indicator.
*
* @param enabled @c true to enable the indicator. The default is @c false.
*/
void enableIndicatorDraw(bool enabled);
void glMakeScrollIndicatorGeometry(DefaultVertexBuf::Builder &verts,
Vector2f const &origin = Vector2f(0, 0));
// Events.
void viewResized() override;
void update() override;
void drawContent() override;
bool handleEvent(Event const &event) override;
public slots:
void scrollToTop(TimeDelta span = 0.3);
/**
* Moves the scroll offset of the widget to the bottom of the content.
*/
void scrollToBottom(TimeDelta span = 0.3);
void scrollToLeft(TimeDelta span = 0.3);
void scrollToRight(TimeDelta span = 0.3);
/**
* Moves the scroll offset to center on the given widget.
*
* @param widget Widget to center on.
* @param span Animation duration.
*/
void scrollToWidget(GuiWidget const &widget, TimeDelta span = 0.3);
/**
* Finds the topmost scroll area that can be scrolled. May return this widget
* if there are no scrollable ancestors.
*
* @return
*/
ScrollAreaWidget &findTopmostScrollable();
protected:
void glInit() override;
void glDeinit() override;
private:
DENG2_PRIVATE(d)
};
} // namespace de
#endif // LIBAPPFW_SCROLLAREAWIDGET_H