TGUI 1.13
Loading...
Searching...
No Matches
SplitContainer.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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/Renderers/SplitContainerRenderer.hpp>
29#include <TGUI/Widgets/Group.hpp>
30
32
33namespace tgui
34{
43 class TGUI_API SplitContainer : public Group
44 {
45 public:
46 using Ptr = std::shared_ptr<SplitContainer>;
47 using ConstPtr = std::shared_ptr<const SplitContainer>;
48
49 static constexpr char StaticWidgetType[] = "SplitContainer";
50
58 explicit SplitContainer(const char* typeName = StaticWidgetType, bool initRenderer = true);
59
67 [[nodiscard]] static SplitContainer::Ptr create(const Layout2d& size = {"100%", "100%"});
68
76 [[nodiscard]] static SplitContainer::Ptr copy(const SplitContainer::ConstPtr& splitContainer);
77
82 [[nodiscard]] SplitContainerRenderer* getSharedRenderer() override;
83 [[nodiscard]] const SplitContainerRenderer* getSharedRenderer() const override;
84
90 [[nodiscard]] SplitContainerRenderer* getRenderer() override;
91
97 void setSize(const Layout2d& size) override;
98 using Widget::setSize;
99
114 void add(const Widget::Ptr& widgetPtr, const String& widgetName = "") override;
115
129 bool setWidgetIndex(const Widget::Ptr& widget, std::size_t index) override;
130
136 void setOrientation(Orientation orientation);
137
143 [[nodiscard]] Orientation getOrientation() const;
144
157
163 [[nodiscard]] float getMinValidSplitterOffset() const;
164
177
183 [[nodiscard]] float getMaxValidSplitterOffset() const;
184
197
203 [[nodiscard]] float getSplitterOffset() const;
204
210 void setSplitterWidth(float width);
211
217 [[nodiscard]] float getSplitterWidth() const;
218
227 void setMinimumGrabWidth(float width);
228
237 [[nodiscard]] float getMinimumGrabWidth() const;
238
244 [[nodiscard]] bool isMouseOnWidget(Vector2f pos) const override;
245
249 bool leftMousePressed(Vector2f pos) override;
250
254 void mouseMoved(Vector2f pos) override;
255
259 void mouseNoLongerOnWidget() override;
260
267 void draw(BackendRenderTarget& target, RenderStates states) const override;
268
270
271 protected:
277 void rendererChanged(const String& property) override;
278
282 [[nodiscard]] std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
283
287 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
288
292 void mouseEnteredWidget() override;
293
297 void mouseLeftWidget() override;
298
300 // Makes a copy of the widget
302 [[nodiscard]] Widget::Ptr clone() const override;
303
305 // Updates the splitter offset if it is defined as a relative value, and then calls updateChildren()
307 void updateAvailableSize();
308
310 // Updates the position and sizes of the 2 child widgets based on the current splitter offset
312 void updateChildren();
313
315 // Returns the area occupied by the splitter, with a marin around it if m_minimumGrabWidth > m_splitterWidth
317 [[nodiscard]] FloatRect getSplitterInteractRect() const;
318
320
321 protected:
322 Orientation m_orientation = Orientation::Horizontal;
323 AbsoluteOrRelativeValue m_splitterMinOffset;
324 AbsoluteOrRelativeValue m_splitterMaxOffset = RelativeValue(1);
325 AbsoluteOrRelativeValue m_splitterOffset = RelativeValue(0.5f);
326 float m_currentSplitterOffset = 0;
327 float m_splitterWidth = 3;
328 float m_minimumGrabWidth = 5;
329
330 bool m_mouseHoverOnSplitter = false;
331 bool m_mouseDownOnSplitter = false;
332 float m_mouseDownOnSplitterOffset = 0;
333 Cursor::Type m_currentSplitContainerMouseCursor = Cursor::Type::Arrow;
334
335 // Cached renderer properties
336 Color m_splitterColorCached;
337 Color m_splitterColorHoverCached;
338 };
339} // namespace tgui
340
341#endif // TGUI_SPLIT_CONTAINER_HPP
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:44
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:63
Type
List of available cursors.
Definition Cursor.hpp:48
@ Arrow
Arrow cursor (default).
Definition Cursor.hpp:49
Class to store the position or size of a widget.
Definition Layout.hpp:320
Definition SplitContainerRenderer.hpp:36
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:47
std::shared_ptr< SplitContainer > Ptr
Shared widget pointer.
Definition SplitContainer.hpp:46
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.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition SplitContainer.hpp:49
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:94
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:85
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
Orientation
Orientation of the object.
Definition Layout.hpp:50
@ Horizontal
Horizontal orientation.
Definition Layout.hpp:52
Helper class to create an AbsoluteOrRelativeValue object containing a relative value without using a ...
Definition AbsoluteOrRelativeValue.hpp:163
States used for drawing.
Definition RenderStates.hpp:38