TGUI  0.9.5
Loading...
Searching...
No Matches
BitmapButton.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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_BITMAP_BUTTON_HPP
27#define TGUI_BITMAP_BUTTON_HPP
28
29
30#include <TGUI/Widgets/Button.hpp>
31
33
34namespace tgui
35{
39 class TGUI_API BitmapButton : public Button
40 {
41 public:
42
43 typedef std::shared_ptr<BitmapButton> Ptr;
44 typedef std::shared_ptr<const BitmapButton> ConstPtr;
45
46
54 BitmapButton(const char* typeName = "BitmapButton", bool initRenderer = true);
55
56
61
66
71
76
81
82
90 static BitmapButton::Ptr create(const String& text = "");
91
92
99
100
105 void setSize(const Layout2d& size) override;
106 using Widget::setSize;
107
108
113 virtual void setText(const String& text) override;
114
115
120 void setImage(const Texture& image);
121
122
127 const Texture& getImage() const;
128
129
136 void setImageScaling(float relativeHeight);
137
138
144 float getImageScaling() const;
145
146
148 protected:
149
155 void rendererChanged(const String& property) override;
156
157
161 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
162
163
167 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
168
169
171 // Called when size of button is updated
173 void updateSize() override;
174
175
179 void initComponentsBitmapButton();
180
181
185 void updateComponentPositions();
186
187
189 // Makes a copy of the widget
191 Widget::Ptr clone() const override
192 {
193 return std::make_shared<BitmapButton>(*this);
194 }
195
196
198 private:
199
201 // Recalculates the glyph size based on the set relative glyph height
203 void recalculateGlyphSize();
204
205
207 private:
208
209 priv::dev::StyleProperty<Texture> icon;
210
211 // The component must be declared AFTER the style property
212 std::shared_ptr<priv::dev::ImageComponent> m_imageComponent;
213
214 float m_relativeGlyphHeight = 0;
215
216 std::uint64_t m_textStyleChangedCallbackId = 0;
217 };
218
220}
221
223
224#endif // TGUI_BITMAP_BUTTON_HPP
225
Button widget with an image displayed next to the text (or centered in the button without text)
Definition BitmapButton.hpp:40
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition BitmapButton.hpp:191
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
virtual void setText(const String &text) override
Changes the caption of the button.
std::shared_ptr< const BitmapButton > ConstPtr
Shared constant widget pointer.
Definition BitmapButton.hpp:44
BitmapButton(BitmapButton &&)
Move constructor.
void setSize(const Layout2d &size) override
Changes the size of the button.
BitmapButton(const BitmapButton &)
Copy constructor.
static BitmapButton::Ptr copy(BitmapButton::ConstPtr button)
Makes a copy of another button.
BitmapButton & operator=(const BitmapButton &)
Overload of copy assignment operator.
void setImageScaling(float relativeHeight)
Sets the relative size of the image to display next to the text.
void setImage(const Texture &image)
Sets the image that should be displayed next to the text.
~BitmapButton()
Destructor.
const Texture & getImage() const
Returns the image being displayed next to the text.
BitmapButton & operator=(BitmapButton &&)
Move assignment.
std::shared_ptr< BitmapButton > Ptr
Shared widget pointer.
Definition BitmapButton.hpp:43
float getImageScaling() const
Returns the relative size of the image displayed next to the text.
static BitmapButton::Ptr create(const String &text="")
Creates a new bitmap button widget.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
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.
Button widget.
Definition Button.hpp:39
Class to store the position or size of a widget.
Definition Layout.hpp:262
Wrapper class to store strings.
Definition String.hpp:79
Definition Texture.hpp:49
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36