4#include "UIComponent.h"
5#include "UIDirection.h"
16 Dropdown(
const std::string& textureKey,
const std::vector<std::string>& optionLabels);
17 Dropdown(
const std::string& textureKey);
18 Dropdown(
const Dropdown&) =
delete;
19 Dropdown& operator=(
const Dropdown&) =
delete;
28 void AddOption(
UIComponent* comp,
const std::string& value, UIDirection dir = UIDirection::Down);
76 friend class UIDropdownCommand;
std::vector< UIDirection > optionDirs
Directions for positioning each option.
Definition Dropdown.h:82
void SetScale(float x, float y)
Sets the scale of the dropdown.
Definition Dropdown.cpp:119
void ToggleDropdown()
Toggles the expanded/collapsed state of the dropdown.
Definition Dropdown.cpp:186
float scaleY
Y scale factor.
Definition Dropdown.h:89
UIComponent * GetHoveredItem(float x, float y)
Gets the option item currently hovered by the mouse.
Definition Dropdown.cpp:292
void Render() override
Renders the dropdown and its options.
Definition Dropdown.cpp:146
float posX
X position of the dropdown.
Definition Dropdown.h:86
void SetLayer(int layer) override
Sets the layer of the dropdown for rendering.
Definition Dropdown.cpp:138
float heldX
Last held/clicked X coordinate.
Definition Dropdown.h:91
void OnPress() override
Handles the press event on the dropdown.
Definition Dropdown.cpp:156
float heldY
Last held/clicked Y coordinate.
Definition Dropdown.h:92
std::vector< UIComponent * > optionItems
List of option UI components.
Definition Dropdown.h:80
void AddOption(UIComponent *comp, const std::string &value, UIDirection dir=UIDirection::Down)
Adds an option to the dropdown.
Definition Dropdown.cpp:43
std::vector< std::string > optionValues
Values associated with each option.
Definition Dropdown.h:81
float scaleX
X scale factor.
Definition Dropdown.h:88
std::string selectedValue
The currently selected value.
Definition Dropdown.h:94
const std::string & GetSelectedValue() const
Gets the currently selected value.
Definition Dropdown.cpp:106
Button * GetMainButton() const
Gets the main button of the dropdown.
Definition Dropdown.cpp:74
float posY
Y position of the dropdown.
Definition Dropdown.h:87
void SetOnSelectCommand(int index, UICommand *cmd)
Sets the command to be executed when an option is selected.
Definition Dropdown.cpp:86
void UpdateOptionTransforms()
Updates the transforms (position/scale) of the dropdown options.
Definition Dropdown.cpp:200
Button * mainButton
The main button that toggles the dropdown.
Definition Dropdown.h:78
UIDropdownCommand * selectCommand
Command for handling selection/toggle.
Definition Dropdown.h:79
bool IsMouseOver(float x, float y) override
Checks if the mouse is over the dropdown or its options.
Definition Dropdown.cpp:181
void SelectOption(int index)
Selects the option at the given index.
Definition Dropdown.cpp:191
UIComponent * GetComponent(int index) const
Gets the component at the specified index in the Dropdown.
Definition Dropdown.cpp:79
std::vector< UICommand * > ownedCommands
Commands owned and managed by the dropdown.
Definition Dropdown.h:83
bool isExpanded
Whether the dropdown is currently expanded.
Definition Dropdown.h:84
void SetPosition(float x, float y)
Sets the position of the dropdown.
Definition Dropdown.cpp:112
Abstract base class for UI-related command objects.
Definition UICommand.h:32
Abstract base class for all UI components.
Definition UIComponent.h:32
Command class for handling dropdown selection events.
Definition UIDropdownCommand.h:23