21 const auto n = count();
22 index = n == 0 ? 0 : std::min(i, n - 1);
27 const auto n = count();
35 std::size_t next_index = index;
38 next_index = index + 1;
44 next_index = index - 1;
50 if (next_index != index) {
96 text = index < options.size() ? options[index] : std::string {};
97 texture = index < images.size() ? images[index] :
asw::Texture {};
102 if (!show_arrows || !adjusts_left_right() || text.empty() || f ==
nullptr || !enabled
103 || !is_highlighted(ctx)) {
107 const auto& s = get_style(ctx);
109 const float y = transform.position.y
110 + ((transform.size.y -
static_cast<float>(arrow_size.y)) / 2.0F);
111 const float inset = padding + 4.0F;
113 asw::draw::text(f,
"<", { transform.position.x + inset, y }, s.text_hover);
115 { transform.position.x + transform.size.x - inset -
static_cast<float>(arrow_size.x), y },
Choice widget for the ASW UI module.
void select(std::size_t i)
Select an option by index without calling on_change.
bool on_event(Context &ctx, const UIEvent &e) override
Handle left and right while focused.
std::vector< asw::Texture > images
Option textures, one per option. Optional.
void prev()
Move to the previous option, calls on_change.
void activate(Context &ctx) override
Move to the next option, then call on_click.
void draw(Context &ctx) override
Draw the selected option.
bool adjusts_left_right() const
Whether left and right change the option right now.
void next()
Move to the next option, calls on_change.
std::size_t count() const
Number of options, the larger of options and images.
std::vector< std::string > options
Option labels.
Shared state for the UI system.
Theme theme
The current UI theme.
Routines for drawing sprites and primitives to the screen.
Layout widgets for the ASW UI module.
void text(const asw::Font &font, const std::string &text, const asw::Vec2< float > &position, asw::Color color, asw::TextJustify justify=asw::TextJustify::Left)
Draw text. The position is rounded to whole pixels after justification so glyphs stay sharp....
bool in_row_with_focusables(const Widget &w)
Whether a widget sits in a row with other widgets that can take focus: its parent is a horizontal Sta...
const asw::Font & pick_font(const asw::Font &own, const Theme &theme)
The font a widget draws with: its own, or the theme font.
asw::Vec2< int > get_text_size(const asw::Font &font, std::string_view text)
Get text size.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Event structure for UI interactions.
asw::input::Key key
The key associated with the event.
Type type
The type of the event.
General utility functions.