TGUI  1.1
Loading...
Searching...
No Matches
BitmapButton.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
26#ifndef TGUI_BITMAP_BUTTON_HPP
27#define TGUI_BITMAP_BUTTON_HPP
28
29
30#include <TGUI/Widgets/Button.hpp>
31
33
34TGUI_MODULE_EXPORT namespace tgui
35{
39 class TGUI_API BitmapButton : public Button
40 {
41 public:
42
43 using Ptr = std::shared_ptr<BitmapButton>;
44 using ConstPtr = std::shared_ptr<const BitmapButton>;
45
46 static constexpr const char StaticWidgetType[] = "BitmapButton";
47
48
56 BitmapButton(const char* typeName = StaticWidgetType, bool initRenderer = true);
57
58
63
68
72 BitmapButton& operator=(const BitmapButton&);
73
77 BitmapButton& operator=(BitmapButton&&) noexcept;
78
79
87 TGUI_NODISCARD static BitmapButton::Ptr create(const String& text = "");
88
89
95 TGUI_NODISCARD static BitmapButton::Ptr copy(const BitmapButton::ConstPtr& button);
96
97
102 void setSize(const Layout2d& size) override;
103 using Widget::setSize;
104
105
110 void setImage(const Texture& image);
111
112
117 TGUI_NODISCARD const Texture& getImage() const;
118
119
126 void setImageScaling(float relativeHeight);
127
128
134 TGUI_NODISCARD float getImageScaling() const;
135
136
138 protected:
139
145 void rendererChanged(const String& property) override;
146
147
151 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
152
153
157 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
158
159
161 // Called when size of button is updated
163 void updateSize() override;
164
165
169 void initComponentsBitmapButton();
170
171
173 // Called whenever the text position might need to be updated
175 void updateTextPosition() override;
176
177
179 // Makes a copy of the widget
181 TGUI_NODISCARD Widget::Ptr clone() const override;
182
183
185 private:
186
188 // Recalculates the glyph size based on the set relative glyph height
190 void recalculateGlyphSize();
191
192
194 private:
195
196 priv::dev::StyleProperty<Texture> icon;
197
198 // The component must be declared AFTER the style property
199 std::shared_ptr<priv::dev::ImageComponent> m_imageComponent;
200
201 float m_relativeGlyphHeight = 0;
202 };
203
205}
206
208
209#endif // TGUI_BITMAP_BUTTON_HPP
210
Button widget with an image displayed next to the text (or centered in the button without text)
Definition BitmapButton.hpp:40
BitmapButton(const BitmapButton &)
Copy constructor.
std::shared_ptr< const BitmapButton > ConstPtr
Shared constant widget pointer.
Definition BitmapButton.hpp:44
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:305
Wrapper class to store strings.
Definition String.hpp:101
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:57
The parent class for every widget.
Definition Widget.hpp:84
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39