Skip to content

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

OptionTypeDefaultWhat it does
variantButtonVariant
Primary · Secondary · Ghost · Danger
ButtonVariant::SecondaryWhich of the four this is. Secondary by default, because a screen where everything is primary has no primary.
leading optionalstd::optional<Icon>Drawn before the label, in the label's colour.
disabledboolfalse
blockboolfalseStretches to fill the row it is in, the way a COMMIT button does.
heightfloat0.0fZero takes the active design's control height.
iconSizefloat0.0fThe 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.
idstd::string_view
namestd::string_viewWhat 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 optionalstd::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.

Released under the LGPL-3.0-or-later licence.