Jazz2::UI::Menu::Widget class

Base class of a menu widget.

Building block of the declarative menu layout. A widget draws itself within a given rectangle, advances its animations, and optionally reacts to navigation or touch. Containers such as StackLayout and ScrollView arrange and drive their children, while leaves such as ListItem render content through the shared menu painters.

Derived classes

class CanvasWidget
Row drawn entirely by a caller-provided callback.
class ChoiceItem
Setting row that cycles through values.
class CustomValueItem
Setting row with a custom-drawn value.
class ListContainer
Base of vertical lists of selectable children.
class ListItem
Selectable text item.
class Slider
Setting row with a value bar adjusted left/right.
class TextInput
Editable text row.

Public static variables

static float LabelOffset constexpr
Distance of a row's label from the top of the row.

Constructors, destructors, conversion operators

Widget()
~Widget() virtual

Public functions

auto Blend(float compact, float full) const -> float
Blends a metric between its compact and full layout values for the view the widget is drawn in.
auto GetHeight() const -> float virtual
Returns the height the widget occupies in a vertical layout.
void OnUpdate(float timeMult) virtual
Advances the widget's animations.
void Draw(IMenuContainer* root, Canvas* canvas, const Rectf& bounds, std::int32_t& charOffset) virtual
Draws the widget within the given bounds.
auto OnNavigate(const WidgetInput& input, IMenuContainer* root) -> bool virtual
Handles navigation input; returns true if it was consumed.
auto OnTouchEvent(const nCine::TouchEvent& event, Vector2i viewSize, IMenuContainer* root) -> bool virtual
Handles a touch event; returns true if it was consumed.
void Activate(IMenuContainer* root) virtual
Called when the widget is activated (e.g., by Fire or a tap).
void OnSelected() virtual
Called when the widget becomes selected.
auto OnKeyPressed(const nCine::KeyboardEvent& event, IMenuContainer* root) -> bool virtual
Handles a key press while capturing text input; returns true if consumed.
void OnTextInput(const nCine::TextInputEvent& event) virtual
Handles a text input event while capturing text input.
auto IsCapturingInput() const -> bool virtual
Returns true while the widget (or a descendant) is capturing raw text input, which restricts navigation.

Public variables

Rectf Bounds
Rectangle the widget was last drawn in (used for touch hit-testing).
bool Focusable
Whether the widget can receive selection.
bool Selected
Whether the widget is currently selected (set by the parent before drawing).
bool Visible
Whether the widget is laid out and drawn.
float MarginTop
Extra space a vertical layout leaves above the widget (in addition to GetHeight()).
float LayoutTransition
How far the view is from the compact layout towards the full one (0 to 1, see MenuLayout::GetTransition()).

Variable documentation

static float Jazz2::UI::Menu::Widget::LabelOffset constexpr

Distance of a row's label from the top of the row.

Every labelled row (ChoiceItem, Slider, TextInput, CustomValueItem) puts its label here and whatever it shows underneath below it, whatever its own height, so the first row of every section starts at the same distance from the frame - it is also where a default-height ListItem centers its text. Rows used to center the label instead, which put a taller row's label visibly lower than a list's. A row that tightens up on a compact view (see LayoutTransition) moves its label up by a share of the removed height, so it keeps step with the compact ListItem rows, which center at 16.

float Jazz2::UI::Menu::Widget::LayoutTransition

How far the view is from the compact layout towards the full one (0 to 1, see MenuLayout::GetTransition()).

Set by the containing list before it measures its children each frame, so a row can size itself for the view it is drawn in: the labelled rows (Slider, ChoiceItem) tighten up on a handheld's 240-row view, where their full-layout heights fit only two of them at a time.