Skip to content

Dropdown

#include <Dropdown.hpp>

Inherits: Widget

A focusable widget that shows a popup list of options when opened.

ReturnNameDescription
Dropdown explicit
voidsetOptions inlineSets the list of options to display.
voidsetOnChange inlineSets the callback invoked when an option is selected.
voidsetPopupStyle inlineSets the style for the dropdown’s popup list.
voidsetPopupFocusedStyle inlineSets the style for the dropdown’s popup list when focused.
intselectedIndex const inline
const std::string &selectedValue const inline
intgetWidth const inlineGets the current width of the dropdown.
boolisFocusable virtual const inlineReturns whether this widget can receive keyboard focus.
core::Sizemeasure virtualMeasures how much space this widget needs.
boolonEvent virtualHandles an input event.
voidlayout virtualPositions and sizes this widget and its children.

explicit

explicit Dropdown(std::vector< Option > options)

inline

inline void setOptions(std::vector< Option > opts)

Sets the list of options to display.

  • opts The new list of options

inline

inline void setOnChange(std::function< void(int, const std::string &)> cb)

Sets the callback invoked when an option is selected.

  • cb The function to call when an option is selected

inline

inline void setPopupStyle(const core::Style & s)

Sets the style for the dropdown’s popup list.

  • s The style to apply to the popup

inline

inline void setPopupFocusedStyle(const core::Style & s)

Sets the style for the dropdown’s popup list when focused.

  • s The style to apply to the popup when focused

const inline

inline int selectedIndex() const

const inline

inline const std::string & selectedValue() const

const inline

inline int getWidth() const

Gets the current width of the dropdown.

the width in columns


virtual const inline

virtual inline bool isFocusable() const

Returns whether this widget can receive keyboard focus.

Widgets like Button and Input return true; containers return false.

True if this widget can be focused, false otherwise


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.

  • availW Maximum available width (may be ignored by widget)

  • availH Maximum available height (may be ignored by widget)

The Size this widget wants, or needs at minimum


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.

  • event The input event

True if this widget (or one of its listeners) handled the event


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.

  • x The X coordinate for this widget

  • y The Y coordinate for this widget

  • width The width allocated to this widget

  • height The height allocated to this widget

ReturnNameDescription
voiddrawContent virtualDraws this widget’s content.

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.

  • buf The buffer to draw to

  • inner The inner rectangle (excluding border/padding)

ReturnNameDescription
std::vector< Option >options
intselected
boolopen
core::StylepopupStyle
core::StylepopupFocusedStyle
std::function< void(int, const std::string &)>onChange

std::vector< Option > options

int selected = 0

bool open = false

core::Style popupStyle

core::Style popupFocusedStyle

std::function< void(int, const std::string &)> onChange
ReturnNameDescription
voidopenPopup
voidclosePopup

void openPopup()

void closePopup()