TGUI  1.5
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#ifndef TGUI_SPIN_CONTROL_HPP
26#define TGUI_SPIN_CONTROL_HPP
27
28#include <TGUI/SubwidgetContainer.hpp>
29#include <TGUI/Widgets/SpinButton.hpp>
30#include <TGUI/Widgets/EditBox.hpp>
31
33
34TGUI_MODULE_EXPORT namespace tgui
35{
39 class TGUI_API SpinControl : public SubwidgetContainer
40 {
41 public:
42
43 using Ptr = std::shared_ptr<SpinControl>;
44 using ConstPtr = std::shared_ptr<const SpinControl>;
45
46 static constexpr const char StaticWidgetType[] = "SpinControl";
47
55 SpinControl(const char* typeName = StaticWidgetType, bool initRenderer = true);
56
61
65 SpinControl(SpinControl&& copy) noexcept;
66
70 SpinControl& operator= (const SpinControl& right);
71
75 SpinControl& operator= (SpinControl&& right) noexcept;
76
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);
89
97 TGUI_NODISCARD static SpinControl::Ptr copy(const SpinControl::ConstPtr& SpinCtrl);
98
104 TGUI_NODISCARD const SpinButtonRenderer* getSpinButtonSharedRenderer() const;
105
112
118 TGUI_NODISCARD const EditBoxRenderer* getSpinTextSharedRenderer() const;
119
126
132 void setSize(const Layout2d& size) override;
133 using SubwidgetContainer::setSize;
134
143 void setMinimum(float minimum);
144
152 TGUI_NODISCARD float getMinimum() const;
153
162 void setMaximum(float maximum);
163
171 TGUI_NODISCARD float getMaximum() const;
172
182 bool setValue(float value);
183
191 TGUI_NODISCARD float getValue() const;
192
198 void setStep(float step);
199
207 TGUI_NODISCARD float getStep() const;
208
215 void setDecimalPlaces(unsigned int decimalPlaces);
216
224 TGUI_NODISCARD unsigned int getDecimalPlaces() const;
225
230 void setUseWideArrows(bool useWideArrows);
231
236 TGUI_NODISCARD bool getUseWideArrows() const;
237
239 protected:
240
250 TGUI_NODISCARD Signal& getSignal(String signalName) override;
251
253 // Makes a copy of the widget
255 TGUI_NODISCARD Widget::Ptr clone() const override;
256
260 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
261
265 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
266
268 private:
269
271 // Helper function that initializes the widget when constructing a new widget or loading one from a file
273 void init();
274
276 // Checks whether a value lies between the minimum and maximum
278 bool inRange(const float value) const;
279
281 // Updates the text in the edit box
283 void setString(const String& str);
284
286 public:
287
288 SignalFloat onValueChange = {"ValueChanged"};
289
291 protected:
292
293 unsigned int m_decimalPlaces = 0;
294 bool m_useWideArrows = false;
295
297 private:
298 SpinButton::Ptr m_spinButton = SpinButton::create();
299 EditBox::Ptr m_spinText = EditBox::create();
300 };
301
303}
304
306
307#endif // TGUI_SPIN_CONTROL_HPP
Definition EditBoxRenderer.hpp:35
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:313
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Definition SpinButtonRenderer.hpp:35
std::shared_ptr< SpinButton > Ptr
Shared widget pointer.
Definition SpinButton.hpp:43
Spin control widget.
Definition SpinControl.hpp:40
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:44
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:43
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:96
Base class for widgets that consist of subwidgets that act together as if they are a single widget.
Definition SubwidgetContainer.hpp:41
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38