25#ifndef TGUI_LAYOUT_HPP
26#define TGUI_LAYOUT_HPP
28#include <TGUI/Config.hpp>
29#include <TGUI/Vector2.hpp>
31#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
32 #include <type_traits>
40TGUI_MODULE_EXPORT
namespace tgui
138 template <typename T, typename = typename std::enable_if_t<std::is_arithmetic<T>::value, T>>
140 m_value{static_cast<float>(constant)}
171 explicit Layout(
Operation operation, std::unique_ptr<Layout> leftOperand, std::unique_ptr<Layout> rightOperand);
222 return m_operation == Operation::Value;
231 TGUI_NODISCARD
String toString()
const;
240 void connectWidget(
Widget* widget,
bool xAxis, std::function<
void()> valueChangedCallbackHandler);
253 void recalculateValue();
259 TGUI_NODISCARD
Layout* getLeftOperand()
const;
265 TGUI_NODISCARD
Layout* getRightOperand()
const;
279 void resetPointers();
284 void parseBindingStringRecursive(
Widget* widget,
bool xAxis);
289 void parseBindingString(
const String& expression,
Widget* widget,
bool xAxis);
295 Layout* m_parent =
nullptr;
296 Operation m_operation = Operation::Value;
297 std::unique_ptr<Layout> m_leftOperand =
nullptr;
298 std::unique_ptr<Layout> m_rightOperand =
nullptr;
299 Widget* m_boundWidget =
nullptr;
301 std::function<void()> m_connectedWidgetCallback =
nullptr;
302 int m_callingCallbackCount = 0;
334 x{std::move(layoutX)},
335 y{std::move(layoutY)}
372 return {x.getValue(), y.getValue()};
381 TGUI_NODISCARD
String toString()
const
383 return U
"(" + x.toString() + U
", " + y.toString() + U
")";
450 inline namespace bind_functions
462 TGUI_NODISCARD TGUI_API
Layout bindTop(
const std::shared_ptr<Widget>& widget);
Base class for the Gui.
Definition BackendGui.hpp:47
Class to store the position or size of a widget.
Definition Layout.hpp:313
Layout2d(Vector2f constant={0, 0})
Default constructor to implicitly construct from a tgui::Vector2f.
Definition Layout.hpp:321
Layout2d(Layout layoutX, Layout layoutY)
Constructor to create the Layout2d from two Layout classes.
Definition Layout.hpp:333
Layout2d(const char *expression)
Constructs the Layout2d based on a string which will be parsed to determine the value of the layouts.
Definition Layout.hpp:346
TGUI_NODISCARD Vector2f getValue() const
Returns the cached value of the layout.
Definition Layout.hpp:370
Layout2d(const String &expression)
Constructs the Layout2d based on a string which will be parsed to determine the value of the layouts.
Definition Layout.hpp:359
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:101
Layout(Layout &&other) noexcept
Move constructor.
Layout(String expression)
Constructs the layout based on a string which will be parsed to determine the value of the layout.
Operation
The operation which the layout has to perform to find its value.
Definition Layout.hpp:106
TGUI_NODISCARD float getValue() const
Return the cached value of the layout.
Definition Layout.hpp:210
Layout()=default
Default constructor.
Layout & operator=(Layout &&other) noexcept
Move assignment operator.
Layout(T constant)
Constructor to implicitly construct from numeric constant.
Definition Layout.hpp:139
Layout(const Layout &other)
Copy constructor.
void replaceValue(const Layout &value)
Replaces the value of the layout without overwriting its parent.
Layout(const char *expression)
Constructs the layout based on a string which will be parsed to determine the value of the layout.
Definition Layout.hpp:149
TGUI_NODISCARD bool isConstant() const
Return whether the layout stores a constant value.
Definition Layout.hpp:220
Layout & operator=(const Layout &other)
Copy assignment operator.
Wrapper class to store strings.
Definition String.hpp:96
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
TGUI_NODISCARD TGUI_API Layout bindLeft(const std::shared_ptr< Widget > &widget)
Bind to the left position of the widget.
TGUI_NODISCARD TGUI_API Layout bindRight(const std::shared_ptr< Widget > &widget)
Bind to the right position of the widget.
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:61
@ Center
Center the object horizontally.
@ Right
Align to the right side.
@ Left
Align to the left side.
TGUI_NODISCARD TGUI_API Layout bindWidth(const std::shared_ptr< Widget > &widget)
Bind to the width of the widget.
TGUI_NODISCARD TGUI_API Layout bindMax(const Layout &value1, const Layout &value2)
Bind to the maximum value of two layouts.
TGUI_NODISCARD TGUI_API Layout bindHeight(const std::shared_ptr< Widget > &widget)
Bind to the height of the widget.
TGUI_NODISCARD TGUI_API Layout2d bindSize(const std::shared_ptr< Widget > &widget)
Bind to the size of the widget.
TGUI_NODISCARD TGUI_API Layout bindTop(const std::shared_ptr< Widget > &widget)
Bind to the top position of the widget.
TGUI_NODISCARD TGUI_API Layout bindInnerWidth(const std::shared_ptr< Container > &container)
Bind to the inner width of the container widget.
Orientation
Orientation of the object.
Definition Layout.hpp:51
@ Vertical
Vertical orientation.
@ Horizontal
Horizontal orientation.
TGUI_NODISCARD TGUI_API Layout2d bindPosition(const std::shared_ptr< Widget > &widget)
Bind to the position of the widget.
AutoLayout
Alignments for how to position a widget in its parent.
Definition Layout.hpp:84
@ Leftmost
Places the widget on the left side and sets height to 100%. Width needs to be manually set....
@ Rightmost
Places the widget on the right side and sets height to 100%. Width needs to be manually set....
@ Fill
Sets the position and size to fill the entire area that isn't already taken by components with the ot...
@ Manual
Position and size need to be manually set. This is the default.
TGUI_NODISCARD TGUI_API Layout bindPosX(const std::shared_ptr< Widget > &widget)
Bind to the x position of the widget (same as bindLeft unless widget origin is changed)
TGUI_NODISCARD TGUI_API Layout bindBottom(const std::shared_ptr< Widget > &widget)
Bind to the bottom of the widget.
TGUI_NODISCARD TGUI_API Layout bindMin(const Layout &value1, const Layout &value2)
Bind to the minimum value of two layouts.
TGUI_NODISCARD TGUI_API Layout bindPosY(const std::shared_ptr< Widget > &widget)
Bind to the y position of the widget (same as bindTop unless widget origin is changed)
TGUI_NODISCARD TGUI_API Layout2d bindInnerSize(const std::shared_ptr< Container > &container)
Bind to the inner size of the container widget.
VerticalAlignment
The vertical alignment.
Definition Layout.hpp:72
@ Bottom
Align to the bottom.
TGUI_NODISCARD TGUI_API Layout bindInnerHeight(const std::shared_ptr< Container > &container)
Bind to the inner height of the container widget.