TGUI 1.13
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#include <TGUI/SubwidgetContainer.hpp>
29#include <TGUI/Widgets/EditBox.hpp>
30#include <TGUI/Widgets/Slider.hpp>
31
33
34namespace tgui
35{
40 class TGUI_API EditBoxSlider : public SubwidgetContainer
41 {
42 public:
43 using Ptr = std::shared_ptr<EditBoxSlider>;
44 using ConstrPtr = std::shared_ptr<const EditBoxSlider>;
45
46 static constexpr char StaticWidgetType[] = "EditBoxSlider";
47
55 explicit EditBoxSlider(const char* typeName = StaticWidgetType, bool initRenderer = true);
56
60 EditBoxSlider(const EditBoxSlider& other);
61
65 EditBoxSlider(EditBoxSlider&& other) noexcept;
66
70 EditBoxSlider& operator=(const EditBoxSlider& other);
71
75 EditBoxSlider& operator=(EditBoxSlider&& other) noexcept;
76
88 [[nodiscard]] static EditBoxSlider::Ptr create(
89 float min = 0.0f,
90 float max = 10.0f,
91 float value = 0.0f,
92 unsigned int decimal = 0,
93 float step = 1.0f);
94
102 [[nodiscard]] static EditBoxSlider::Ptr copy(const EditBoxSlider::ConstPtr& editBoxSlider);
103
109 [[nodiscard]] const EditBoxRenderer* getEditBoxSharedRenderer() const;
110
117
123 [[nodiscard]] const SliderRenderer* getSliderSharedRenderer() const;
124
131
137 void setSize(const Layout2d& size) override;
139
147 [[nodiscard]] Vector2f getFullSize() const override;
148
157 [[nodiscard]] Vector2f getWidgetOffset() const override;
158
167 void setMinimum(float minimum);
168
176 [[nodiscard]] float getMinimum() const;
177
186 void setMaximum(float maximum);
187
195 [[nodiscard]] float getMaximum() const;
196
206 bool setValue(float value);
207
215 [[nodiscard]] float getValue() const;
216
222 void setStep(float step);
223
231 [[nodiscard]] float getStep() const;
232
239 void setDecimalPlaces(unsigned int decimalPlaces);
240
248 [[nodiscard]] unsigned int getDecimalPlaces() const;
249
257
266
268
269 private:
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(float value) const;
279
281 // Updates the text in the edit box
283 void setString(const String& str);
284
286
287 protected:
297 [[nodiscard]] Signal& getSignal(String signalName) override;
298
300 // Makes a copy of the widget
302 [[nodiscard]] Widget::Ptr clone() const override;
303
307 [[nodiscard]] std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
308
312 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
313
315
316 public:
317 SignalFloat onValueChange = {"ValueChanged"};
318
320
321 protected:
322 unsigned m_decimalPlaces = 0;
323
325
326 private:
327 EditBox::Ptr m_editBox = EditBox::create();
328 Slider::Ptr m_slider = Slider::create();
329 };
330} // namespace tgui
331
332#endif // TGUI_EDIT_BOX_SLIDER_HPP
Definition EditBoxRenderer.hpp:35
static 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.
SignalFloat onValueChange
Value of the slider changed. Optional parameter: new value.
Definition EditBoxSlider.hpp:317
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition EditBoxSlider.hpp:46
void setSize(const Layout2d &size) override
Changes the size of the edit box slider.
Vector2f getFullSize() const override
Returns the full size of the combined edit box and slider.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
HorizontalAlignment getTextAlignment() const
Returns the current text alignment of the edit box.
bool setValue(float value)
Changes the current value.
float getValue() const
Returns the current value.
void setMaximum(float maximum)
Sets a maximum value.
void setStep(float step)
Changes how much the value changes on each arrow press.
float getMinimum() const
Returns the minimum value.
SliderRenderer * getSliderRenderer()
Returns the renderer of slider part of widget.
std::shared_ptr< EditBoxSlider > Ptr
Shared widget pointer.
Definition EditBoxSlider.hpp:43
void setMinimum(float minimum)
Sets a 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 * getEditBoxSharedRenderer()
Returns the renderer of edit box part of widget.
EditBoxSlider(EditBoxSlider &&other) noexcept
Move constructor.
EditBoxRenderer * getEditBoxRenderer()
Returns the renderer of edit box part of widget.
unsigned int getDecimalPlaces() const
Returns the number of decimal places to display.
float getMaximum() const
Returns the maximum value.
static EditBoxSlider::Ptr copy(const EditBoxSlider::ConstPtr &editBoxSlider)
Makes a copy of another edit box slider.
void setTextAlignment(HorizontalAlignment alignment)
Sets the alignment of the edit box text.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< const EditBoxSlider > ConstrPtr
Shared const widget pointer.
Definition EditBoxSlider.hpp:44
void setDecimalPlaces(unsigned int decimalPlaces)
Changes the number of decimal places to display.
Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
EditBoxSlider(const EditBoxSlider &other)
Copy constructor.
float getStep() const
Returns the number of positions the thumb advances with each move.
EditBoxSlider & operator=(const EditBoxSlider &other)
Overload of copy assignment operator.
EditBoxSlider & operator=(EditBoxSlider &&other) noexcept
Overload of move assignment operator.
SliderRenderer * getSliderSharedRenderer()
Returns the renderer of slider part of widget.
static EditBox::Ptr create()
Creates a new edit box widget.
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition EditBox.hpp:48
Class to store the position or size of a widget.
Definition Layout.hpp:320
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
Definition SliderRenderer.hpp:35
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition Slider.hpp:41
static Slider::Ptr create(float minimum=0, float maximum=10)
Creates a new slider widget.
Wrapper class to store strings.
Definition String.hpp:94
void setSize(const Layout2d &size) override
Changes the size of the widget.
std::shared_ptr< const SubwidgetContainer > ConstPtr
Shared constant widget pointer.
Definition SubwidgetContainer.hpp:44
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:85
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:60
SignalTyped< float > SignalFloat
Signal with one "float" as optional unbound parameter.
Definition Signal.hpp:411