25#ifndef TGUI_SPIN_CONTROL_HPP
26#define TGUI_SPIN_CONTROL_HPP
28#include <TGUI/SubwidgetContainer.hpp>
29#include <TGUI/Widgets/SpinButton.hpp>
30#include <TGUI/Widgets/EditBox.hpp>
34TGUI_MODULE_EXPORT
namespace tgui
39 class TGUI_API SpinControl :
public SubwidgetContainer
43 using Ptr = std::shared_ptr<SpinControl>;
44 using ConstPtr = std::shared_ptr<const SpinControl>;
55 SpinControl(
const char* typeName =
StaticWidgetType,
bool initRenderer =
true);
70 SpinControl& operator= (
const SpinControl& right);
75 SpinControl& operator= (SpinControl&& right)
noexcept;
88 TGUI_NODISCARD
static SpinControl::Ptr create(
float min = 0.0f,
float max = 10.0f,
float value = 0.0f,
unsigned int decimal = 0,
float step = 1.0f);
182 template <typename T, typename = typename std::enable_if_t<std::is_arithmetic<T>::value, T>>
187 if (m_spinButton->getValue() !=
static_cast<float>(value) && inRange(
static_cast<float>(value)))
189 m_spinButton->setValue(value);
210 template <typename T, typename = typename std::enable_if_t<std::is_arithmetic<T>::value, T>>
215 m_spinButton->setStep(step);
248 TGUI_DEPRECATED(
"Use setSpinButtonWidth(\"100%\") or setSpinButtonWidth(\"50%\") instead") void
setUseWideArrows(
bool useWideArrows);
254 TGUI_DEPRECATED(
"Use getSpinButtonWidth() instead") TGUI_NODISCARD
bool getUseWideArrows() const;
296 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers) const override;
301 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
314 bool inRange(const
float value) const;
319 void setString(const
String& str);
329 unsigned int m_decimalPlaces = 0;
330 bool m_useWideArrows =
false;
Class to store the a value that is either a constant or a ratio.
Definition AbsoluteOrRelativeValue.hpp:45
Definition EditBoxRenderer.hpp:35
static EditBox::Ptr create()
Creates a new edit box widget.
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition EditBox.hpp:51
Class to store the position or size of a widget.
Definition Layout.hpp:323
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
SpinButtonRenderer * getSpinButtonSharedRenderer()
Returns the renderer of spin buttons part of widget.
EditBoxRenderer * getSpinTextSharedRenderer()
Returns the renderer of edit box part of widget.
void setMaximum(float maximum)
Sets a maximum value.
static SpinControl::Ptr copy(const SpinControl::ConstPtr &SpinCtrl)
Makes a copy of another spin control.
float getMaximum() const
Returns the maximum value.
SpinControl(const SpinControl ©)
Copy constructor.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< const SpinControl > ConstPtr
Shared constant widget pointer.
Definition SpinControl.hpp:44
float getMinimum() const
Returns the minimum value.
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.
bool getUseWideArrows() const
Returns whether the spin button width equals the heigh or the widget or only half of the height (defa...
SignalFloat onValueChange
Value of the spin control changed. Optional parameter: new value.
Definition SpinControl.hpp:324
void setSpinButtonWidth(AbsoluteOrRelativeValue width)
Changes the width of the spin button (i.e. width of the arrows that are shown next to the edit box)
EditBoxRenderer * getSpinTextRenderer()
Returns the renderer of edit box part of widget.
SpinControl(SpinControl &©) noexcept
Move constructor.
unsigned int getDecimalPlaces() const
Returns the number of decimal places to display.
static constexpr const char StaticWidgetType[]
Type name of the widget.
Definition SpinControl.hpp:46
static SpinControl::Ptr create(float min=0.0f, float max=10.0f, float value=0.0f, unsigned int decimal=0, float step=1.0f)
Creates a new spin button widget.
void setUseWideArrows(bool useWideArrows)
Changes whether the spin button width equals the heigh or the widget or only half of the height (defa...
void setSize(const Layout2d &size) override
Changes the size of the spin control.
void setMinimum(float minimum)
Sets a minimum value.
bool setValue(T value)
Changes the current value.
Definition SpinControl.hpp:183
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
std::shared_ptr< SpinControl > Ptr
Shared widget pointer.
Definition SpinControl.hpp:43
void setStep(T step)
Changes how much the value changes on each arrow press.
Definition SpinControl.hpp:211
SpinButtonRenderer * getSpinButtonRenderer()
Returns the renderer of spin buttons part of widget.
void setDecimalPlaces(unsigned int decimalPlaces)
Changes the number of decimal places to display.
float getSpinButtonWidth() const
Returns the width of the spin button (i.e. width of the arrows that are shown next to the edit box)
float getValue() const
Returns the current value.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
float getStep() const
Returns the number of positions the thumb advances with each move.
Wrapper class to store strings.
Definition String.hpp:96
static String fromNumberRounded(T value, unsigned int decimals)
Construct the string from a floating point number, keeping only a certain amount of decimals behind t...
Definition String.hpp:329
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
SignalTyped< float > SignalFloat
Signal with one "float" as optional unbound parameter.
Definition Signal.hpp:426