FifeGUI 0.2.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#include <string>
9
10#include "fifechan/mouselistener.hpp"
11#include "fifechan/platform.hpp"
12#include "fifechan/widget.hpp"
13
14namespace fcn
15{
25 class FIFEGUI_API ScrollArea : public MouseListener, public Widget
26 {
27 public:
37 enum class ScrollPolicy : uint8_t
38 {
39 ShowAlways = 0,
40 ShowNever,
41 ShowAuto
42 };
43
44 ScrollArea();
45
51 explicit ScrollArea(Widget* content);
52
62 ScrollArea(Widget* content, ScrollPolicy hPolicy, ScrollPolicy vPolicy);
63
64 ~ScrollArea() override;
65
66 ScrollArea(ScrollArea const &) = delete;
67 ScrollArea& operator=(ScrollArea const &) = delete;
68 ScrollArea(ScrollArea&&) = delete;
69 ScrollArea& operator=(ScrollArea&&) = delete;
70
76 void setContent(Widget* widget);
77
83 Widget* getContent() const;
84
91 void setHorizontalScrollPolicy(ScrollPolicy hPolicy);
92
99 ScrollPolicy getHorizontalScrollPolicy() const;
100
107 void setVerticalScrollPolicy(ScrollPolicy vPolicy);
108
115 ScrollPolicy getVerticalScrollPolicy() const;
116
124 void setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy);
125
132 void setVerticalScrollAmount(int vScroll);
133
140 int getVerticalScrollAmount() const;
141
148 void setHorizontalScrollAmount(int hScroll);
149
156 int getHorizontalScrollAmount() const;
157
165 void setScrollAmount(int hScroll, int vScroll);
166
172 int getHorizontalMaxScroll();
173
179 int getVerticalMaxScroll();
180
187 void setScrollbarWidth(int width);
188
195 int getScrollbarWidth() const;
196
204 void setLeftButtonScrollAmount(int amount);
205
213 void setRightButtonScrollAmount(int amount);
214
222 void setUpButtonScrollAmount(int amount);
223
231 void setDownButtonScrollAmount(int amount);
232
240 int getLeftButtonScrollAmount() const;
241
249 int getRightButtonScrollAmount() const;
250
258 int getUpButtonScrollAmount() const;
259
267 int getDownButtonScrollAmount() const;
268
275 void setOpaque(bool opaque);
276
283 bool isOpaque() const;
284
285 // Inherited from Container
286
287 void showWidgetPart(Widget* widget, Rectangle area) override;
288
289 Rectangle getChildrenArea() override;
290
297 virtual Widget* getWidgetAt(int x, int y);
298
299 // Inherited from Widget
300
301 void draw(Graphics* graphics) override;
302
303 void logic() override;
304
306 void setWidth(int width);
307
309 void setHeight(int height);
310
312 void setDimension(Rectangle const & dimension);
313
316
317 void resizeToContent(bool recursion) override;
318
319 void adjustSize() override;
320
321 void expandContent(bool recursion) override;
322
323 // Inherited from MouseListener
324
325 void mousePressed(MouseEvent& mouseEvent) override;
326
327 void mouseReleased(MouseEvent& mouseEvent) override;
328
329 void mouseDragged(MouseEvent& mouseEvent) override;
330
331 void mouseWheelMovedUp(MouseEvent& mouseEvent) override;
332
333 void mouseWheelMovedDown(MouseEvent& mouseEvent) override;
334
335 void mouseWheelMovedRight(MouseEvent& mouseEvent) override;
336
337 void mouseWheelMovedLeft(MouseEvent& mouseEvent) override;
338
339 protected:
346 virtual void drawBackground(Graphics* graphics);
347
353 virtual void drawUpButton(Graphics* graphics);
354
360 virtual void drawDownButton(Graphics* graphics);
361
367 virtual void drawLeftButton(Graphics* graphics);
368
374 virtual void drawRightButton(Graphics* graphics);
375
381 virtual void drawVBar(Graphics* graphics);
382
388 virtual void drawHBar(Graphics* graphics);
389
395 virtual void drawVMarker(Graphics* graphics);
396
402 virtual void drawHMarker(Graphics* graphics);
403
407 virtual void checkPolicies();
408
414 Rectangle getUpButtonDimension();
415
421 Rectangle getDownButtonDimension();
422
428 Rectangle getLeftButtonDimension();
429
435 Rectangle getRightButtonDimension();
436
442 Rectangle getVerticalBarDimension();
443
449 Rectangle getHorizontalBarDimension();
450
456 Rectangle getVerticalMarkerDimension();
457
463 Rectangle getHorizontalMarkerDimension();
464
468 int mVScroll{0};
469
473 int mHScroll{0};
474
479
483 ScrollPolicy mHPolicy{ScrollPolicy::ShowAuto};
484
488 ScrollPolicy mVPolicy{ScrollPolicy::ShowAuto};
489
493 bool mVBarVisible{false};
494
498 bool mHBarVisible{false};
499
503 bool mUpButtonPressed{false};
504
509
514
519
524
529
534
539
544
549
554
559
564 bool mOpaque{true};
565 };
566} // namespace fcn
567
568#endif // INCLUDE_FIFECHAN_WIDGETS_SCROLLAREA_HPP_
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
Represents a mouse event.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20
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:45
Widget()
Constructor.
Definition widget.cpp:36
void expandContent()
Expands the child widgets to the size of this widget, calls recursively all childs.
Definition widget.hpp:1440
void resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1417