Skylicht Engine
Loading...
Searching...
No Matches
CUICheckbox.h
1/*
2!@
3MIT License
4
5Copyright (c) 2024 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "CUIBase.h"
28
29namespace Skylicht
30{
31 namespace UI
32 {
54 class CUICheckbox : public CUIBase
55 {
56 protected:
57 CGUIElement* m_background;
58 CGUIElement* m_checked;
59
60 bool m_toggleStatus;
61
62 CTween* m_tween;
63
64 public:
65
73 std::function<void(CUICheckbox*, bool)> OnChanged;
74
75 public:
84 CUICheckbox(CUIContainer* container, CGUIElement* element);
85
93 CUICheckbox(CUIContainer* container, CGUIElement* element, CGUIElement* bg, CGUIElement* checked);
94
95 virtual ~CUICheckbox();
96
104 virtual void onPressed();
105
112 void setToggle(bool b, bool invokeEvent = true, bool doAnimation = false);
113
118 inline bool isToggle()
119 {
120 return m_toggleStatus;
121 }
122
128 {
129 return m_background;
130 }
131
137 {
138 return m_checked;
139 }
140
141 protected:
142
149 void stopTween();
150
156 void playTween();
157 };
158 }
159}
This is the base object class from which other GUIs inherit. It's an empty GUI and can contain child ...
Definition CGUIElement.h:51
Definition CTween.h:11
CUIBase(CUIContainer *container, CGUIElement *element)
Constructor.
void playTween()
Start the tween animation for the checked/unchecked transition.
bool isToggle()
Query current checked state.
Definition CUICheckbox.h:118
CGUIElement * getChecked()
Get the checked element.
Definition CUICheckbox.h:136
void stopTween()
Stop and clear any active tween animation.
void setToggle(bool b, bool invokeEvent=true, bool doAnimation=false)
Set the checked state programmatically.
virtual void onPressed()
Called when the control is pressed.
CGUIElement * getBackground()
Get the background element.
Definition CUICheckbox.h:127
std::function< void(CUICheckbox *, bool)> OnChanged
Callback invoked when the checkbox state changes.
Definition CUICheckbox.h:73
CUICheckbox(CUIContainer *container, CGUIElement *element, CGUIElement *bg, CGUIElement *checked)
Create a checkbox with explicit background and checked elements.
CUICheckbox(CUIContainer *container, CGUIElement *element)
Create a checkbox bound to a container and element.
Top-level UI container and event router.
Definition CUIContainer.h:59
Classes used to build the User Interface (UI).
Definition CAlphaMotion.h:32
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29