TGUI  1.6.1
Loading...
Searching...
No Matches
BitmapButton.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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_BITMAP_BUTTON_HPP
26#define TGUI_BITMAP_BUTTON_HPP
27
28#include <TGUI/Widgets/Button.hpp>
29
31
32TGUI_MODULE_EXPORT namespace tgui
33{
37 class TGUI_API BitmapButton : public Button
38 {
39 public:
40
41 using Ptr = std::shared_ptr<BitmapButton>;
42 using ConstPtr = std::shared_ptr<const BitmapButton>;
43
44 static constexpr const char StaticWidgetType[] = "BitmapButton";
45
53 BitmapButton(const char* typeName = StaticWidgetType, bool initRenderer = true);
54
59
64
68 BitmapButton& operator=(const BitmapButton&);
69
73 BitmapButton& operator=(BitmapButton&&) noexcept;
74
82 TGUI_NODISCARD static BitmapButton::Ptr create(const String& text = "");
83
89 TGUI_NODISCARD static BitmapButton::Ptr copy(const BitmapButton::ConstPtr& button);
90
95 void setSize(const Layout2d& size) override;
96 using Widget::setSize;
97
102 void setImage(const Texture& image);
103
108 TGUI_NODISCARD const Texture& getImage() const;
109
116 void setImageScaling(float relativeHeight);
117
123 TGUI_NODISCARD float getImageScaling() const;
124
126 protected:
127
133 void rendererChanged(const String& property) override;
134
138 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
139
143 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
144
146 // Called when size of button is updated
148 void updateSize() override;
149
153 void initComponentsBitmapButton();
154
156 // Called whenever the text position might need to be updated
158 void updateTextPosition() override;
159
161 // Makes a copy of the widget
163 TGUI_NODISCARD Widget::Ptr clone() const override;
164
166 private:
167
169 // Recalculates the glyph size based on the set relative glyph height
171 void recalculateGlyphSize();
172
174 private:
175
176 priv::dev::StyleProperty<Texture> icon;
177
178 // The component must be declared AFTER the style property
179 std::shared_ptr<priv::dev::ImageComponent> m_imageComponent;
180
181 float m_relativeGlyphHeight = 0;
182 };
183
185}
186
188
189#endif // TGUI_BITMAP_BUTTON_HPP
190
Button widget with an image displayed next to the text (or centered in the button without text)
Definition BitmapButton.hpp:38
BitmapButton(const BitmapButton &)
Copy constructor.
std::shared_ptr< const BitmapButton > ConstPtr
Shared constant widget pointer.
Definition BitmapButton.hpp:42
BitmapButton(BitmapButton &&) noexcept
Move constructor.
std::shared_ptr< BitmapButton > Ptr
Shared widget pointer.
Definition BitmapButton.hpp:41
Button widget.
Definition Button.hpp:38
Class to store the position or size of a widget.
Definition Layout.hpp:323
Wrapper class to store strings.
Definition String.hpp:96
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:83
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38