TGUI 1.13
Loading...
Searching...
No Matches
CheckBox.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_CHECK_BOX_HPP
26#define TGUI_CHECK_BOX_HPP
27
28#include <TGUI/Renderers/CheckBoxRenderer.hpp>
29#include <TGUI/Widgets/RadioButton.hpp>
30
32
33namespace tgui
34{
38 class TGUI_API CheckBox : public RadioButton
39 {
40 public:
41 using Ptr = std::shared_ptr<CheckBox>;
42 using ConstPtr = std::shared_ptr<const CheckBox>;
43
44 static constexpr char StaticWidgetType[] = "CheckBox";
45
53 explicit CheckBox(const char* typeName = StaticWidgetType, bool initRenderer = true);
54
62 [[nodiscard]] static CheckBox::Ptr create(const String& text = "");
63
71 [[nodiscard]] static CheckBox::Ptr copy(const CheckBox::ConstPtr& checkbox);
72
77 [[nodiscard]] CheckBoxRenderer* getSharedRenderer() override;
78 [[nodiscard]] const CheckBoxRenderer* getSharedRenderer() const override;
79
85 [[nodiscard]] CheckBoxRenderer* getRenderer() override;
86
95 [[nodiscard]] Vector2f getFullSize() const override;
96
105 [[nodiscard]] Vector2f getWidgetOffset() const override;
106
113 void setChecked(bool checked) override;
114
118 void leftMouseReleased(Vector2f pos) override;
119
123 void keyPressed(const Event::KeyEvent& event) override;
124
134 bool canHandleKeyPress(const Event::KeyEvent& event) override;
135
142 void draw(BackendRenderTarget& target, RenderStates states) const override;
143
145
146 protected:
152 void rendererChanged(const String& property) override;
153
155 // Resets the sizes of the textures if they are used
157 void updateTextureSizes() override;
158
160 // Makes a copy of the widget
162 [[nodiscard]] Widget::Ptr clone() const override;
163
165
166 private:
167 Texture m_textureUncheckedCached;
168 Texture m_textureCheckedCached;
169 };
170} // namespace tgui
171
172#endif // TGUI_CHECK_BOX_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Renderer for the CheckBox widget.
Definition CheckBoxRenderer.hpp:38
CheckBoxRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
static CheckBox::Ptr copy(const CheckBox::ConstPtr &checkbox)
Makes a copy of another checkbox.
std::shared_ptr< const CheckBox > ConstPtr
Shared constant widget pointer.
Definition CheckBox.hpp:42
Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
void setChecked(bool checked) override
Checks or unchecks the check box.
CheckBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition CheckBox.hpp:44
Vector2f getFullSize() const override
Returns the full size of the radio button.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< CheckBox > Ptr
Shared widget pointer.
Definition CheckBox.hpp:41
static CheckBox::Ptr create(const String &text="")
Creates a new check box widget.
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
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
KeyPressed event parameters.
Definition Event.hpp:166
States used for drawing.
Definition RenderStates.hpp:38