TGUI  0.8-dev
ScrollablePanel.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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/Widgets/Panel.hpp>
30 #include <TGUI/Widgets/Scrollbar.hpp>
31 #include <TGUI/Renderers/ScrollablePanelRenderer.hpp>
32 
34 
35 namespace tgui
36 {
40  class TGUI_API ScrollablePanel : public Panel
41  {
42  public:
43 
44  typedef std::shared_ptr<ScrollablePanel> Ptr;
45  typedef std::shared_ptr<const ScrollablePanel> ConstPtr;
46 
47 
56  ScrollablePanel(const Layout2d& size = {"100%", "100%"}, sf::Vector2f contentSize = {0, 0});
57 
58 
69  static ScrollablePanel::Ptr create(Layout2d size = {"100%", "100%"}, sf::Vector2f contentSize = {0, 0});
70 
71 
80 
81 
86  ScrollablePanelRenderer* getSharedRenderer();
87  const ScrollablePanelRenderer* getSharedRenderer() const;
88 
94  ScrollablePanelRenderer* getRenderer();
95  const ScrollablePanelRenderer* getRenderer() const;
96 
97 
103  void setSize(const Layout2d& size) override;
104  using Widget::setSize;
105 
106 
113  void add(const tgui::Widget::Ptr& widget, const sf::String& widgetName = "") override;
114 
115 
123  bool remove(const Widget::Ptr& widget) override;
124 
125 
129  void removeAllWidgets() override;
130 
131 
141  void setContentSize(sf::Vector2f size);
142 
143 
151  sf::Vector2f getContentSize() const;
152 
153 
159  sf::Vector2f getContentOffset() const;
160 
161 
165  void leftMousePressed(sf::Vector2f pos) override;
166 
170  void leftMouseReleased(sf::Vector2f pos) override;
171 
175  void mouseMoved(sf::Vector2f pos) override;
176 
180  void mouseWheelScrolled(float delta, sf::Vector2f pos) override;
181 
185  void mouseNoLongerOnWidget() override;
186 
190  void mouseNoLongerDown() override;
191 
192 
199  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
200 
201 
203  protected:
204 
211  void rendererChanged(const std::string& property) override;
212 
213 
215  // Makes a copy of the widget
217  Widget::Ptr clone() const override
218  {
219  return std::make_shared<ScrollablePanel>(*this);
220  }
221 
222 
224  private:
225 
227  // Update the position, size and value of the scrollbars
229  void updateScrollbars();
230 
231 
233  // Find out where the
235  void recalculateMostBottomRightPosition();
236 
237 
239  private:
240 
241  sf::Vector2f m_contentSize;
242  sf::Vector2f m_mostBottomRightPosition;
243  ScrollbarChildWidget m_verticalScrollbar;
244  ScrollbarChildWidget m_horizontalScrollbar;
245 
247  };
248 
250 }
251 
253 
254 #endif // TGUI_SCROLLABLE_PANEL_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Group of widgets that has a background color and optional borders.
Definition: ScrollablePanel.hpp:40
Class to store the position or size of a widget.
Definition: Layout.hpp:243
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: ScrollablePanel.hpp:217
std::shared_ptr< const ScrollablePanel > ConstPtr
Shared constant widget pointer.
Definition: ScrollablePanel.hpp:45
Wrapper around scrollbar to be used inside widgets that need a scrollbar.
Definition: Scrollbar.hpp:372
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
std::shared_ptr< ScrollablePanel > Ptr
Shared widget pointer.
Definition: ScrollablePanel.hpp:44
Group of widgets that has a background color and optional borders.
Definition: Panel.hpp:40
Definition: ScrollablePanelRenderer.hpp:36