Skylicht Engine
Loading...
Searching...
No Matches
CUISlider.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 {
60 class CUISlider : public CUIBase
61 {
62 protected:
63 CGUIElement* m_background;
64 CGUIElement* m_fillBar;
65 CGUIElement* m_handle;
66 CGUIMask* m_mask;
67
68 CUIBase* m_bgHander;
69 CUIBase* m_buttonHander;
70
71 float m_value;
72 float m_handleWidth;
73
74 core::vector2df m_offset;
75
76 public:
89 std::function<void(CUISlider*, float)> OnChanged;
90
91 public:
101 CUISlider(CUIContainer* container, CGUIElement* element);
102
114 CUISlider(CUIContainer* container, CGUIElement* element, CGUIElement* bg, CGUIElement* fillbar, CGUIElement* handle);
115
116 virtual ~CUISlider();
117
126 void setValue(float value, bool invokeEvent = true);
127
129 inline float getValue()
130 {
131 return m_value;
132 }
133
134 protected:
135
144 void init();
145
152 virtual void onBeginDrag();
153
161 virtual void updateDrag();
162
168 virtual void onEndDrag();
169 };
170 }
171}
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 that represents a masked rectangle, and other GUIs will only display within ...
Definition CGUIMask.h:48
CUIBase(CUIContainer *container, CGUIElement *element)
Constructor.
Top-level UI container and event router.
Definition CUIContainer.h:59
void init()
Initialize internal state and locate child elements.
float getValue()
Get the current normalized slider value in range [0,1].
Definition CUISlider.h:129
virtual void updateDrag()
Update the slider value according to current pointer position.
virtual void onEndDrag()
Called when a drag ends (pointer up).
void setValue(float value, bool invokeEvent=true)
Set the slider value and optionally invoke the OnChanged event.
CUISlider(CUIContainer *container, CGUIElement *element)
Construct a slider that wraps an existing CGUIElement.
CUISlider(CUIContainer *container, CGUIElement *element, CGUIElement *bg, CGUIElement *fillbar, CGUIElement *handle)
Construct a slider with explicit sub-elements.
std::function< void(CUISlider *, float)> OnChanged
Event invoked when slider value changes.
Definition CUISlider.h:89
virtual void onBeginDrag()
Called when a drag begins (pointer down on handle).
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
vector2d< f32 > vector2df
Typedef for f32 2d vector.
Definition vector2d.h:323