SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Dropdown Class Reference
Inheritance diagram for Dropdown:
Inheritance graph

Public Member Functions

 Dropdown (const std::string &textureKey, const std::vector< std::string > &optionLabels)
 
 Dropdown (const std::string &textureKey)
 
 Dropdown (const Dropdown &)=delete
 
Dropdownoperator= (const Dropdown &)=delete
 
void AddOption (UIComponent *comp, const std::string &value, UIDirection dir=UIDirection::Down)
 Adds an option to the dropdown.
 
void SetPosition (float x, float y)
 Sets the position of the dropdown.
 
void SetScale (float x, float y)
 Sets the scale of the dropdown.
 
void SetLayer (int layer) override
 Sets the layer of the dropdown for rendering.
 
void SetOnSelectCommand (int index, UICommand *cmd)
 Sets the command to be executed when an option is selected.
 
ButtonGetMainButton () const
 Gets the main button of the dropdown.
 
UIComponentGetComponent (int index) const
 Gets the component at the specified index in the Dropdown.
 
const std::string & GetSelectedValue () const
 Gets the currently selected value.
 
- Public Member Functions inherited from UIComponent
virtual ~UIComponent ()=default
 Virtual destructor.
 
int GetLayer () const
 Gets 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 dropdown and its options.
 
void OnPress () override
 Handles the press event on the dropdown.
 
bool IsMouseOver (float x, float y) override
 Checks if the mouse is over the dropdown or its options.
 
void ToggleDropdown ()
 Toggles the expanded/collapsed state of the dropdown.
 
void SelectOption (int index)
 Selects the option at the given index.
 
void UpdateOptionTransforms ()
 Updates the transforms (position/scale) of the dropdown options.
 
UIComponentGetHoveredItem (float x, float y)
 Gets the option item currently hovered by the mouse.
 

Private Attributes

ButtonmainButton
 The main button that toggles the dropdown.
 
UIDropdownCommandselectCommand
 Command for handling selection/toggle.
 
std::vector< UIComponent * > optionItems
 List of option UI components.
 
std::vector< std::string > optionValues
 Values associated with each option.
 
std::vector< UIDirection > optionDirs
 Directions for positioning each option.
 
std::vector< UICommand * > ownedCommands
 Commands owned and managed by the dropdown.
 
bool isExpanded
 Whether the dropdown is currently expanded.
 
float posX
 X position of the dropdown.
 
float posY
 Y position of the dropdown.
 
float scaleX
 X scale factor.
 
float scaleY
 Y scale factor.
 
float heldX
 Last held/clicked X coordinate.
 
float heldY
 Last held/clicked Y coordinate.
 
std::string selectedValue
 The currently selected value.
 

Friends

class UIDropdownCommand
 

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.
 

Member Function Documentation

◆ AddOption()

void Dropdown::AddOption ( UIComponent * comp,
const std::string & value,
UIDirection dir = UIDirection::Down )

Adds an option to the dropdown.

Parameters
compThe UIComponent to add (Button or Dropdown).
valueThe value associated with this option.
dirThe direction in which this option will be positioned relative to the main button.
Here is the call graph for this function:

◆ GetComponent()

UIComponent * Dropdown::GetComponent ( int index) const

Gets the component at the specified index in the Dropdown.

Returns
Pointer to the UI component.

◆ GetHoveredItem()

UIComponent * Dropdown::GetHoveredItem ( float x,
float y )
private

Gets the option item currently hovered by the mouse.

Parameters
xThe x-coordinate of the mouse.
yThe y-coordinate of the mouse.
Returns
Pointer to the hovered UIComponent, or nullptr if none.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMainButton()

Button * Dropdown::GetMainButton ( ) const

Gets the main button of the dropdown.

Returns
Pointer to the main button.

◆ GetSelectedValue()

const std::string & Dropdown::GetSelectedValue ( ) const

Gets the currently selected value.

Returns
The string value.

◆ IsMouseOver()

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

Checks if the mouse is over the dropdown or its options.

Parameters
xThe x-coordinate of the mouse.
yThe y-coordinate of the mouse.
Returns
True if the mouse is over the dropdown or its options, false otherwise.

Implements UIComponent.

Here is the call graph for this function:

◆ OnPress()

void Dropdown::OnPress ( )
overrideprivatevirtual

Handles the press event on the dropdown.

Implements UIComponent.

Here is the call graph for this function:

◆ Render()

void Dropdown::Render ( )
overrideprivatevirtual

Renders the dropdown and its options.

Implements UIComponent.

Here is the call graph for this function:

◆ SelectOption()

void Dropdown::SelectOption ( int index)
private

Selects the option at the given index.

Parameters
indexThe index of the option to select.
Here is the caller graph for this function:

◆ SetLayer()

void Dropdown::SetLayer ( int layer)
overridevirtual

Sets the layer of the dropdown for rendering.

Parameters
layerThe layer to set the dropdown to.

Reimplemented from UIComponent.

◆ SetOnSelectCommand()

void Dropdown::SetOnSelectCommand ( int index,
UICommand * cmd )

Sets the command to be executed when an option is selected.

Parameters
indexThe index of the option.
cmdThe command to execute on selection.
Here is the call graph for this function:

◆ SetPosition()

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

Sets the position of the dropdown.

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

◆ SetScale()

void Dropdown::SetScale ( float x,
float y )

Sets the scale of the dropdown.

Parameters
xThe x-scale factor.
yThe y-scale factor.
Here is the call graph for this function:
Here is the caller graph for this function:

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