Skylicht Engine
Loading...
Searching...
No Matches
CUIListView.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 {
48 class CUIListView : public CUIBase
49 {
50 protected:
51 bool m_vertical;
52
53 CGUIMask* m_mask;
54
55 std::vector<CGUIElement*> m_allItems;
56 std::vector<CGUIElement*> m_visibleItems;
57
58 CGUIElement* m_listElement;
59 CGUIElement* m_baseItem;
60 CObjectSerializable* m_itemSerializable;
61
62 float m_offset;
63 float m_speed;
64
65 float m_lastPointerX;
66 float m_lastPointerY;
67 float m_pointerX;
68 float m_pointerY;
69
70 float m_maxOffset;
71 float m_springOffset;
72 float m_itemSpacing;
73
74 public:
84 CUIListView(CUIContainer* container, CGUIElement* element, CGUIElement* baseItem, CGUIElement* listElement = NULL);
85
86 virtual ~CUIListView();
87
95
102
107 {
108 return m_mask;
109 }
110
115 void enableMask(bool b);
116
123
140 void clear();
141
143 inline int getItemCount()
144 {
145 return (int)m_allItems.size();
146 }
147
154
155 virtual void update();
156
157 virtual void onPointerDown(int pointerId, float pointerX, float pointerY);
158
159 virtual void onPointerUp(int pointerId, float pointerX, float pointerY);
160
161 virtual void onPointerMove(int pointerId, float pointerX, float pointerY);
162
164 inline void setVertical(bool b)
165 {
166 m_vertical = b;
167 }
168
170 inline bool isVertical()
171 {
172 return m_vertical;
173 }
174
176 inline void setItemSpacing(float b)
177 {
178 m_itemSpacing = b;
179 }
180
182 inline float getItemSpacing()
183 {
184 return m_itemSpacing;
185 }
186
188 inline float getOffset()
189 {
190 return m_offset;
191 }
192
197 inline void setOffset(float offset)
198 {
199 m_speed = 0.0f;
200 m_offset = offset;
201 }
202
204 inline float getMaxOffset()
205 {
206 return m_maxOffset;
207 }
208
209 virtual bool acceptDragFocus()
210 {
211 return true;
212 }
213
214 protected:
215
222 virtual void updateLimitOffset();
223
229 virtual void updateItemPosition();
230
236 virtual void updateItemMovement();
237
239 virtual void updateInertia();
240
242 virtual void updateStopSpeed();
243 };
244 }
245}
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
Definition CObjectSerializable.h:36
CUIBase(CUIContainer *container, CGUIElement *element)
Constructor.
Top-level UI container and event router.
Definition CUIContainer.h:59
void setOffset(float offset)
Set content offset programmatically.
Definition CUIListView.h:197
virtual bool acceptDragFocus()
Whether this UI element should accept drag-focus when the pointer is already down and the user drags ...
Definition CUIListView.h:209
float getItemSpacing()
Get spacing between items.
Definition CUIListView.h:182
void enableMask(bool b)
Enable or disable visual masking for the list viewport.
virtual void updateStopSpeed()
Damp and stop the scrolling speed smoothly when near rest.
virtual void onPointerMove(int pointerId, float pointerX, float pointerY)
Called when pointer moves while over or dragging the element.
CGUIElement * getItem(int id)
Get item by index.
CGUIElement * addItem(CObjectSerializable *data)
Create a new item and attach data to it (using serialization template).
CGUIMask * getMask()
Get the current mask element used for clipping the list viewport.
Definition CUIListView.h:106
virtual void updateItemMovement()
Update item movement logic (applies m_speed, clamps and spring-back).
void clear()
Remove and destroy all child UI elements created from the list's base item.
int getItemCount()
Return number of items currently in the list.
Definition CUIListView.h:143
virtual void updateLimitOffset()
Update computed limits for allowable offset (m_maxOffset and related).
bool removeItem(CGUIElement *item)
Remove a specific item from the list, The function also remove and destroy all child UI elements crea...
void setVertical(bool b)
Set vertical layout mode.
Definition CUIListView.h:164
float getOffset()
Get current scroll offset.
Definition CUIListView.h:188
virtual void onPointerUp(int pointerId, float pointerX, float pointerY)
Called when pointer is released over the element.
float getMaxOffset()
Returns maximum computed offset (content size - viewport size).
Definition CUIListView.h:204
bool isVertical()
Returns true when layout is vertical.
Definition CUIListView.h:170
CGUIElement * addItem()
Create a new item using the m_baseItem template and append it to the list.
virtual void updateInertia()
Compute and apply inertia when the pointer is released and m_speed != 0.
virtual void onPointerDown(int pointerId, float pointerX, float pointerY)
Called when pointer is pressed down on the element.
CUIListView(CUIContainer *container, CGUIElement *element, CGUIElement *baseItem, CGUIElement *listElement=NULL)
Create a list view.
void setItemSpacing(float b)
Set spacing between items.
Definition CUIListView.h:176
virtual void updateItemPosition()
Recompute and apply item world/local positions based on m_offset.
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