Button
Button is the standard labeled action control.
Button("Save changes").OnClick([] { SaveChanges();})Construct it from StringResource, std::string, std::string_view, or a string literal.
The label is required component input rather than an arbitrary child view.
Interaction
Section titled “Interaction”.OnClick(...) uses the shared pointer, Enter, and Space activation path.
The current theme resolves hover, pressed, focus-visible, disabled state, and Material ripple or Flat feedback.
Button("Delete") .OnClick(DeleteSelection) .With(Enabled(has_selection))Enabled(false) removes activation and applies disabled semantics and style.
Theme and accessibility
Section titled “Theme and accessibility”ButtonStyle controls background, label style, disabled colors, padding, minimum size, radius, and optional indication.
The component exposes button role, accessible label, focus, and activate action automatically.
Use Semantics{.hint = ...} only when the visible label does not fully explain the result.
- Constructors:
Button(StringResource|string|string_view|const char*). - Event:
.OnClick(function)or.On<ViewEvents::Click>(function). - Common modifiers:
Enabled,Frame,Padding,Semantics. - Theme style:
ButtonStyle.
Use IconButton for an icon-only action and Chip for compact action or selection tokens.
Configure size and appearance
Section titled “Configure size and appearance”Declared in <huxerui/view.h>, namespace huxerui. The actual constructor is explicit Button(StringVariant label); the string and resource forms above convert to that value. The declaration owns the label for its UI lifetime. OnClick accepts a void() callable and provides no automatic loading state or asynchronous completion tracking.
ButtonStyle field |
Effect |
|---|---|
background, disabled_background |
Normal and disabled surface fills, including supported brush/image fills. |
label_style, disabled_label |
Normal typography and disabled text color. |
padding |
Space between the label and the control surface. |
minimum_width, minimum_height |
Lower size preferences; parent constraints still apply. |
corner_radii |
Per-corner surface geometry. |
indication |
Optional interaction visual override. |
Material supplies a 40-DIP minimum height and a rounded filled treatment. Flat uses its compact padding-based treatment. To customize a subtree, override ButtonStyle in its theme definition; see style overrides. Use Frame for application layout requirements, not a style override on every individual button.
Prevent repeated submission
Section titled “Prevent repeated submission”This complete component leaves the simulated work inside its composition lifetime. Use the same busy-state pattern around a real request:
#include <huxerui/huxerui.h>
#include <chrono>
using namespace huxerui;
[[huxerui::composable]]View SaveAction() { auto busy = UseState(false); auto tasks = UseTaskScope(); return Button(busy ? "Saving..." : "Save") .OnClick([busy, tasks] { if (busy) { return; } busy = true; tasks.Launch([busy]() -> Task<void> { co_await Delay(std::chrono::milliseconds{300}); busy = false; }); }) .With(Enabled(!busy));}For fallible work, restore the busy state on both success and handled failure and show the error near the action. A button with no handler still looks and reads as a button; use Enabled(false) for an intentionally unavailable action.

