TGUI  0.10-beta
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 void setImage(const Texture& image);
114
115
120 const Texture& getImage() const;
121
122
129 void setImageScaling(float relativeHeight);
130
131
137 float getImageScaling() const;
138
139
141 protected:
142
148 void rendererChanged(const String& property) override;
149
150
154 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
155
156
160 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
161
162
164 // Called when size of button is updated
166 void updateSize() override;
167
168
172 void initComponentsBitmapButton();
173
174
178 void updateComponentPositions();
179
180
182 // Makes a copy of the widget
184 Widget::Ptr clone() const override;
185
186
188 private:
189
191 // Recalculates the glyph size based on the set relative glyph height
193 void recalculateGlyphSize();
194
195
197 private:
198
199 priv::dev::StyleProperty<Texture> icon;
200
201 // The component must be declared AFTER the style property
202 std::shared_ptr<priv::dev::ImageComponent> m_imageComponent;
203
204 float m_relativeGlyphHeight = 0;
205
206 std::uint64_t m_textStyleChangedCallbackId = 0;
207 };
208
210}
211
213
214#endif // TGUI_BITMAP_BUTTON_HPP
215
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.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
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:284
Wrapper class to store strings.
Definition: String.hpp:79
Definition: Texture.hpp:52
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36