TGUI  0.9-dev
SpinControl.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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 typedef std::shared_ptr<SpinControl> Ptr;
46 typedef std::shared_ptr<const SpinControl> ConstPtr;
47
48
56 SpinControl(const char* typeName = "SpinControl", bool initRenderer = true);
57
58
70 static SpinControl::Ptr create(float min = 0.0f, float max = 10.0f, float value = 0.0f, unsigned int decimal = 0, float step = 1.0f);
71
72
81
82
88 const SpinButtonRenderer* getSpinButtonSharedRenderer() const;
89
96 const SpinButtonRenderer* getSpinButtonRenderer() const;
97
98
104 const EditBoxRenderer* getSpinTextSharedRenderer() const;
105
106
113 const EditBoxRenderer* getSpinTextRenderer() const;
114
115
121 void setSize(const Layout2d& size) override;
123
124
133 void setMinimum(float minimum);
134
135
143 float getMinimum() const;
144
145
154 void setMaximum(float maximum);
155
156
164 float getMaximum() const;
165
166
176 bool setValue(float value);
177
178
186 float getValue() const;
187
188
194 void setStep(float step);
195
196
204 float getStep() const;
205
206
213 void setDecimalPlaces(unsigned int decimalPlaces);
214
215
223 unsigned int getDecimalPlaces() const;
224
225
227 protected:
228
230 // Makes a copy of the widget
232 Widget::Ptr clone() const override
233 {
234 return std::make_shared<SpinControl>(*this);
235 }
236
237
241 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
242
243
247 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
248
249
251 private:
252
254 // Helper function that initializes the widget when constructing a new widget or loading one from a file
256 void init();
257
258
260 // Checks whether a value lies between the minimum and maximum
262 bool inRange(const float value) const;
263
264
266 // Updates the text in the edit box
268 void setString(const tgui::String& str);
269
270
272 public:
273
274 SignalFloat onValueChange = {"ValueChanged"};
275
276
278 protected:
279
280 unsigned int m_decimalPlaces = 0;
281
283 private:
284 tgui::SpinButton::Ptr m_spinButton;
285 tgui::EditBox::Ptr m_spinText;
286 };
287
289}
290
292
293#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:262
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.
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.
Definition: SpinControl.hpp:232
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.
static SpinControl::Ptr copy(SpinControl::ConstPtr SpinCtrl)
Makes a copy of another spin control.
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
std::shared_ptr< const SpinControl > ConstPtr
Shared constant widget pointer.
Definition: SpinControl.hpp:46
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
void setSize(const Layout2d &size) override
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36