Skylicht Engine
Loading...
Searching...
No Matches
CUIButton.h
1/*
2!@
3MIT License
4
5Copyright (c) 2023 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 {
47 class CUIButton : public CUIBase
48 {
49 protected:
50 CGUIElement* m_background;
51 CGUIText* m_text;
52
53 bool m_isToggle;
54 bool m_toggleStatus;
55
56 public:
57
63 std::function<void(CUIBase*, bool)> OnToggle;
64
65 public:
74 CUIButton(CUIContainer* container, CGUIElement* element);
75
83 CUIButton(CUIContainer* container, CGUIElement* element, CGUIElement* bg, CGUIText* text);
84
85 virtual ~CUIButton();
86
91 void setLabel(const char* string);
92
97 void setLabel(const wchar_t* string);
98
106 void setLabelAndChangeWidth(const char* string, float addition);
107
113 void setLabelAndChangeWidth(const wchar_t* string, float addition);
114
115 virtual void onPointerHover(int pointerId, float pointerX, float pointerY);
116
117 virtual void onPointerOut(int pointerId, float pointerX, float pointerY);
118
119 virtual void onPressed();
120
125 inline void setToggleButton(bool b)
126 {
127 m_isToggle = b;
128 }
129
134 inline bool isToggleButton()
135 {
136 return m_isToggle;
137 }
138
144 virtual void setToggle(bool b, bool invokeEvent = true);
145
147 inline bool isToggle()
148 {
149 return m_toggleStatus;
150 }
151
154 {
155 return m_background;
156 }
157
160 {
161 return m_text;
162 }
163 };
164 }
165}
This is the base object class from which other GUIs inherit. It's an empty GUI and can contain child ...
Definition CGUIElement.h:51
This is the object class for displaying a text.
Definition CGUIText.h:60
CUIBase(CUIContainer *container, CGUIElement *element)
Constructor.
void setLabelAndChangeWidth(const char *string, float addition)
Set the label and adjust the button width by addition units.
CUIButton(CUIContainer *container, CGUIElement *element, CGUIElement *bg, CGUIText *text)
Construct a button with explicit background and text elements.
CUIButton(CUIContainer *container, CGUIElement *element)
Construct a button bound to a container and element.
bool isToggleButton()
Query whether the button is configured as a toggle.
Definition CUIButton.h:134
virtual void setToggle(bool b, bool invokeEvent=true)
Set the toggle state programmatically.
CGUIElement * getBackground()
Get the background element (may be nullptr).
Definition CUIButton.h:153
void setToggleButton(bool b)
Enable or disable toggle mode for this button.
Definition CUIButton.h:125
virtual void onPressed()
Called when the element is considered "pressed" (high-level event). Subclasses may trigger OnPressed ...
void setLabel(const wchar_t *string)
Set the button label using a wide character string.
std::function< void(CUIBase *, bool)> OnToggle
Callback invoked when the button toggle state changes.
Definition CUIButton.h:63
bool isToggle()
Returns current toggle state.
Definition CUIButton.h:147
void setLabelAndChangeWidth(const wchar_t *string, float addition)
Set the label (wide chars) and adjust the button width by addition units.
virtual void onPointerHover(int pointerId, float pointerX, float pointerY)
Called when pointer enters or hovers over the element.
CGUIText * getText()
Get the text element used as label (may be nullptr).
Definition CUIButton.h:159
void setLabel(const char *string)
Set the button label using a UTF-8 char string.
virtual void onPointerOut(int pointerId, float pointerX, float pointerY)
Called when pointer leaves the 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