SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
ScrollList Class Reference

A scrollable list of UI buttons. More...

#include <ScrollList.h>

Inheritance diagram for ScrollList:
Inheritance graph

Public Member Functions

 ScrollList (float width, float height, float buttonWidth, float buttonHeight)
 Constructs a ScrollList with specified dimensions and button sizes.
 
 ScrollList (const ScrollList &)=delete
 
ScrollListoperator= (const ScrollList &)=delete
 
void AddButton (const std::string &label, UICommand *onPressCommand)
 Adds a button to the scroll list.
 
ButtonGetButton (size_t index) const
 Gets the specified button.
 
size_t GetButtonCount () const
 Gets the number of buttons in the scroll list.
 
void SetPosition (float x, float y)
 Sets the position of the scroll list.
 
void Scroll (float offset)
 Scrolls the list by a given offset (typically in response to mouse wheel input).
 
void SetScrollSpeed (float speed)
 Sets the scroll speed for the list.
 
- Public Member Functions inherited from UIComponent
virtual ~UIComponent ()=default
 Virtual destructor.
 
int GetLayer () const
 Gets the rendering layer of the component.
 
virtual void SetLayer (int layer)
 Sets the rendering layer of the component.
 
UIComponentType GetType () const
 Gets the type of the UI component.
 
bool IsEnabled () const
 Returns whether the component is enabled or not.
 
void SetEnabled (bool enabled)
 Sets the enabled state of the component.
 
void SetOwningCanvas (Canvas *canvas)
 Gets the owning canvas of the component.
 

Private Member Functions

void Render () override
 Renders the scroll list and its buttons.
 
void OnPress () override
 Handles press events on the scroll list (not typically used).
 
bool IsMouseOver (float x, float y) override
 Checks if the mouse is over the scroll list.
 
void UpdateButtonPositions ()
 Updates the positions of the buttons based on the current scroll offset.
 

Private Attributes

SUNENGINESpritepSprite
 Background sprite for the scroll list.
 
std::vector< Button * > buttons
 List of buttons in the scroll list.
 
float width
 Width of the scroll list.
 
float height
 Height of the scroll list.
 
float buttonWidth
 Width of each button.
 
float buttonHeight
 Height of each button.
 
float scrollOffset
 Current scroll offset.
 
float posX
 X-coordinate of the scroll list's position.
 
float posY
 Y-coordinate of the scroll list's position.
 
float scrollSpeed
 Speed of scrolling (multiplier for scroll offset)
 

Additional Inherited Members

- Protected Attributes inherited from UIComponent
bool Enabled = true
 Indicates if the component is enabled or not.
 
int Layer = 0
 Rendering layer in.
 
UIComponentType Type = UIComponentType::None
 Type of the UI component.
 
CanvaspOwningCanvas = nullptr
 Pointer to the owning canvas, if any.
 

Detailed Description

A scrollable list of UI buttons.

The ScrollList class provides a vertical list of buttons that can be scrolled if the content exceeds the visible area. It is useful for displaying selectable options, menus, or lists within a UI. Each button can have its own label and command. The ScrollList handles rendering only the visible buttons and manages their positions as the user scrolls.

Example usage:

ScrollList* list = new ScrollList(200.0f, 400.0f, 180.0f, 40.0f);
list->SetPosition(300.0f, 300.0f);
list->AddButton("Option 1", new MyCommand());
list->AddButton("Option 2", nullptr);
canvas->AddComponent(list);
void SetPosition(float x, float y)
Sets the position of the scroll list.
Definition ScrollList.cpp:55
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
See also
Button, Canvas, UICommand

Constructor & Destructor Documentation

◆ ScrollList()

ScrollList::ScrollList ( float width,
float height,
float buttonWidth,
float buttonHeight )

Constructs a ScrollList with specified dimensions and button sizes.

Parameters
widthThe width of the scroll list in pixels.
heightThe height of the scroll list in pixels.
buttonWidthThe width of each button in pixels.
buttonHeightThe height of each button in pixels.

Member Function Documentation

◆ AddButton()

void ScrollList::AddButton ( const std::string & label,
UICommand * onPressCommand )

Adds a button to the scroll list.

Parameters
labelThe label for the button.
onPressCommandThe command to execute when the button is pressed.
Here is the call graph for this function:

◆ GetButton()

Button * ScrollList::GetButton ( size_t index) const

Gets the specified button.

Returns
The button at the given index.

◆ GetButtonCount()

size_t ScrollList::GetButtonCount ( ) const

Gets the number of buttons in the scroll list.

Returns
The count of buttons in the scroll list.

◆ IsMouseOver()

bool ScrollList::IsMouseOver ( float x,
float y )
overrideprivatevirtual

Checks if the mouse is over the scroll list.

Parameters
xThe x-coordinate of the mouse position.
yThe y-coordinate of the mouse position.
Returns
True if the mouse is over the scroll list, false otherwise.

Implements UIComponent.

Here is the call graph for this function:

◆ OnPress()

void ScrollList::OnPress ( )
overrideprivatevirtual

Handles press events on the scroll list (not typically used).

Implements UIComponent.

Here is the call graph for this function:

◆ Render()

void ScrollList::Render ( )
overrideprivatevirtual

Renders the scroll list and its buttons.

Implements UIComponent.

Here is the call graph for this function:

◆ Scroll()

void ScrollList::Scroll ( float offset)

Scrolls the list by a given offset (typically in response to mouse wheel input).

Parameters
offsetThe scroll offset; positive or negative to scroll up or down.
Here is the call graph for this function:

◆ SetPosition()

void ScrollList::SetPosition ( float x,
float y )

Sets the position of the scroll list.

Parameters
xThe x-coordinate of the scroll list's position.
yThe y-coordinate of the scroll list's position.
Here is the call graph for this function:

◆ SetScrollSpeed()

void ScrollList::SetScrollSpeed ( float speed)

Sets the scroll speed for the list.

Parameters
speedThe scroll speed multiplier.

The documentation for this class was generated from the following files: