TGUI  1.0-beta
Loading...
Searching...
No Matches
SpinControl.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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
26#ifndef TGUI_SPIN_CONTROL_HPP
27#define TGUI_SPIN_CONTROL_HPP
28
29
30#include <TGUI/SubwidgetContainer.hpp>
31#include <TGUI/Widgets/SpinButton.hpp>
32#include <TGUI/Widgets/EditBox.hpp>
33
35
36namespace tgui
37{
41 class TGUI_API SpinControl : public SubwidgetContainer
42 {
43 public:
44
45 using Ptr = std::shared_ptr<SpinControl>;
46 using ConstPtr = std::shared_ptr<const SpinControl>;
47
48 static constexpr const char StaticWidgetType[] = "SpinControl";
49
50
58 SpinControl(const char* typeName = StaticWidgetType, bool initRenderer = true);
59
60
72 static SpinControl::Ptr create(float min = 0.0f, float max = 10.0f, float value = 0.0f, unsigned int decimal = 0, float step = 1.0f);
73
74
83
84
90 const SpinButtonRenderer* getSpinButtonSharedRenderer() const;
91
98 const SpinButtonRenderer* getSpinButtonRenderer() const;
99
100
106 const EditBoxRenderer* getSpinTextSharedRenderer() const;
107
108
115 const EditBoxRenderer* getSpinTextRenderer() const;
116
117
123 void setSize(const Layout2d& size) override;
124 using SubwidgetContainer::setSize;
125
126
135 void setMinimum(float minimum);
136
137
145 float getMinimum() const;
146
147
156 void setMaximum(float maximum);
157
158
166 float getMaximum() const;
167
168
178 bool setValue(float value);
179
180
188 float getValue() const;
189
190
196 void setStep(float step);
197
198
206 float getStep() const;
207
208
215 void setDecimalPlaces(unsigned int decimalPlaces);
216
217
225 unsigned int getDecimalPlaces() const;
226
227
229 protected:
230
232 // Makes a copy of the widget
234 Widget::Ptr clone() const override;
235
236
240 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
241
242
246 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
247
248
250 private:
251
253 // Helper function that initializes the widget when constructing a new widget or loading one from a file
255 void init();
256
257
259 // Checks whether a value lies between the minimum and maximum
261 bool inRange(const float value) const;
262
263
265 // Updates the text in the edit box
267 void setString(const tgui::String& str);
268
269
271 public:
272
273 SignalFloat onValueChange = {"ValueChanged"};
274
275
277 protected:
278
279 unsigned int m_decimalPlaces = 0;
280
282 private:
283 tgui::SpinButton::Ptr m_spinButton = SpinButton::create();
284 tgui::EditBox::Ptr m_spinText = EditBox::create();
285 };
286
288}
289
291
292#endif // TGUI_SPIN_CONTROL_HPP
Definition: EditBoxRenderer.hpp:37
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition: EditBox.hpp:49
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Definition: SpinButtonRenderer.hpp:37
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition: SpinButton.hpp:45
Spin control widget.
Definition: SpinControl.hpp:42
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.
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:46
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.
EditBoxRenderer * getSpinTextRenderer()
Returns the renderer of edit box part of widget.
unsigned int getDecimalPlaces() const
Returns the number of decimal places to display.
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 setSize(const Layout2d &size) override
Changes the size of the spin control.
void setMinimum(float minimum)
Sets a minimum value.
void setStep(float step)
Changes how much the value changes on each arrow press.
std::shared_ptr< SpinControl > Ptr
Shared widget pointer.
Definition: SpinControl.hpp:45
SpinButtonRenderer * getSpinButtonRenderer()
Returns the renderer of spin buttons part of widget.
void setDecimalPlaces(unsigned int decimalPlaces)
Changes the number of decimal places to display.
bool setValue(float value)
Changes the current value.
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:79
Base class for widgets that consist of subwidgets that act together as if they are a single widget.
Definition: SubwidgetContainer.hpp:43
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36