TGUI  1.3-dev
Loading...
Searching...
No Matches
SpinControl.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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
36TGUI_MODULE_EXPORT namespace 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
65
66
70 SpinControl(SpinControl&& copy) noexcept;
71
72
76 SpinControl& operator= (const SpinControl& right);
77
78
82 SpinControl& operator= (SpinControl&& right) noexcept;
83
84
96 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);
97
98
106 TGUI_NODISCARD static SpinControl::Ptr copy(const SpinControl::ConstPtr& SpinCtrl);
107
108
114 TGUI_NODISCARD const SpinButtonRenderer* getSpinButtonSharedRenderer() const;
115
122
123
129 TGUI_NODISCARD const EditBoxRenderer* getSpinTextSharedRenderer() const;
130
131
138
139
145 void setSize(const Layout2d& size) override;
146 using SubwidgetContainer::setSize;
147
148
157 void setMinimum(float minimum);
158
159
167 TGUI_NODISCARD float getMinimum() const;
168
169
178 void setMaximum(float maximum);
179
180
188 TGUI_NODISCARD float getMaximum() const;
189
190
200 bool setValue(float value);
201
202
210 TGUI_NODISCARD float getValue() const;
211
212
218 void setStep(float step);
219
220
228 TGUI_NODISCARD float getStep() const;
229
230
237 void setDecimalPlaces(unsigned int decimalPlaces);
238
239
247 TGUI_NODISCARD unsigned int getDecimalPlaces() const;
248
249
254 void setUseWideArrows(bool useWideArrows);
255
256
261 TGUI_NODISCARD bool getUseWideArrows() const;
262
263
265 protected:
266
276 TGUI_NODISCARD Signal& getSignal(String signalName) override;
277
278
280 // Makes a copy of the widget
282 TGUI_NODISCARD Widget::Ptr clone() const override;
283
284
288 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
289
290
294 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
295
296
298 private:
299
301 // Helper function that initializes the widget when constructing a new widget or loading one from a file
303 void init();
304
305
307 // Checks whether a value lies between the minimum and maximum
309 bool inRange(const float value) const;
310
311
313 // Updates the text in the edit box
315 void setString(const String& str);
316
317
319 public:
320
321 SignalFloat onValueChange = {"ValueChanged"};
322
323
325 protected:
326
327 unsigned int m_decimalPlaces = 0;
328 bool m_useWideArrows = false;
329
331 private:
332 SpinButton::Ptr m_spinButton = SpinButton::create();
333 EditBox::Ptr m_spinText = EditBox::create();
334 };
335
337}
338
340
341#endif // TGUI_SPIN_CONTROL_HPP
Definition EditBoxRenderer.hpp:37
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition EditBox.hpp:52
Class to store the position or size of a widget.
Definition Layout.hpp:305
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Definition SpinButtonRenderer.hpp:37
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition SpinButton.hpp:45
Spin control widget.
Definition SpinControl.hpp:42
void setMaximum(float maximum)
Sets a maximum value.
TGUI_NODISCARD float getValue() const
Returns the current value.
SpinControl(const SpinControl &copy)
Copy constructor.
std::shared_ptr< const SpinControl > ConstPtr
Shared constant widget pointer.
Definition SpinControl.hpp:46
static TGUI_NODISCARD 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.
TGUI_NODISCARD float getStep() const
Returns the number of positions the thumb advances with each move.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
SpinControl(SpinControl &&copy) noexcept
Move constructor.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
TGUI_NODISCARD unsigned int getDecimalPlaces() const
Returns the number of decimal places to display.
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.
static TGUI_NODISCARD SpinControl::Ptr copy(const SpinControl::ConstPtr &SpinCtrl)
Makes a copy of another spin control.
void setMinimum(float minimum)
Sets a minimum value.
TGUI_NODISCARD SpinButtonRenderer * getSpinButtonRenderer()
Returns the renderer of spin buttons part of widget.
TGUI_NODISCARD float getMinimum() const
Returns the 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
TGUI_NODISCARD 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.
void setDecimalPlaces(unsigned int decimalPlaces)
Changes the number of decimal places to display.
bool setValue(float value)
Changes the current value.
TGUI_NODISCARD SpinButtonRenderer * getSpinButtonSharedRenderer()
Returns the renderer of spin buttons part of widget.
TGUI_NODISCARD EditBoxRenderer * getSpinTextRenderer()
Returns the renderer of edit box part of widget.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
TGUI_NODISCARD float getMaximum() const
Returns the maximum value.
TGUI_NODISCARD bool getUseWideArrows() const
Returns whether the spin button width equals the heigh or the widget or only half of the height (defa...
TGUI_NODISCARD EditBoxRenderer * getSpinTextSharedRenderer()
Returns the renderer of edit box part of widget.
Wrapper class to store strings.
Definition String.hpp:101
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:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39