TGUI  0.8.9
ScrollablePanel.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2020 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
48#ifndef TGUI_REMOVE_DEPRECATED_CODE
50 using ScrollbarPolicy TGUI_DEPRECATED("Use tgui::Scrollbar::Policy instead") = Scrollbar::Policy;
51#endif
52
61 ScrollablePanel(const Layout2d& size = {"100%", "100%"}, Vector2f contentSize = {0, 0});
62
63
68
69
74
75
79 ScrollablePanel& operator= (const ScrollablePanel& other);
80
81
85 ScrollablePanel& operator= (ScrollablePanel&& other);
86
87
98 static ScrollablePanel::Ptr create(Layout2d size = {"100%", "100%"}, Vector2f contentSize = {0, 0});
99
100
109
110
116 const ScrollablePanelRenderer* getSharedRenderer() const;
117
124 const ScrollablePanelRenderer* getRenderer() const;
125
126
132 void setSize(const Layout2d& size) override;
133 using Widget::setSize;
134
135
141
142
149 void add(const Widget::Ptr& widget, const sf::String& widgetName = "") override;
150
151
159 bool remove(const Widget::Ptr& widget) override;
160
161
165 void removeAllWidgets() override;
166
167
178
179
188
189
196
197#ifndef TGUI_REMOVE_DEPRECATED_CODE
202 TGUI_DEPRECATED("Use the ScrollbarWidth renderer property instead") void setScrollbarWidth(float width);
203#endif
204
209 float getScrollbarWidth() const;
210
211
217
218
224
225
231
232
238
239
245 void setVerticalScrollAmount(unsigned int scrollAmount);
246
247
253 unsigned int getVerticalScrollAmount() const;
254
255
261 void setHorizontalScrollAmount(unsigned int scrollAmount);
262
263
269 unsigned int getHorizontalScrollAmount() const;
270
271
277 void setVerticalScrollbarValue(unsigned int value);
278
279
285 unsigned int getVerticalScrollbarValue() const;
286
287
293 void setHorizontalScrollbarValue(unsigned int value);
294
295
301 unsigned int getHorizontalScrollbarValue() const;
302
303
312 void enableSkipDrawingWidgetsOutsideView(bool skipDrawing = true);
313
314
322 Widget::Ptr getWidgetAtPosition(sf::Vector2f pos) const override;
323
324
328 void leftMousePressed(Vector2f pos) override;
329
333 void leftMouseReleased(Vector2f pos) override;
334
338 void mouseMoved(Vector2f pos) override;
339
343 bool mouseWheelScrolled(float delta, Vector2f pos) override;
344
348 void mouseNoLongerOnWidget() override;
349
353 void leftMouseButtonNoLongerDown() override;
354
355
358 // Shows the tool tip when the widget is located below the mouse.
359 // Returns its tool tip or the tool tip from a child widget if the mouse is on top of the widget.
360 // A nullptr is returned when the mouse is not on top of the widget or when the tool tip is empty.
362 Widget::Ptr askToolTip(Vector2f mousePos) override;
363
364
371 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
372
373
375 protected:
376
383 void rendererChanged(const std::string& property) override;
384
385
389 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
390
391
395 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
396
397
399 // Makes a copy of the widget
401 Widget::Ptr clone() const override
402 {
403 return std::make_shared<ScrollablePanel>(*this);
404 }
405
406
408 private:
409
411 // Update the position, size and value of the scrollbars
413 void updateScrollbars();
414
415
417 // Find out what the most right and bottom positions are that are in use by the child widgets
419 void recalculateMostBottomRightPosition();
420
421
423 // Connect the position and size events to recalculate the bottom right position when a widget is updated
425 void connectPositionAndSize(Widget::Ptr widget);
426
427
429 // Disconnect the position and size events that were connected to keep track of widget changes
431 void disconnectAllChildWidgets();
432
433
435 private:
436
437 Vector2f m_contentSize;
438 Vector2f m_mostBottomRightPosition;
439 CopiedSharedPtr<ScrollbarChildWidget> m_verticalScrollbar;
440 CopiedSharedPtr<ScrollbarChildWidget> m_horizontalScrollbar;
441
442 Scrollbar::Policy m_verticalScrollbarPolicy = Scrollbar::Policy::Automatic;
443 Scrollbar::Policy m_horizontalScrollbarPolicy = Scrollbar::Policy::Automatic;
444
445 unsigned int m_verticalScrollAmount = 0;
446 unsigned int m_horizontalScrollAmount = 0;
447
448 bool m_skipDrawingWidgetsOutsideView = false;
449
450 std::map<Widget::Ptr, unsigned int> m_connectedCallbacks;
451
453 };
454
456}
457
459
460#endif // TGUI_SCROLLABLE_PANEL_HPP
Definition: CopiedSharedPtr.hpp:40
Class to store the position or size of a widget.
Definition: Layout.hpp:260
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
void enableSkipDrawingWidgetsOutsideView(bool skipDrawing=true)
Sets whether widgets that are located outside the visible view of the ScrollablePanel still get drawn...
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.
void add(const Widget::Ptr &widget, const sf::String &widgetName="") override
Adds a widget at the end of the layout.
Vector2f getAbsolutePosition() const override
void setContentSize(Vector2f size)
Channges the size available for child widgets.
ScrollablePanel(const Layout2d &size={"100%", "100%"}, Vector2f contentSize={0, 0})
Default constructor.
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.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
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:401
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.
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.
Widget::Ptr getWidgetAtPosition(sf::Vector2f pos) const override
Returns the leaf child widget that is located at the given position.
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
@ Automatic
Show the scrollbar only when needed (default)
Definition: Vector2f.hpp:39
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37