Skip to main content

Class: UISelector

The UISelector class provides a UI component for selecting a single item from a grid. It highlights the selected item, supports optional callbacks on selection, and allows for custom name display during hold events.

The source file for this class is located in os/ui/UIComponents/UISelector.h.


Constructor​

UISelector​

UISelector(Dimension dimension, string name, Color color, uint16_t count, uint16_t* value, std::function<void(uint16_t)> callback = nullptr);

Creates a new UISelector component.

Parameters:

  • dimension (Dimension): The grid size of the selector.
  • name (string): The name of the selector, displayed during hold events.
  • color Color: The color for the selector.
  • count (uint16_t): The number of selectable items.
  • value (uint16_t*): Pointer to the variable that stores the currently selected item's index.
  • callback (std::function<void(uint16_t)>, optional): A callback function invoked when an item is selected. Defaults to nullptr.

Methods​

GetColor​

virtual Color GetColor();

Retrieves the color of the selector.

Returns:

  • Color: The color of the selector.

SetColor​

void SetColor(Color color);

Sets the color of the selector.

Parameters:

  • color Color: The new color for the selector.

GetSize​

virtual Dimension GetSize();

Calculates the dimensions of the selector grid.

Returns:

  • Dimension: The dimensions (width and height) of the selector.

Render​

virtual bool Render(Point origin);

Renders the selector grid, highlighting the currently selected item.

Parameters:

  • origin (Point): The top-left corner of the rendering area.

Returns:

  • bool: true if rendering was successful.

Behavior:

  • Items greater than the count are unlit.
  • The currently selected item is fully lit, while others are dimmed.

KeyEvent​

virtual bool KeyEvent(Point xy, KeyInfo* keyInfo);

Handles key events for selecting items and displaying the selector's name during hold events.

Parameters:

  • xy (Point): The position of the event relative to the selector grid.
  • keyInfo (KeyInfo*): Information about the key event.

Behavior:

  • Hold: Displays the name of the selector in a scrolling text format.
  • Released: Updates the value to the selected item's index and invokes the callback, if defined.

Returns:

  • bool: true to indicate the event was handled.

Comments