Button
button · Elements · interactive
A button, in the four variants the design system has.
Import
cpp
#include "gbui/widgets/button.hpp"Example
Nothing is downloaded until you press it.
cpp
NodeId button(Ui& ui, std::string_view text, const ButtonOptions& options = {});cpp
NodeId button(Ui& ui, const Interaction& input, std::string_view text, const ButtonOptions& options = {});Without an Interaction there is no pointer to start a ripple from, so this overload ignores options.ripple. Everything else is identical.
The same button, given what it needs to draw a press.
API
ButtonOptions
| Option | Type | Default | What it does |
|---|---|---|---|
variant | ButtonVariantPrimary · Secondary · Ghost · Danger | ButtonVariant::Secondary | Which of the four this is. Secondary by default, because a screen where everything is primary has no primary. |
leading optional | std::optional<Icon> | Drawn before the label, in the label's colour. | |
disabled | bool | false | |
block | bool | false | Stretches to fill the row it is in, the way a COMMIT button does. |
height | float | 0.0f | Zero takes the active design's control height. |
iconSize | float | 0.0f | The glyph's size. Zero matches the label's, which is what a button with a label wants; one with only an icon in it usually wants more, since the glyph is the whole button rather than a mark beside a word. |
id | std::string_view | ||
name | std::string_view | What a reader who cannot see it is told this button is called. The label, unless it is given — which leaves exactly one case where the caller must say something: an icon-only button, which has no label to borrow. Nothing is guessed from the glyph; a name inferred from Icon::Trash would be a guess the reader has no way to check, and "button, button, button" across a toolbar is the failure this exists to stop. | |
ripple optional | std::optional<bool> | A circle of ink that grows from where the pointer went down. Unset — the normal case — asks the active Design: Material throws ink, the others change the surface. Set, it overrides that decision for this one button, which is the escape hatch and not the default. Either way it needs the overload below (the ripple starts at the point the press landed) and an id, since that is what the animation is keyed by. |