SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
ScrollList.h
1#ifndef ScrollList_H
2#define ScrollList_H
3
4#include "UIComponent.h"
5#include "Button.h"
6#include <vector>
7#include <string>
8#include "../Sprites/SUNENGINESprite.h"
9
29class ScrollList : public UIComponent
30{
31public:
39 ScrollList(float width, float height, float buttonWidth, float buttonHeight);
40 ScrollList(const ScrollList&) = delete;
41 ScrollList& operator=(const ScrollList&) = delete;
43
49 void AddButton(const std::string& label, UICommand* onPressCommand);
50
55 Button* GetButton(size_t index) const;
56
61 size_t GetButtonCount() const;
62
68 void SetPosition(float x, float y);
69
74 void Scroll(float offset);
75
80 void SetScrollSpeed(float speed);
81
82private:
84 std::vector<Button*> buttons;
85 float width;
86 float height;
90 float posX;
91 float posY;
93
97 void Render() override;
98
102 void OnPress() override;
103
110 bool IsMouseOver(float x, float y) override;
111
116};
117
118#endif // ScrollList_H
A clickable UI button component.
Definition Button.h:30
Represents a sprite in the SUNENGINE.
Definition Sprites/SUNENGINESprite.h:16
void SetPosition(float x, float y)
Sets the position of the scroll list.
Definition ScrollList.cpp:55
float posX
X-coordinate of the scroll list's position.
Definition ScrollList.h:90
void Render() override
Renders the scroll list and its buttons.
Definition ScrollList.cpp:78
float buttonHeight
Height of each button.
Definition ScrollList.h:88
void SetScrollSpeed(float speed)
Sets the scroll speed for the list.
Definition ScrollList.cpp:145
SUNENGINESprite * pSprite
Background sprite for the scroll list.
Definition ScrollList.h:83
float height
Height of the scroll list.
Definition ScrollList.h:86
float width
Width of the scroll list.
Definition ScrollList.h:85
Button * GetButton(size_t index) const
Gets the specified button.
Definition ScrollList.cpp:36
float scrollSpeed
Speed of scrolling (multiplier for scroll offset)
Definition ScrollList.h:92
size_t GetButtonCount() const
Gets the number of buttons in the scroll list.
Definition ScrollList.cpp:50
void OnPress() override
Handles press events on the scroll list (not typically used).
Definition ScrollList.cpp:95
void AddButton(const std::string &label, UICommand *onPressCommand)
Adds a button to the scroll list.
Definition ScrollList.cpp:26
ScrollList(float width, float height, float buttonWidth, float buttonHeight)
Constructs a ScrollList with specified dimensions and button sizes.
Definition ScrollList.cpp:6
void UpdateButtonPositions()
Updates the positions of the buttons based on the current scroll offset.
Definition ScrollList.cpp:150
bool IsMouseOver(float x, float y) override
Checks if the mouse is over the scroll list.
Definition ScrollList.cpp:118
void Scroll(float offset)
Scrolls the list by a given offset (typically in response to mouse wheel input).
Definition ScrollList.cpp:63
std::vector< Button * > buttons
List of buttons in the scroll list.
Definition ScrollList.h:84
float buttonWidth
Width of each button.
Definition ScrollList.h:87
float scrollOffset
Current scroll offset.
Definition ScrollList.h:89
float posY
Y-coordinate of the scroll list's position.
Definition ScrollList.h:91
Abstract base class for UI-related command objects.
Definition UICommand.h:32
Abstract base class for all UI components.
Definition UIComponent.h:32