TGUI  1.3-dev
Loading...
Searching...
No Matches
EditBoxSlider.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2023 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_EDIT_BOX_SLIDER_HPP
26#define TGUI_EDIT_BOX_SLIDER_HPP
27
28
29#include <TGUI/SubwidgetContainer.hpp>
30#include <TGUI/Widgets/EditBox.hpp>
31#include <TGUI/Widgets/Slider.hpp>
32
34
35TGUI_MODULE_EXPORT namespace tgui
36{
40 class TGUI_API EditBoxSlider : public SubwidgetContainer
41 {
42 public:
43
44 using Ptr = std::shared_ptr<EditBoxSlider>;
45 using ConstrPtr = std::shared_ptr<const EditBoxSlider>;
46
47 static constexpr const char StaticWidgetType[] = "EditBoxSlider";
48
56 EditBoxSlider(const char* typeName = StaticWidgetType, bool initRenderer = true);
57
62
63
67 EditBoxSlider(EditBoxSlider&& copy) noexcept;
68
69
73 EditBoxSlider& operator= (const EditBoxSlider& right);
74
75
79 EditBoxSlider& operator= (EditBoxSlider&& right) noexcept;
80
92 TGUI_NODISCARD static EditBoxSlider::Ptr create(float min = 0.0f, float max = 10.0f, float value = 0.0f, unsigned int decimal = 0, float step = 1.0f);
93
95
104 TGUI_NODISCARD static EditBoxSlider::Ptr copy(const EditBoxSlider::ConstPtr& editBoxSlider);
105
111 TGUI_NODISCARD const EditBoxRenderer* getEditBoxSharedRenderer() const;
112
119
120
126 TGUI_NODISCARD const SliderRenderer* getSliderSharedRenderer() const;
127
128
135
136
142 void setSize(const Layout2d& size) override;
143 using SubwidgetContainer::setSize;
144
153 void setMinimum(float minimum);
154
155
163 TGUI_NODISCARD float getMinimum() const;
164
165
174 void setMaximum(float maximum);
175
176
184 TGUI_NODISCARD float getMaximum() const;
185
195 bool setValue(float value);
196
197
205 TGUI_NODISCARD float getValue() const;
206
212 void setStep(float step);
213
221 TGUI_NODISCARD float getStep() const;
222
229 void setDecimalPlaces(unsigned int decimalPlaces);
230
231
239 TGUI_NODISCARD unsigned int getDecimalPlaces() const;
240
248
256 TGUI_NODISCARD EditBox::Alignment getTextAlignment() const;
257
258
260 private:
262 // Helper function that initializes the widget when constructing a new widget or loading one from a file
264 void init();
265
267 // Checks whether a value lies between the minimum and maximum
269 bool inRange(const float value) const;
270
271
273 // Updates the text in the edit box
275 void setString(const String& str);
276
277
279 protected:
280
290 TGUI_NODISCARD Signal& getSignal(String signalName) override;
291
293 // Makes a copy of the widget
295 TGUI_NODISCARD Widget::Ptr clone() const override;
296
300 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
301
302
306 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
307
308
310 public:
311 SignalFloat onValueChange = {"ValueChanged"};
312
314 protected:
315 unsigned m_decimalPlaces = 0;
316
318 private:
319 EditBox::Ptr m_editBox = EditBox::create();
320 Slider::Ptr m_slider = Slider::create();
321 };
322}
323
325
326#endif // TGUI_EDIT_BOX_SLIDER_HPP
Definition EditBoxRenderer.hpp:37
Edit box slider widget.
Definition EditBoxSlider.hpp:41
static TGUI_NODISCARD EditBoxSlider::Ptr copy(const EditBoxSlider::ConstPtr &editBoxSlider)
Makes a copy of another edit box slider.
void setSize(const Layout2d &size) override
Changes the size of the edit box slider.
static TGUI_NODISCARD EditBoxSlider::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 edit box slider widget.
bool setValue(float value)
Changes the current value.
TGUI_NODISCARD float getMinimum() const
Returns the minimum value.
void setMaximum(float maximum)
Sets a maximum value.
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 setStep(float step)
Changes how much the value changes on each arrow press.
TGUI_NODISCARD EditBoxRenderer * getEditBoxSharedRenderer()
Returns the renderer of edit box part of widget.
EditBoxSlider(const EditBoxSlider &copy)
Copy constructor.
std::shared_ptr< EditBoxSlider > Ptr
Shared widget pointer.
Definition EditBoxSlider.hpp:44
void setMinimum(float minimum)
Sets a minimum value.
TGUI_NODISCARD float getMaximum() const
Returns the maximum value.
EditBoxSlider(EditBoxSlider &&copy) noexcept
Move constructor.
TGUI_NODISCARD SliderRenderer * getSliderSharedRenderer()
Returns the renderer of slider part of widget.
TGUI_NODISCARD EditBoxRenderer * getEditBoxRenderer()
Returns the renderer of edit box part of widget.
TGUI_NODISCARD EditBox::Alignment getTextAlignment() const
Returns the current text alignment of the edit box.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
void setTextAlignment(EditBox::Alignment alignment)
Sets the alignment of the edit box text.
TGUI_NODISCARD unsigned int getDecimalPlaces() const
Returns the number of decimal places to display.
TGUI_NODISCARD SliderRenderer * getSliderRenderer()
Returns the renderer of slider part of widget.
std::shared_ptr< const EditBoxSlider > ConstrPtr
Shared const widget pointer.
Definition EditBoxSlider.hpp:45
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void setDecimalPlaces(unsigned int decimalPlaces)
Changes the number of decimal places to display.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
TGUI_NODISCARD float getValue() const
Returns the current value.
TGUI_NODISCARD float getStep() const
Returns the number of positions the thumb advances with each move.
Alignment
The text alignment.
Definition EditBox.hpp:62
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 SliderRenderer.hpp:37
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition Slider.hpp:44
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< const SubwidgetContainer > ConstPtr
Shared constant widget pointer.
Definition SubwidgetContainer.hpp:47
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39