TGUI 1.13
Loading...
Searching...
No Matches
BitmapButton.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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
32namespace tgui
33{
37 class TGUI_API BitmapButton : public Button
38 {
39 public:
40 using Ptr = std::shared_ptr<BitmapButton>;
41 using ConstPtr = std::shared_ptr<const BitmapButton>;
42
43 static constexpr char StaticWidgetType[] = "BitmapButton";
44
52 explicit BitmapButton(const char* typeName = StaticWidgetType, bool initRenderer = true);
53
57 BitmapButton(const BitmapButton& other);
58
62 BitmapButton(BitmapButton&& other) noexcept;
63
67 BitmapButton& operator=(const BitmapButton& other);
68
72 BitmapButton& operator=(BitmapButton&& other) noexcept;
73
81 [[nodiscard]] static BitmapButton::Ptr create(const String& text = "");
82
88 [[nodiscard]] static BitmapButton::Ptr copy(const BitmapButton::ConstPtr& button);
89
94 void setSize(const Layout2d& size) override;
95 using Widget::setSize;
96
101 void setImage(const Texture& image);
102
107 [[nodiscard]] const Texture& getImage() const;
108
115 void setImageScaling(float relativeHeight);
116
122 [[nodiscard]] float getImageScaling() const;
123
125
126 protected:
132 void rendererChanged(const String& property) override;
133
137 [[nodiscard]] std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
138
142 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
143
145 // Called when size of button is updated
147 void updateSize() override;
148
152 void initComponentsBitmapButton();
153
155 // Called whenever the text position might need to be updated
157 void updateTextPosition() override;
158
160 // Makes a copy of the widget
162 [[nodiscard]] Widget::Ptr clone() const override;
163
165
166 private:
168 // Recalculates the glyph size based on the set relative glyph height
170 void recalculateGlyphSize();
171
173
174 private:
175 priv::dev::StyleProperty<Texture> icon;
176
177 // The component must be declared AFTER the style property
178 std::shared_ptr<priv::dev::ImageComponent> m_imageComponent;
179
180 float m_relativeGlyphHeight = 0;
181 };
182} // namespace tgui
183
184#endif // TGUI_BITMAP_BUTTON_HPP
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
static BitmapButton::Ptr copy(const BitmapButton::ConstPtr &button)
Makes a copy of another button.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
BitmapButton & operator=(const BitmapButton &other)
Overload of copy assignment operator.
void setSize(const Layout2d &size) override
Changes the size of the button.
BitmapButton(BitmapButton &&other) noexcept
Move constructor.
BitmapButton(const BitmapButton &other)
Copy constructor.
std::shared_ptr< const BitmapButton > ConstPtr
Shared constant widget pointer.
Definition BitmapButton.hpp:41
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.
const Texture & getImage() const
Returns the image being displayed next to the text.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition BitmapButton.hpp:43
std::shared_ptr< BitmapButton > Ptr
Shared widget pointer.
Definition BitmapButton.hpp:40
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.
BitmapButton & operator=(BitmapButton &&other) noexcept
Move assignment.
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.
Class to store the position or size of a widget.
Definition Layout.hpp:320
Wrapper class to store strings.
Definition String.hpp:94
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:53
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:85
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37