TGUI  1.0-alpha
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
70 BitmapButton& operator=(const BitmapButton&);
71
75 BitmapButton& operator=(BitmapButton&&) noexcept;
76
77
85 static BitmapButton::Ptr create(const String& text = "");
86
87
93 static BitmapButton::Ptr copy(BitmapButton::ConstPtr button);
94
95
100 void setSize(const Layout2d& size) override;
101 using Widget::setSize;
102
103
108 void setImage(const Texture& image);
109
110
115 const Texture& getImage() const;
116
117
124 void setImageScaling(float relativeHeight);
125
126
132 float getImageScaling() const;
133
134
136 protected:
137
143 void rendererChanged(const String& property) override;
144
145
149 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
150
151
155 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
156
157
159 // Called when size of button is updated
161 void updateSize() override;
162
163
167 void initComponentsBitmapButton();
168
169
171 // Called whenever the text position might need to be updated
173 void updateTextPosition() override;
174
175
177 // Makes a copy of the widget
179 Widget::Ptr clone() const override;
180
181
183 private:
184
186 // Recalculates the glyph size based on the set relative glyph height
188 void recalculateGlyphSize();
189
190
192 private:
193
194 priv::dev::StyleProperty<Texture> icon;
195
196 // The component must be declared AFTER the style property
197 std::shared_ptr<priv::dev::ImageComponent> m_imageComponent;
198
199 float m_relativeGlyphHeight = 0;
200 };
201
203}
204
206
207#endif // TGUI_BITMAP_BUTTON_HPP
208
Button widget with an image displayed next to the text (or centered in the button without text)
Definition: BitmapButton.hpp:40
std::shared_ptr< const BitmapButton > ConstPtr
Shared constant widget pointer.
Definition: BitmapButton.hpp:44
BitmapButton(const BitmapButton &)
Copy constructor.
BitmapButton(BitmapButton &&) noexcept
Move constructor.
std::shared_ptr< BitmapButton > Ptr
Shared widget pointer.
Definition: BitmapButton.hpp:43
Button widget.
Definition: Button.hpp:39
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Wrapper class to store strings.
Definition: String.hpp:79
Definition: Texture.hpp:52
The parent class for every widget.
Definition: Widget.hpp:70
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
std::shared_ptr< const Widget > ConstPtr
Shared constant widget pointer.
Definition: Widget.hpp:74
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36