26#ifndef TGUI_ABSOLUTE_OR_RELATIVE_VALUE_HPP
27#define TGUI_ABSOLUTE_OR_RELATIVE_VALUE_HPP
29#include <TGUI/Global.hpp>
30#include <TGUI/String.hpp>
60 template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
63 m_value {static_cast<float>(constant)}
86 if (!expression.empty() && (expression.back() ==
'%'))
89 m_ratio = expression.substr(0, expression.length()-1).
toFloat() / 100.f;
94 m_value = expression.substr(0, expression.length()).
toFloat();
138 TGUI_CONSTEXPR
void updateParentSize(
float newParentSize)
142 m_parentValue = newParentSize;
143 m_value = m_ratio * newParentSize;
154 String toString()
const
157 return String::fromNumber(m_value);
159 return String::fromNumber(m_ratio * 100) +
'%';
166 bool m_constant =
true;
169 float m_parentValue = 0;
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:43
TGUI_CONSTEXPR float getValue() const
Returns the value.
Definition AbsoluteOrRelativeValue.hpp:104
AbsoluteOrRelativeValue(const char *expression)
Construct the value from a string that either contains a value or a percentage.
Definition AbsoluteOrRelativeValue.hpp:73
TGUI_CONSTEXPR float getRatio() const
Returns the stored ratio.
Definition AbsoluteOrRelativeValue.hpp:115
TGUI_CONSTEXPR bool isConstant() const
Returns whether the value is constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:126
TGUI_CONSTEXPR AbsoluteOrRelativeValue()
Default constructor.
Definition AbsoluteOrRelativeValue.hpp:49
AbsoluteOrRelativeValue(const String &expression)
Construct the value from a string that either contains a value or a percentage.
Definition AbsoluteOrRelativeValue.hpp:84
TGUI_CONSTEXPR AbsoluteOrRelativeValue(T constant)
Constructor to set constant.
Definition AbsoluteOrRelativeValue.hpp:61
Wrapper class to store strings.
Definition String.hpp:79
float toFloat(float defaultValue=0) const
Converts the string to a float.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
Helper class to create an AbsoluteOrRelativeValue object containing a relative value without using a ...
Definition AbsoluteOrRelativeValue.hpp:177