TGUI  1.5
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
34TGUI_MODULE_EXPORT namespace tgui
35{
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
66 EditBoxSlider(EditBoxSlider&& copy) noexcept;
67
71 EditBoxSlider& operator= (const EditBoxSlider& right);
72
76 EditBoxSlider& operator= (EditBoxSlider&& right) noexcept;
77
89 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);
90
98 TGUI_NODISCARD static EditBoxSlider::Ptr copy(const EditBoxSlider::ConstPtr& editBoxSlider);
99
105 TGUI_NODISCARD const EditBoxRenderer* getEditBoxSharedRenderer() const;
106
113
119 TGUI_NODISCARD const SliderRenderer* getSliderSharedRenderer() const;
120
127
133 void setSize(const Layout2d& size) override;
134 using SubwidgetContainer::setSize;
135
143 TGUI_NODISCARD Vector2f getFullSize() const override;
144
153 TGUI_NODISCARD Vector2f getWidgetOffset() const override;
154
163 void setMinimum(float minimum);
164
172 TGUI_NODISCARD float getMinimum() const;
173
182 void setMaximum(float maximum);
183
191 TGUI_NODISCARD float getMaximum() const;
192
202 bool setValue(float value);
203
211 TGUI_NODISCARD float getValue() const;
212
218 void setStep(float step);
219
227 TGUI_NODISCARD float getStep() const;
228
235 void setDecimalPlaces(unsigned int decimalPlaces);
236
244 TGUI_NODISCARD unsigned int getDecimalPlaces() const;
245
253
261 TGUI_NODISCARD HorizontalAlignment getTextAlignment() const;
262
264 private:
266 // Helper function that initializes the widget when constructing a new widget or loading one from a file
268 void init();
269
271 // Checks whether a value lies between the minimum and maximum
273 bool inRange(const float value) const;
274
276 // Updates the text in the edit box
278 void setString(const String& str);
279
281 protected:
282
292 TGUI_NODISCARD Signal& getSignal(String signalName) override;
293
295 // Makes a copy of the widget
297 TGUI_NODISCARD Widget::Ptr clone() const override;
298
302 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
303
307 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
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:35
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 Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
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.
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.
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 Vector2f getFullSize() const override
Returns the full size of the combined edit box and slider.
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 HorizontalAlignment getTextAlignment() const
Returns the current text alignment of the edit box.
TGUI_NODISCARD float getStep() const
Returns the number of positions the thumb advances with each move.
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 SliderRenderer.hpp:35
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition Slider.hpp:42
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< const SubwidgetContainer > ConstPtr
Shared constant widget pointer.
Definition SubwidgetContainer.hpp:45
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:61