Class: UINumItemSelector
The UINumItemSelector
class is a numeric item selection UI component that highlights all items less than or equal to the selected value, providing a cascading visual effect. This makes it ideal for range-based selection scenarios.
The source file for this class is located in os/ui/UIComponents/UINumItemSelector.h.
Constructor​
UINumItemSelector
​
UINumItemSelector(Dimension dimension, Color color, uint16_t* output, uint16_t count, std::function<void(T)> callback = nullptr);
Creates a new numeric item selector UI component.
Template Parameter:
T
: The data type of the selectable items.
Parameters:
dimension
(Dimension
): The grid size of the item selector.color
Color
: The color for the selector.output
(uint16_t*
): Pointer to the variable that stores the selected item's index.count
(uint16_t
): The number of items in the selector.callback
(std::function<void(T)>
, optional): A callback function invoked when an item is selected. Defaults tonullptr
.
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
andheight
) of the selector.
Render
​
virtual bool Render(Point origin);
Renders the selector grid, highlighting items less than or equal to the selected value.
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.
- Items less than or equal to the selected value are fully lit, while others are dimmed.
KeyEvent
​
virtual bool KeyEvent(Point xy, KeyInfo* keyInfo);
Handles key events for selecting items.
Parameters:
xy
(Point
): The position of the event relative to the selector grid.keyInfo
(KeyInfo*
): Information about the key event.
Behavior:
- Pressed: Updates the
output
value and invokes thecallback
, if defined.
Returns:
bool
:true
to indicate the event was handled.
Comments