A button that cycles through a list of options, e.g. difficulty or window mode.
More...
|
| bool | adjusts_left_right () const |
| | Whether left and right change the option right now.
|
| |
| std::size_t | count () const |
| | Number of options, the larger of options and images.
|
| |
| void | select (std::size_t i) |
| | Select an option by index without calling on_change.
|
| |
| void | next () |
| | Move to the next option, calls on_change.
|
| |
| void | prev () |
| | Move to the previous option, calls on_change.
|
| |
| void | activate (Context &ctx) override |
| | Move to the next option, then call on_click.
|
| |
| bool | on_event (Context &ctx, const UIEvent &e) override |
| | Handle left and right while focused.
|
| |
| void | draw (Context &ctx) override |
| | Draw the selected option.
|
| |
| | Button () |
| | Default constructor.
|
| |
| const ButtonStyle & | get_style (const Context &ctx) const |
| | Get the style this button draws with.
|
| |
| void | set_texture (const asw::Texture &tex, bool auto_size=false) |
| | Set the texture, optionally resizing the button to match.
|
| |
| void | set_images (const asw::Texture &normal, const asw::Texture &hover=nullptr, const asw::Texture &pressed=nullptr, const asw::Texture &disabled=nullptr, bool auto_size=true) |
| | Make an image button: set the state textures, turn off the background, and optionally size the button to the normal texture.
|
| |
| void | set_text (const std::string &t, bool auto_size=false) |
| | Set the text, optionally resizing the button to match.
|
| |
| void | measure (Context &ctx) override |
| | Size to the text if set_text asked for it.
|
| |
| void | layout (Context &ctx) override |
| | Measure, in case the parent did not, then lay out the children.
|
| |
| | Widget () |
| | Default constructor for Widget.
|
| |
| virtual | ~Widget ()=default |
| | Default virtual destructor.
|
| |
| | Widget (Widget &&other) noexcept |
| | Move constructor. The children move over and point to the new widget as their parent. The new widget gets its own id and no parent, since it is not in the old parent's children. Removed children stay with the old widget, which is where Root finds and frees them.
|
| |
| Widget & | operator= (Widget &&other) noexcept |
| | Move assignment operator. The children move over and point to this widget as their parent. This widget keeps its place in the tree: its parent, id and state. Its old children are removed as by clear_children. Removed children of the other widget stay with it.
|
| |
| | Widget (const Widget &)=delete |
| |
| Widget & | operator= (const Widget &)=delete |
| |
| WidgetId | id () const |
| | Get the unique identifier for this widget.
|
| |
| const std::vector< std::unique_ptr< Widget > > & | children () const |
| | Get the child widgets. Change them with add_child, remove_child and clear_children, which keep removed widgets alive until Root is done with them.
|
| |
| virtual void | on_focus_changed (Context &ctx, bool focused) |
| | Called when focus state changes.
|
| |
| template<class T , class... Args> |
| T & | add_child (Args &&... args) |
| | Add a child widget.
|
| |
| bool | remove_child (const Widget &child) |
| | Remove a child widget. It leaves the tree now and is destroyed at the next Root::update, so a callback can remove any widget, even the one it runs in.
|
| |
| void | clear_children () |
| | Remove every child widget, destroyed as for remove_child.
|
| |
| bool | is_hovered () const |
| | Whether the pointer is currently over this widget.
|
| |
| bool | is_pressed () const |
| | Whether this widget is currently being pressed.
|
| |
| bool | is_focused () const |
| | Whether this widget currently holds focus.
|
| |
| bool | is_captured () const |
| | Whether this widget was pressed and the pointer is still held, even if it has moved off the widget.
|
| |
| bool | is_highlighted (const Context &ctx) const |
| | Whether to draw the hover look: hovered, pressed, or focused while focus is shown.
|
| |
|
| std::vector< std::string > | options |
| | Option labels.
|
| |
| std::vector< asw::Texture > | images |
| | Option textures, one per option. Optional.
|
| |
| std::size_t | index = 0 |
| | Index of the selected option.
|
| |
| bool | wrap = true |
| | Wrap around at either end.
|
| |
| std::optional< bool > | adjust_on_left_right |
| | Whether left and right change the option. Empty to decide from the layout: off in a row with other focusable widgets, on otherwise.
|
| |
| bool | show_arrows = true |
| | Show < and > at the sides while highlighted, when there is text and left and right change the option.
|
| |
| std::function< void(std::size_t)> | on_change |
| | Callback invoked with the new index when the user changes it.
|
| |
| std::function< void()> | on_click |
| | Callback invoked when the button is clicked.
|
| |
| float | padding = 0.0f |
| | Padding applied inside the button on all sides.
|
| |
| asw::Font | font |
| | The font for the text. Uses the theme font when empty.
|
| |
| std::string | text |
| | The button text.
|
| |
| asw::Texture | texture |
| | The texture to display on the button.
|
| |
| asw::Texture | texture_hover |
| | Texture shown while hovered or focused. Falls back to texture.
|
| |
| asw::Texture | texture_pressed |
| | Texture shown while pressed. Falls back to texture_hover, then texture.
|
| |
| asw::Texture | texture_disabled |
| | Texture shown while disabled. Falls back to texture.
|
| |
| bool | draw_background = true |
| | Fill the button with the theme background. Turn off for buttons that are only an image.
|
| |
| std::optional< ButtonStyle > | style |
| | Style for this button only. Uses the theme button style when empty.
|
| |
| bool | visible = true |
| | Whether the widget is visible.
|
| |
| bool | enabled = true |
| | Whether the widget is enabled.
|
| |
| bool | focusable = false |
| | Whether the widget can receive focus. Focusable widgets are also the ones the pointer can press.
|
| |
| Widget * | nav_up = nullptr |
| | Widget to focus on up, instead of the nearest one. Optional.
|
| |
| Widget * | nav_down = nullptr |
| | Widget to focus on down, instead of the nearest one. Optional.
|
| |
| Widget * | nav_left = nullptr |
| | Widget to focus on left, instead of the nearest one. Optional.
|
| |
| Widget * | nav_right = nullptr |
| | Widget to focus on right, instead of the nearest one. Optional.
|
| |
| bool | focus_ring = true |
| | Draw the theme focus ring around this widget while it has visible focus. Turn off for widgets that show focus themselves.
|
| |
| Widget * | parent = nullptr |
| | Pointer to the parent widget.
|
| |
| asw::Quad< float > | transform |
| | The transform (position and size) of the widget.
|
| |
| Anchor | anchor = Anchor::None |
| | Pin this widget to a point of its parent, e.g. BottomRight for a corner button. The parent places it on every layout, so it stays in place when the screen or its own size changes. Stack and Grid place their children themselves and ignore it.
|
| |
| asw::Vec2< float > | anchor_margin { 0.0F, 0.0F } |
| | Space between an anchored widget and the parent's edges.
|
| |
A button that cycles through a list of options, e.g. difficulty or window mode.
Clicking or activating moves to the next option. While focused, left and right move back and forward, unless the choice sits in a row with other focusable widgets, where they move focus instead (see adjust_on_left_right). Each option shows its label from options, its texture from images, or both. The rest of the look is the Button style.
Definition at line 32 of file choice.h.