Skylicht Engine
Loading...
Searching...
No Matches
CUISwitch.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 CUISwitch : public CUIBase
55 {
56 protected:
57 CGUIElement* m_background;
58 CGUIElement* m_on;
59 CGUIElement* m_handle;
60
61 bool m_toggleStatus;
62
63 core::vector3df m_onPosition;
64 core::vector3df m_offPosition;
65
66 CTween* m_tween;
67
68 SColor m_onColor;
69 SColor m_offColor;
70
71 public:
72
81 std::function<void(CUISwitch*, bool)> OnChanged;
82
83 public:
93 CUISwitch(CUIContainer* container, CGUIElement* element);
94
103 CUISwitch(CUIContainer* container, CGUIElement* element, CGUIElement* bg, CGUIElement* handle, CGUIElement* on);
104
105 virtual ~CUISwitch();
106
107 virtual void onPressed();
108
120 void setToggle(bool b, bool invokeEvent = true, bool doAnimation = false);
121
123 inline bool isToggle()
124 {
125 return m_toggleStatus;
126 }
127
133 void setHandleColor(const SColor& on, const SColor& off)
134 {
135 m_onColor = on;
136 m_offColor = off;
137 }
138
141 {
142 return m_background;
143 }
144
147 {
148 return m_handle;
149 }
150
151 protected:
153 void stopTween();
154
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.
Top-level UI container and event router.
Definition CUIContainer.h:59
virtual void onPressed()
Called when the element is considered "pressed" (high-level event). Subclasses may trigger OnPressed ...
CUISwitch(CUIContainer *container, CGUIElement *element, CGUIElement *bg, CGUIElement *handle, CGUIElement *on)
Construct a switch using explicit sub-elements.
CGUIElement * getBackground()
Get the background GUI element.
Definition CUISwitch.h:140
std::function< void(CUISwitch *, bool)> OnChanged
Callback invoked when the toggle state changes.
Definition CUISwitch.h:81
CGUIElement * getHandle()
Get the handle GUI element.
Definition CUISwitch.h:146
CUISwitch(CUIContainer *container, CGUIElement *element)
Construct a switch from a root CGUIElement.
void setToggle(bool b, bool invokeEvent=true, bool doAnimation=false)
Set the toggle state programmatically.
bool isToggle()
Returns current toggle state.
Definition CUISwitch.h:123
void setHandleColor(const SColor &on, const SColor &off)
Set colors used for the handle in on/off states.
Definition CUISwitch.h:133
Class representing a 32 bit ARGB color.
Definition SColor.h:285
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
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445