TGUI  1.6.1
Loading...
Searching...
No Matches
SplitContainer.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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#ifndef TGUI_SPLIT_CONTAINER_HPP
26#define TGUI_SPLIT_CONTAINER_HPP
27
28#include <TGUI/Widgets/Group.hpp>
29#include <TGUI/Renderers/SplitContainerRenderer.hpp>
30
32
33TGUI_MODULE_EXPORT namespace tgui
34{
43 class TGUI_API SplitContainer : public Group
44 {
45 public:
46
47 using Ptr = std::shared_ptr<SplitContainer>;
48 using ConstPtr = std::shared_ptr<const SplitContainer>;
49
50 static constexpr const char StaticWidgetType[] = "SplitContainer";
51
59 SplitContainer(const char* typeName = StaticWidgetType, bool initRenderer = true);
60
68 TGUI_NODISCARD static SplitContainer::Ptr create(const Layout2d& size = {"100%", "100%"});
69
77 TGUI_NODISCARD static SplitContainer::Ptr copy(const SplitContainer::ConstPtr& splitContainer);
78
83 TGUI_NODISCARD SplitContainerRenderer* getSharedRenderer() override;
84 TGUI_NODISCARD const SplitContainerRenderer* getSharedRenderer() const override;
85
91 TGUI_NODISCARD SplitContainerRenderer* getRenderer() override;
92
98 void setSize(const Layout2d& size) override;
99 using Widget::setSize;
100
115 void add(const Widget::Ptr& widgetPtr, const String& widgetName = "") override;
116
130 bool setWidgetIndex(const Widget::Ptr& widget, std::size_t index) override;
131
137 void setOrientation(Orientation orientation);
138
144 TGUI_NODISCARD Orientation getOrientation() const;
145
158
164 TGUI_NODISCARD float getMinValidSplitterOffset() const;
165
178
184 TGUI_NODISCARD float getMaxValidSplitterOffset() const;
185
198
204 TGUI_NODISCARD float getSplitterOffset() const;
205
211 void setSplitterWidth(float width);
212
218 TGUI_NODISCARD float getSplitterWidth() const;
219
228 void setMinimumGrabWidth(float width);
229
238 TGUI_NODISCARD float getMinimumGrabWidth() const;
239
245 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
246
250 bool leftMousePressed(Vector2f pos) override;
251
255 void mouseMoved(Vector2f pos) override;
256
260 void mouseNoLongerOnWidget() override;
261
268 void draw(BackendRenderTarget& target, RenderStates states) const override;
269
271 protected:
272
278 void rendererChanged(const String& property) override;
279
283 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
284
288 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
289
293 void mouseEnteredWidget() override;
294
298 void mouseLeftWidget() override;
299
301 // Makes a copy of the widget
303 TGUI_NODISCARD Widget::Ptr clone() const override;
304
306 // Updates the splitter offset if it is defined as a relative value, and then calls updateChildren()
308 void updateAvailableSize();
309
311 // Updates the position and sizes of the 2 child widgets based on the current splitter offset
313 void updateChildren();
314
316 // Returns the area occupied by the splitter, with a marin around it if m_minimumGrabWidth > m_splitterWidth
318 TGUI_NODISCARD FloatRect getSplitterInteractRect() const;
319
321 protected:
322
323 Orientation m_orientation = Orientation::Horizontal;
324 AbsoluteOrRelativeValue m_splitterMinOffset;
325 AbsoluteOrRelativeValue m_splitterMaxOffset = RelativeValue(1);
326 AbsoluteOrRelativeValue m_splitterOffset = RelativeValue(0.5f);
327 float m_currentSplitterOffset = 0;
328 float m_splitterWidth = 3;
329 float m_minimumGrabWidth = 5;
330
331 bool m_mouseHoverOnSplitter = false;
332 bool m_mouseDownOnSplitter = false;
333 float m_mouseDownOnSplitterOffset = 0;
334 Cursor::Type m_currentSplitContainerMouseCursor = Cursor::Type::Arrow;
335
336 // Cached renderer properties
337 Color m_splitterColorCached;
338 Color m_splitterColorHoverCached;
339
341 };
342
344}
345
347
348#endif // TGUI_SPLIT_CONTAINER_HPP
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:45
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:73
Type
List of available cursors.
Definition Cursor.hpp:50
Group widget.
Definition Group.hpp:42
Class to store the position or size of a widget.
Definition Layout.hpp:323
Definition SplitContainerRenderer.hpp:36
Container that should contains exactly 2 child widgets which will be resized to fill the container to...
Definition SplitContainer.hpp:44
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
static SplitContainer::Ptr copy(const SplitContainer::ConstPtr &splitContainer)
Makes a copy of another split container.
void setSize(const Layout2d &size) override
Changes the size of the split container.
void setOrientation(Orientation orientation)
Sets whether the widgets are placed left and right of the splitter or above and below the splitter.
std::shared_ptr< const SplitContainer > ConstPtr
Shared constant widget pointer.
Definition SplitContainer.hpp:48
std::shared_ptr< SplitContainer > Ptr
Shared widget pointer.
Definition SplitContainer.hpp:47
void mouseEnteredWidget() override
This function is called when the mouse enters the widget.
void add(const Widget::Ptr &widgetPtr, const String &widgetName="") override
Adds a widget to the container.
static SplitContainer::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new split container widget.
Orientation getOrientation() const
Returns whether the widgets are placed left and right of the splitter or above and below the splitter...
float getSplitterOffset() const
Returns the position of the splitter from the left or top position (depending on orientation)
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
void setMinValidSplitterOffset(AbsoluteOrRelativeValue minOffset)
Sets the minimum value for the splitter, effectively providing a minimum size for the top/left widget...
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the child widgets to a render target.
float getMinimumGrabWidth() const
Returns the minimum width of the area where the splitter can be dragged.
float getMinValidSplitterOffset() const
Returns the minimum value for the splitter.
void setMinimumGrabWidth(float width)
Sets the minimum width of the area where the splitter can be dragged.
void setSplitterWidth(float width)
Sets the width of the draggable splitter line that separates the two widgets in the container.
SplitContainerRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
float getMaxValidSplitterOffset() const
Returns the maximum value for the splitter.
bool setWidgetIndex(const Widget::Ptr &widget, std::size_t index) override
Changes the index of a widget in this container.
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.
SplitContainerRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
void setMaxValidSplitterOffset(AbsoluteOrRelativeValue maxOffset)
Sets the maximum value for the splitter, effectively providing a minimum size for the bottom/right wi...
void setSplitterOffset(AbsoluteOrRelativeValue offset)
Sets the position of the splitter from the left or top position (depending on orientation)
void mouseLeftWidget() override
This function is called when the mouse leaves the widget.
float getSplitterWidth() const
Returns the width of the draggable splitter line that separates the two widgets in the container.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
Wrapper class to store strings.
Definition String.hpp:96
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
Orientation
Orientation of the object.
Definition Layout.hpp:52
Helper class to create an AbsoluteOrRelativeValue object containing a relative value without using a ...
Definition AbsoluteOrRelativeValue.hpp:166
States used for drawing.
Definition RenderStates.hpp:38