TGUI  0.9.5
Loading...
Searching...
No Matches
ScrollablePanel.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_SCROLLABLE_PANEL_HPP
27#define TGUI_SCROLLABLE_PANEL_HPP
28
29#include <TGUI/CopiedSharedPtr.hpp>
30#include <TGUI/Widgets/Panel.hpp>
31#include <TGUI/Widgets/Scrollbar.hpp>
32#include <TGUI/Renderers/ScrollablePanelRenderer.hpp>
33
35
36namespace tgui
37{
41 class TGUI_API ScrollablePanel : public Panel
42 {
43 public:
44
45 typedef std::shared_ptr<ScrollablePanel> Ptr;
46 typedef std::shared_ptr<const ScrollablePanel> ConstPtr;
47
55 ScrollablePanel(const char* typeName = "ScrollablePanel", bool initRenderer = true);
56
57
62
63
68
69
73 ScrollablePanel& operator= (const ScrollablePanel& other);
74
75
79 ScrollablePanel& operator= (ScrollablePanel&& other);
80
81
92 static ScrollablePanel::Ptr create(Layout2d size = {"100%", "100%"}, Vector2f contentSize = {0, 0});
93
94
103
104
110 const ScrollablePanelRenderer* getSharedRenderer() const;
111
118 const ScrollablePanelRenderer* getRenderer() const;
119
120
126 void setSize(const Layout2d& size) override;
127 using Widget::setSize;
128
129
135
136
143 void add(const Widget::Ptr& widget, const String& widgetName = "") override;
144
145
153 bool remove(const Widget::Ptr& widget) override;
154
155
159 void removeAllWidgets() override;
160
161
172
173
182
183
190
191
196 float getScrollbarWidth() const;
197
198
204
205
211
212
218
219
225
226
232 void setVerticalScrollAmount(unsigned int scrollAmount);
233
234
240 unsigned int getVerticalScrollAmount() const;
241
242
248 void setHorizontalScrollAmount(unsigned int scrollAmount);
249
250
256 unsigned int getHorizontalScrollAmount() const;
257
258
264 void setVerticalScrollbarValue(unsigned int value);
265
266
272 unsigned int getVerticalScrollbarValue() const;
273
274
280 void setHorizontalScrollbarValue(unsigned int value);
281
282
288 unsigned int getHorizontalScrollbarValue() const;
289
290
299
300
304 void leftMousePressed(Vector2f pos) override;
305
309 void leftMouseReleased(Vector2f pos) override;
310
314 void mouseMoved(Vector2f pos) override;
315
319 bool mouseWheelScrolled(float delta, Vector2f pos) override;
320
324 void mouseNoLongerOnWidget() override;
325
329 void leftMouseButtonNoLongerDown() override;
330
331
334 // Shows the tool tip when the widget is located below the mouse.
335 // Returns its tool tip or the tool tip from a child widget if the mouse is on top of the widget.
336 // A nullptr is returned when the mouse is not on top of the widget or when the tool tip is empty.
338 Widget::Ptr askToolTip(Vector2f mousePos) override;
339
340
347 void draw(BackendRenderTargetBase& target, RenderStates states) const override;
348
349
351 protected:
352
359 void rendererChanged(const String& property) override;
360
361
365 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
366
367
371 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
372
373
375 // Makes a copy of the widget
377 Widget::Ptr clone() const override
378 {
379 return std::make_shared<ScrollablePanel>(*this);
380 }
381
382
384 private:
385
387 // Update the position, size and value of the scrollbars
389 void updateScrollbars();
390
391
393 // Find out what the most right and bottom positions are that are in use by the child widgets
395 void recalculateMostBottomRightPosition();
396
397
399 // Connect the position and size events to recalculate the bottom right position when a widget is updated
401 void connectPositionAndSize(Widget::Ptr widget);
402
403
405 // Disconnect the position and size events that were connected to keep track of widget changes
407 void disconnectAllChildWidgets();
408
409
411 private:
412
413 Vector2f m_contentSize;
414 Vector2f m_mostBottomRightPosition;
415 CopiedSharedPtr<ScrollbarChildWidget> m_verticalScrollbar;
416 CopiedSharedPtr<ScrollbarChildWidget> m_horizontalScrollbar;
417
418 Scrollbar::Policy m_verticalScrollbarPolicy = Scrollbar::Policy::Automatic;
419 Scrollbar::Policy m_horizontalScrollbarPolicy = Scrollbar::Policy::Automatic;
420
421 unsigned int m_verticalScrollAmount = 0;
422 unsigned int m_horizontalScrollAmount = 0;
423
424 std::map<Widget::Ptr, unsigned int> m_connectedPositionCallbacks;
425 std::map<Widget::Ptr, unsigned int> m_connectedSizeCallbacks;
426
428 };
429
431}
432
434
435#endif // TGUI_SCROLLABLE_PANEL_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Definition CopiedSharedPtr.hpp:40
Class to store the position or size of a widget.
Definition Layout.hpp:262
Group of widgets that has a background color and optional borders.
Definition Panel.hpp:41
Definition ScrollablePanelRenderer.hpp:37
Group of widgets that has a background color and optional borders.
Definition ScrollablePanel.hpp:42
std::shared_ptr< ScrollablePanel > Ptr
Shared widget pointer.
Definition ScrollablePanel.hpp:45
Widget::Ptr getWidgetAtPosition(Vector2f pos) const override
Returns the leaf child widget that is located at the given position.
Vector2f getContentSize() const
Returns the size available for child widgets.
ScrollablePanelRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Vector2f getAbsolutePosition() const override
void setContentSize(Vector2f size)
Channges the size available for child widgets.
void draw(BackendRenderTargetBase &target, RenderStates states) const override
Draw the widget to a render target.
ScrollablePanelRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Scrollbar::Policy getHorizontalScrollbarPolicy() const
Returns when the horizontal scrollbar should be displayed.
void setVerticalScrollAmount(unsigned int scrollAmount)
Changes how much the value changes when scrolling or pressing one of the arrows of the vertical scrol...
void removeAllWidgets() override
Removes all widgets that were added to the container.
void setHorizontalScrollAmount(unsigned int scrollAmount)
Changes how much the value changes when scrolling or pressing one of the arrows of the horizontal scr...
float getScrollbarWidth() const
Returns the width of the scrollbars.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition ScrollablePanel.hpp:377
unsigned int getVerticalScrollAmount() const
Returns how much the value changes when scrolling or pressing one of the arrows of the vertical scrol...
Vector2f getContentOffset() const
Returns the amount of pixels the child widgets have been shifted to be displayed by the scrollable pa...
std::shared_ptr< const ScrollablePanel > ConstPtr
Shared constant widget pointer.
Definition ScrollablePanel.hpp:46
bool remove(const Widget::Ptr &widget) override
Removes a single widget that was added to the container.
void add(const Widget::Ptr &widget, const String &widgetName="") override
Adds a widget at the end of the layout.
ScrollablePanel(const ScrollablePanel &copy)
Copy constructor.
ScrollablePanel(ScrollablePanel &&copy)
Move constructor.
void setVerticalScrollbarValue(unsigned int value)
Changes the thumb position of the vertical scrollbar.
void setHorizontalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the horizontal scrollbar should be displayed.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void setSize(const Layout2d &size) override
Changes the size of the panel.
unsigned int getHorizontalScrollAmount() const
Returns how much the value changes when scrolling or pressing one of the arrows of the horizontal scr...
void setHorizontalScrollbarValue(unsigned int value)
Changes the thumb position of the horizontal scrollbar.
Scrollbar::Policy getVerticalScrollbarPolicy() const
Returns when the vertical scrollbar should be displayed.
static ScrollablePanel::Ptr create(Layout2d size={"100%", "100%"}, Vector2f contentSize={0, 0})
Creates a new scrollable panel widget.
static ScrollablePanel::Ptr copy(ScrollablePanel::ConstPtr panel)
Makes a copy of another scrollbable panel.
unsigned int getVerticalScrollbarValue() const
Returns the thumb position of the vertical scrollbar.
unsigned int getHorizontalScrollbarValue() const
Returns the thumb position of the horizontal scrollbar.
void setVerticalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the vertical scrollbar should be displayed.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
Policy
Defines when the scrollbar shows up.
Definition Scrollbar.hpp:50
Wrapper class to store strings.
Definition String.hpp:79
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition RenderStates.hpp:39