Dropdown
Dropdown
Section titled “Dropdown”#include <Dropdown.hpp>Inherits:
Widget
A focusable widget that shows a popup list of options when opened.
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
Dropdown explicit | ||
void | setOptions inline | Sets the list of options to display. |
void | setOnChange inline | Sets the callback invoked when an option is selected. |
void | setPopupStyle inline | Sets the style for the dropdown’s popup list. |
void | setPopupFocusedStyle inline | Sets the style for the dropdown’s popup list when focused. |
int | selectedIndex const inline | |
const std::string & | selectedValue const inline | |
int | getWidth const inline | Gets the current width of the dropdown. |
bool | isFocusable virtual const inline | Returns whether this widget can receive keyboard focus. |
core::Size | measure virtual | Measures how much space this widget needs. |
bool | onEvent virtual | Handles an input event. |
void | layout virtual | Positions and sizes this widget and its children. |
Dropdown
Section titled “Dropdown”explicit
explicit Dropdown(std::vector< Option > options)setOptions
Section titled “setOptions”inline
inline void setOptions(std::vector< Option > opts)Sets the list of options to display.
Parameters
Section titled “Parameters”optsThe new list of options
setOnChange
Section titled “setOnChange”inline
inline void setOnChange(std::function< void(int, const std::string &)> cb)Sets the callback invoked when an option is selected.
Parameters
Section titled “Parameters”cbThe function to call when an option is selected
setPopupStyle
Section titled “setPopupStyle”inline
inline void setPopupStyle(const core::Style & s)Sets the style for the dropdown’s popup list.
Parameters
Section titled “Parameters”sThe style to apply to the popup
setPopupFocusedStyle
Section titled “setPopupFocusedStyle”inline
inline void setPopupFocusedStyle(const core::Style & s)Sets the style for the dropdown’s popup list when focused.
Parameters
Section titled “Parameters”sThe style to apply to the popup when focused
selectedIndex
Section titled “selectedIndex”const inline
inline int selectedIndex() constselectedValue
Section titled “selectedValue”const inline
inline const std::string & selectedValue() constgetWidth
Section titled “getWidth”const inline
inline int getWidth() constGets the current width of the dropdown.
Returns
Section titled “Returns”the width in columns
isFocusable
Section titled “isFocusable”virtual const inline
virtual inline bool isFocusable() constReturns whether this widget can receive keyboard focus.
Widgets like Button and Input return true; containers return false.
Returns
Section titled “Returns”True if this widget can be focused, false otherwise
measure
Section titled “measure”virtual
virtual core::Size measure(int availW, int availH)Measures how much space this widget needs.
Called during the measurement pass to determine widget size requirements. Should return the preferred size based on available space.
Parameters
Section titled “Parameters”-
availWMaximum available width (may be ignored by widget) -
availHMaximum available height (may be ignored by widget)
Returns
Section titled “Returns”The Size this widget wants, or needs at minimum
onEvent
Section titled “onEvent”virtual
virtual bool onEvent(const core::events::Event & event)Handles an input event.
Called by the framework to deliver an event to this widget. The default implementation runs any listeners registered via addEventListener(), then returns false. Subclasses (Button, Input, etc.) override this to add built-in behavior, and should call Widget::onEvent(event) first to give user listeners a chance to handle the event before the widget’s own logic.
Return true if the event was handled, false to let it bubble to the parent widget.
Parameters
Section titled “Parameters”eventThe input event
Returns
Section titled “Returns”True if this widget (or one of its listeners) handled the event
layout
Section titled “layout”virtual
virtual void layout(int x, int y, int width, int height)Positions and sizes this widget and its children.
Called after measurement to actually place the widget at a specific location. If your widget has children, you must call their layout() methods here.
Parameters
Section titled “Parameters”-
xThe X coordinate for this widget -
yThe Y coordinate for this widget -
widthThe width allocated to this widget -
heightThe height allocated to this widget
Protected Methods
Section titled “Protected Methods”| Return | Name | Description |
|---|---|---|
void | drawContent virtual | Draws this widget’s content. |
drawContent
Section titled “drawContent”virtual
virtual void drawContent(backend::Buffer & buf, core::Rect inner)Draws this widget’s content.
Called by render() after background and borders are drawn. This is where you should draw your widget’s actual content. The inner rectangle accounts for borders and padding.
Parameters
Section titled “Parameters”-
bufThe buffer to draw to -
innerThe inner rectangle (excluding border/padding)
Private Attributes
Section titled “Private Attributes”| Return | Name | Description |
|---|---|---|
std::vector< Option > | options | |
int | selected | |
bool | open | |
core::Style | popupStyle | |
core::Style | popupFocusedStyle | |
std::function< void(int, const std::string &)> | onChange |
options
Section titled “options”std::vector< Option > optionsselected
Section titled “selected”int selected = 0bool open = falsepopupStyle
Section titled “popupStyle”core::Style popupStylepopupFocusedStyle
Section titled “popupFocusedStyle”core::Style popupFocusedStyleonChange
Section titled “onChange”std::function< void(int, const std::string &)> onChangePrivate Methods
Section titled “Private Methods”| Return | Name | Description |
|---|---|---|
void | openPopup | |
void | closePopup |
openPopup
Section titled “openPopup”void openPopup()closePopup
Section titled “closePopup”void closePopup()