FifeGUI 0.3.0
A C++ GUI library designed for games.
scrollarea.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_WIDGETS_SCROLLAREA_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_SCROLLAREA_HPP_
7
8// Standard library includes
9#include <string>
10
11// Platform config include
12#include "fifechan/platform.hpp"
13
14// Project headers (subdirs before local)
15#include "fifechan/listeners/mouselistener.hpp"
16#include "fifechan/widget.hpp"
17
18namespace fcn
19{
29 class FIFEGUI_API ScrollArea : public MouseListener, public Widget
30 {
31 public:
41 enum class ScrollPolicy : uint8_t
42 {
43 ShowAlways = 0,
44 ShowNever,
45 ShowAuto
46 };
47
48 ScrollArea();
49
55 explicit ScrollArea(Widget* content);
56
66 ScrollArea(Widget* content, ScrollPolicy hPolicy, ScrollPolicy vPolicy);
67
68 ~ScrollArea() override;
69
70 ScrollArea(ScrollArea const &) = delete;
71 ScrollArea& operator=(ScrollArea const &) = delete;
72 ScrollArea(ScrollArea&&) = delete;
73 ScrollArea& operator=(ScrollArea&&) = delete;
74
80 void setContent(Widget* widget);
81
87 Widget* getContent() const;
88
95 void setHorizontalScrollPolicy(ScrollPolicy hPolicy);
96
103 ScrollPolicy getHorizontalScrollPolicy() const;
104
111 void setVerticalScrollPolicy(ScrollPolicy vPolicy);
112
119 ScrollPolicy getVerticalScrollPolicy() const;
120
128 void setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy);
129
136 void setVerticalScrollAmount(int vScroll);
137
144 int getVerticalScrollAmount() const;
145
152 void setHorizontalScrollAmount(int hScroll);
153
160 int getHorizontalScrollAmount() const;
161
169 void setScrollAmount(int hScroll, int vScroll);
170
176 int getHorizontalMaxScroll();
177
183 int getVerticalMaxScroll();
184
191 void setScrollbarWidth(int width);
192
199 int getScrollbarWidth() const;
200
208 void setLeftButtonScrollAmount(int amount);
209
217 void setRightButtonScrollAmount(int amount);
218
226 void setUpButtonScrollAmount(int amount);
227
235 void setDownButtonScrollAmount(int amount);
236
244 int getLeftButtonScrollAmount() const;
245
253 int getRightButtonScrollAmount() const;
254
262 int getUpButtonScrollAmount() const;
263
271 int getDownButtonScrollAmount() const;
272
279 void setOpaque(bool opaque);
280
287 bool isOpaque() const;
288
289 // Inherited from Container
290
291 void showWidgetPart(Widget* widget, Rectangle area) override;
292
293 Rectangle getChildrenArea() override;
294
301 virtual Widget* getWidgetAt(int x, int y);
302
303 // Inherited from Widget
304
305 void draw(Graphics* graphics) override;
306
307 void logic() override;
308
310 void setWidth(int width) override;
311
313 void setHeight(int height) override;
314
316 void setDimension(Rectangle const & dimension) override;
317
320
321 void resizeToContent(bool recursion = true) override;
322
323 void adjustSize() override;
324
325 void expandContent(bool recursion) override;
326
327 // Inherited from MouseListener
328
329 void mousePressed(MouseEvent& mouseEvent) override;
330
331 void mouseReleased(MouseEvent& mouseEvent) override;
332
333 void mouseDragged(MouseEvent& mouseEvent) override;
334
335 void mouseWheelMovedUp(MouseEvent& mouseEvent) override;
336
337 void mouseWheelMovedDown(MouseEvent& mouseEvent) override;
338
339 void mouseWheelMovedRight(MouseEvent& mouseEvent) override;
340
341 void mouseWheelMovedLeft(MouseEvent& mouseEvent) override;
342
343 protected:
350 virtual void drawBackground(Graphics* graphics);
351
357 virtual void drawUpButton(Graphics* graphics);
358
364 virtual void drawDownButton(Graphics* graphics);
365
371 virtual void drawLeftButton(Graphics* graphics);
372
378 virtual void drawRightButton(Graphics* graphics);
379
385 virtual void drawVBar(Graphics* graphics);
386
392 virtual void drawHBar(Graphics* graphics);
393
399 virtual void drawVMarker(Graphics* graphics);
400
406 virtual void drawHMarker(Graphics* graphics);
407
411 virtual void checkPolicies(); // cppcheck-suppress virtualCallInConstructor
412
418 Rectangle getUpButtonDimension();
419
425 Rectangle getDownButtonDimension();
426
432 Rectangle getLeftButtonDimension();
433
439 Rectangle getRightButtonDimension();
440
446 Rectangle getVerticalBarDimension();
447
453 Rectangle getHorizontalBarDimension();
454
460 Rectangle getVerticalMarkerDimension();
461
467 Rectangle getHorizontalMarkerDimension();
468
472 int mVScroll{0};
473
477 int mHScroll{0};
478
483
487 ScrollPolicy mHPolicy{ScrollPolicy::ShowAuto};
488
492 ScrollPolicy mVPolicy{ScrollPolicy::ShowAuto};
493
497 bool mVBarVisible{false};
498
502 bool mHBarVisible{false};
503
507 bool mUpButtonPressed{false};
508
513
518
523
528
533
538
543
548
553
558
563
568 bool mOpaque{true};
569 };
570} // namespace fcn
571
572#endif // INCLUDE_FIFECHAN_WIDGETS_SCROLLAREA_HPP_
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
Represents a mouse event.
MouseListener(MouseListener const &)=default
Copy constructor.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:22
A scrollable viewport for viewing widgets larger than the visible area.
int mVerticalMarkerDragOffset
Holds the vertical markers drag offset.
int mRightButtonScrollAmount
Holds the right button scroll amount.
int mLeftButtonScrollAmount
Holds the left button scroll amount.
bool mRightButtonPressed
True if the right button is pressed, false otherwise.
int mDownButtonScrollAmount
Holds the down button scroll amount.
ScrollPolicy mHPolicy
Holds the horizontal scroll bar policy.
bool mIsVerticalMarkerDragged
True if the vertical marked is dragged.
bool mOpaque
True if the scroll area should be opaque (that is display its background), false otherwise.
bool mDownButtonPressed
True if the down button is pressed, false otherwise.
ScrollPolicy mVPolicy
Holds the vertical scroll bar policy.
bool mVBarVisible
True if the vertical scroll bar is visible, false otherwise.
bool mHBarVisible
True if the horizontal scroll bar is visible, false otherwise.
int mScrollbarWidth
Holds the width of the scroll bars.
bool mIsHorizontalMarkerDragged
True if the horizontal marked is dragged.
int mVScroll
Holds the vertical scroll amount.
ScrollPolicy
Scroll policies for the horizontal and vertical scrollbar.
bool mUpButtonPressed
True if the up button is pressed, false otherwise.
bool mLeftButtonPressed
True if the left button is pressed, false otherwise.
int mUpButtonScrollAmount
Holds the up button scroll amount.
int mHorizontalMarkerDragOffset
Holds the horizontal markers drag offset.
int mHScroll
Holds the horizontal scroll amount.
Abstract base class defining the common behavior, properties, and lifecycle of all GUI elements.
Definition widget.hpp:56
Widget()
Constructor.
Definition widget.cpp:52
void expandContent()
Expands the child widgets to the size of this widget, calls recursively all childs.
Definition widget.hpp:1597
virtual void resizeToContent(bool recursion=true)
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1580
Used replacement tokens by configure_file():