Player12
An open source football management simulator
Loading...
Searching...
No Matches
Dropdown Class Reference

Represents a UI dropdown menu. More...

#include <dropdown.h>

Public Member Functions

 Dropdown (SDL_Renderer *dropdown_renderer, TTF_Font *dropdown_font, const SDL_FRect &rect, const std::vector< std::string > &dropdown_options)
 Constructs a new Dropdown.
 
 ~Dropdown ()
 Destroys the Dropdown.
 
 Dropdown (const Dropdown &)=delete
 
Dropdown & operator= (const Dropdown &)=delete
 
 Dropdown (Dropdown &&)=delete
 
Dropdown & operator= (Dropdown &&)=delete
 
bool handleEvent (const SDL_Event &event)
 Handles SDL events for the dropdown.
 
void render ()
 Renders the dropdown.
 
void update (float deltaTime)
 Updates the dropdown logic.
 
void close ()
 Closes the dropdown if it is open.
 
bool isDropdownOpen () const
 Checks if the dropdown is currently open.
 
int getSelectedIndex () const
 Gets the index of the currently selected option.
 
std::string getSelectedOption () const
 Gets the text of the currently selected option.
 
void setSelectedIndex (int index)
 Sets the selected option by index.
 
void setOnSelectionChanged (std::function< void(int, const std::string &)> callback)
 Sets the callback invoked when the selection changes.
 

Private Member Functions

void createTextures ()
 
void freeTextures ()
 
void renderArrow (const SDL_FRect &buttonRect) const
 

Private Attributes

SDL_Renderer * renderer
 
TTF_Font * font
 
SDL_FRect mainRect
 
std::vector< std::string > options
 
std::vector< SDL_FRect > optionRects
 
DropdownStyle style
 
bool isOpen = false
 
int selectedIndex = 0
 
int hoveredIndex = -1
 
SDL_Texture * selectedOptionTexture = nullptr
 
std::vector< SDL_Texture * > optionTextures
 
std::function< void(int, const std::string &)> onSelectionChangedCallback
 

Detailed Description

Represents a UI dropdown menu.

Constructor & Destructor Documentation

◆ Dropdown() [1/3]

Dropdown::Dropdown ( SDL_Renderer *  dropdown_renderer,
TTF_Font *  dropdown_font,
const SDL_FRect &  rect,
const std::vector< std::string > &  dropdown_options 
)

Constructs a new Dropdown.

Parameters
dropdown_rendererThe SDL renderer used for drawing.
dropdown_fontThe font used for text.
rectThe rectangle defining the dropdown's position and size.
dropdown_optionsThe list of string options in the dropdown.

◆ ~Dropdown()

Dropdown::~Dropdown ( )

Destroys the Dropdown.

◆ Dropdown() [2/3]

Dropdown::Dropdown ( const Dropdown &  )
delete

◆ Dropdown() [3/3]

Dropdown::Dropdown ( Dropdown &&  )
delete

Member Function Documentation

◆ close()

void Dropdown::close ( )

Closes the dropdown if it is open.

◆ createTextures()

void Dropdown::createTextures ( )
private

◆ freeTextures()

void Dropdown::freeTextures ( )
private

◆ getSelectedIndex()

int Dropdown::getSelectedIndex ( ) const

Gets the index of the currently selected option.

Returns
The selected index.

◆ getSelectedOption()

std::string Dropdown::getSelectedOption ( ) const

Gets the text of the currently selected option.

Returns
The selected string.

◆ handleEvent()

bool Dropdown::handleEvent ( const SDL_Event &  event)

Handles SDL events for the dropdown.

Parameters
eventThe SDL event to process.
Returns
True if the event was handled by the dropdown.

◆ isDropdownOpen()

bool Dropdown::isDropdownOpen ( ) const

Checks if the dropdown is currently open.

Returns
True if open, false otherwise.

◆ operator=() [1/2]

Dropdown & Dropdown::operator= ( const Dropdown &  )
delete

◆ operator=() [2/2]

Dropdown & Dropdown::operator= ( Dropdown &&  )
delete

◆ render()

void Dropdown::render ( )

Renders the dropdown.

◆ renderArrow()

void Dropdown::renderArrow ( const SDL_FRect &  buttonRect) const
private

◆ setOnSelectionChanged()

void Dropdown::setOnSelectionChanged ( std::function< void(int, const std::string &)>  callback)

Sets the callback invoked when the selection changes.

Parameters
callbackThe function to call, passing the new index and text.

◆ setSelectedIndex()

void Dropdown::setSelectedIndex ( int  index)

Sets the selected option by index.

Parameters
indexThe index to select.

◆ update()

void Dropdown::update ( float  deltaTime)

Updates the dropdown logic.

Parameters
deltaTimeThe time elapsed since the last update.

Member Data Documentation

◆ font

TTF_Font* Dropdown::font
private

◆ hoveredIndex

int Dropdown::hoveredIndex = -1
private

◆ isOpen

bool Dropdown::isOpen = false
private

◆ mainRect

SDL_FRect Dropdown::mainRect
private

◆ onSelectionChangedCallback

std::function<void(int, const std::string&)> Dropdown::onSelectionChangedCallback
private

◆ optionRects

std::vector<SDL_FRect> Dropdown::optionRects
private

◆ options

std::vector<std::string> Dropdown::options
private

◆ optionTextures

std::vector<SDL_Texture*> Dropdown::optionTextures
private

◆ renderer

SDL_Renderer* Dropdown::renderer
private

◆ selectedIndex

int Dropdown::selectedIndex = 0
private

◆ selectedOptionTexture

SDL_Texture* Dropdown::selectedOptionTexture = nullptr
private

◆ style

DropdownStyle Dropdown::style
private

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