Buttons

Button

A pressable button with variants and states.

Rust
1use herogpui::prelude::{Button, Size, Variant};

Usage

Rust
1use herogpui::prelude::{Button, Size, Variant};
2
3Button::new("button")
4    .label("Click me")

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

Button

Button is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Button uses.

Styling

Button styling
StyleDescription
flex + h(36px) + gap(8px) + px(16px) + control_radiusBase desktop geometry, typography and 24px rounded control surface.
Variant::Primary + colors.accentSolid accent variant tokens.
Variant::Secondary + colors.default + colors.accent.soft_foreground(colors.foreground)Neutral filled surface with accent-colored foreground.
Variant::Tertiary + colors.default + colors.foregroundNeutral default surface that preserves the inherited foreground.
Variant::Ghost + colors.defaultTransparent low-emphasis variant with the neutral foreground.
Variant::Outline + colors.default.color.alpha(0.6) + colors.borderOutlined variant with the translucent hover fill.
Variant::Danger/DangerSoft + colors.dangerSolid and soft danger variants.
Size + PRESSED_SCALE_SUBTLE/PRESSED_SCALE/PRESSED_SCALE_FIRMSize-specific control metrics and press geometry.
is_icon_only + icon_control_sizeSquare icon-only geometry follows the selected size.
full_width(true) + w_fullFills the available width.
child(element)Caller-owned GPUI children do not receive selector-driven icon sizing or margins.
anim::hover_fade + TRANSITION_MS + Curve::OutHover colors interpolate on a listener-free child fill and reduced motion swaps directly.
anim::pressed + ring_if_focusedPress geometry and focus shadow reach the correct endpoints, but GPUI applies both without property interpolation.

API reference

Builders

Button builders
BuilderTypeDefaultDescription
variant(Variant)VariantVariant::PrimaryVisual style variant.
size(Size)SizeSize::MdSize of the button.
full_width(bool)boolfalseWhether the button fills its container.
is_disabled(bool)boolfalseDisables pointer and keyboard presses and removes the tab stop.
is_pending(bool)boolfalseBlocks presses and hover while retaining focusability.
is_icon_only(bool)boolfalseUses the size-specific square icon control geometry.
on_press(callback)Fn(e: ClickEvent) -> ()Pointer and keyboard presses are supported, but the callback receives GPUI's ClickEvent.
label(value) / child(element) / content(render)AnyElement | Fn(values: ButtonRenderProps) -> AnyElementText, arbitrary children and state-driven content are supported through separate builders.
content(render)boolPending state supplied to custom content.

Parts

Button parts
PartDescription
ButtonFocusable root that owns content, visual variant and interaction state.

States

Button states
BuilderStateDescription
anim::hover_fade + InteractiveState::is_hoveredHoveredVariant-specific hover background and render state.
anim::pressed + InteractiveState::is_pressedPressedSize-specific scale and render state for pointer or keyboard press.
tab_stop_handle + ring_if_focusedFocus visibleKeyboard focus displays the status-focused ring.
is_disabled + disabled_opacityDisabledDisabled buttons are dimmed, inert and removed from the tab order.
is_pending + disabled_opacity + interactive=falsePendingPending buttons are dimmed and inert but remain focusable.