pub struct Button { /* private fields */ }Expand description
HeroUI Button.
Implementations§
Source§impl Button
impl Button
pub fn new(id: impl Into<ElementId>) -> Self
Sourcepub fn content(
self,
render: impl Fn(InteractiveState) -> AnyElement + 'static,
) -> Self
pub fn content( self, render: impl Fn(InteractiveState) -> AnyElement + 'static, ) -> Self
v3’s render function for a button’s children, handed isHovered,
isPressed, isFocused, isFocusVisible, isDisabled and isPending.
The hover and the press are a frame behind the pointer: gpui reports both to a handler, so the render that draws them can only read what the last frame recorded. The button’s own hover and press styling does not go through this – it is applied by gpui in the same frame.
pub fn label(self, label: impl Into<SharedString>) -> Self
Sourcepub fn variant(self, variant: Variant) -> Self
pub fn variant(self, variant: Variant) -> Self
The visual style.
Setting this at the call site suppresses
herogpui_theme::ButtonStyle::variant from
every recipe on the button — the instance is the more specific source,
so it wins, the same way Button::hover_bg outranks a recipe’s
hover_bg. The surprise is what goes with the variant: each one
derives its own hover shade, so
.variant(Variant::Primary).recipe("accented") keeps primary’s hover
even when the recipe was written to change it through its variant. A
recipe that must change the hover names it with
herogpui_theme::ButtonStyle::hover_bg, which is honoured whatever variant is in
force; a hover that should follow a whole role everywhere belongs on
the role instead, through
herogpui_theme::ThemeBuilder::role_hover.
pub fn size(self, size: Size) -> Self
Sourcepub fn full_width(self, v: bool) -> Self
pub fn full_width(self, v: bool) -> Self
Fills the parent with w-full. An explicit Button::width is the
more specific source and wins when both are set.
pub fn is_icon_only(self, v: bool) -> Self
Sourcepub fn width(self, w: impl Into<Pixels>) -> Self
pub fn width(self, w: impl Into<Pixels>) -> Self
The button’s fixed pixel width, in place of the content-fit ladder.
Beats Button::full_width when both are set: full_width fills the
parent, a pixel width fixes the box, and the pixel width is the more
specific source. It also replaces the icon-only square. The pressed
skin keeps the fixed box instead of snapping back to the ladder, and a
matching sx width still refines the root last.
Not a v3 prop; a per-component repository extension like
Button::radius.
Sourcepub fn min_width(self, w: impl Into<Pixels>) -> Self
pub fn min_width(self, w: impl Into<Pixels>) -> Self
The button’s width floor, under the content-fit ladder, an explicit
Button::width and grow’s zero floor alike.
Not a v3 prop; a per-component repository extension like
Button::radius.
Sourcepub fn height(self, h: impl Into<Pixels>) -> Self
pub fn height(self, h: impl Into<Pixels>) -> Self
The button’s fixed pixel height, in place of the size ladder’s control
height. Beats what Button::size derives; a matching sx height
still refines the root last, and the pressed skin keeps the fixed box.
Not a v3 prop; a per-component repository extension like
Button::radius.
Sourcepub fn padding_x(self, p: impl Into<Pixels>) -> Self
pub fn padding_x(self, p: impl Into<Pixels>) -> Self
The button’s horizontal inset, in place of the size ladder’s px-4
(px-3 on --sm). Beats what Button::size derives and feeds the
pressed skin’s inset geometry; a matching sx padding still refines
the root last.
Not a v3 prop; a per-component repository extension like
Button::radius.
Sourcepub fn text_size(self, size: impl Into<Pixels>) -> Self
pub fn text_size(self, size: impl Into<Pixels>) -> Self
The label’s font size; unset keeps the size ladder’s pair (text-sm,
stepping to text-base on --lg). Beats what Button::size
derives. A Tailwind step keeps its paired leading through
util::leading_for; other sizes keep the size step’s leading, the
same convention crate::chip::Chip::text_size records.
Not a v3 prop; a per-component repository extension like
Button::radius.
Sourcepub fn font_weight(self, weight: FontWeight) -> Self
pub fn font_weight(self, weight: FontWeight) -> Self
The label’s font weight, in place of .button’s font-medium. Beats
what Button::size derives; a matching sx weight still refines the
root last.
Not a v3 prop; a per-component repository extension like
Button::radius.
Sourcepub fn grow(self, v: bool) -> Self
pub fn grow(self, v: bool) -> Self
Fills the row’s free width: v3’s flex-1 plus min-w-0, the pair a
caller otherwise has to reach for sx to spell. The button shares the
free width of its flex parent instead of overflowing it, and may
compress below its own content width — exactly what the min-w-0 half
is for.
Coexists with Button::full_width: full_width pins the box to
100% of the parent, grow shares whatever is left over after the
siblings.
Not a v3 prop; a per-component repository extension like
Button::radius.
Sourcepub fn sx(self, style: impl FnOnce(Div) -> Div) -> Self
pub fn sx(self, style: impl FnOnce(Div) -> Div) -> Self
The one slot for caller-owned low-level styling: GPUI’s styling methods
(bg, text_color, w, h, p, rounded, border_color, …)
applied to the button’s root element after every value the variant and
the active theme chose, so they win. An overridden background also
replaces the hover fade’s endpoints and an overridden pixel size the
press geometry, so the override holds across states.
Sourcepub fn hover_bg(self, color: impl Into<Hsla>) -> Self
pub fn hover_bg(self, color: impl Into<Hsla>) -> Self
The fill the hover fade eases to, in place of the variant’s own hover colour.
The escape hatch for a caller-owned surface: sx’s background replaces
both of the fade’s endpoints, because a fill that eased back to the
variant colour would paint over the override — so an sx background
alone is a button whose hover does not move. Naming the hover colour
restores the transition: the fade runs from the resting background (the
sx background when one is set, the variant’s resting colour
otherwise) to color, over the same transition-colors timing every
other button uses. The press state is unaffected either way — v3’s
:active is the opacity step apply_button_variant applies, not a
third colour.
v3 has no such prop; on the web this is className="hover:bg-…".
Sourcepub fn radius(self, radius: impl Into<Pixels>) -> Self
pub fn radius(self, radius: impl Into<Pixels>) -> Self
The corner radius, in place of --radius-3xl (capped). Group edges and
the press scale still apply. Not a v3 prop; the removed v2 radius
prop is prohibited and this is a per-component repository extension.
Sourcepub fn recipe(self, name: impl Into<SharedString>) -> Self
pub fn recipe(self, name: impl Into<SharedString>) -> Self
Named theme overlay from herogpui_theme::ComponentThemes::button.
Stackable; a missing name adds no override.
pub fn is_disabled(self, v: bool) -> Self
Sourcepub fn is_pending(self, v: bool) -> Self
pub fn is_pending(self, v: bool) -> Self
isPending — blocks presses and hover while retaining the tab stop and focus ring.
A content closure receives the pending state and owns any loading indicator.
pub fn on_press( self, handler: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, ) -> Self
Trait Implementations§
Source§impl IntoElement for Button
impl IntoElement for Button
Source§type Element = ViewElement<Button>
type Element = ViewElement<Button>
Source§fn into_element(self) -> Self::Element
fn into_element(self) -> Self::Element
Element.Source§fn into_any_element(self) -> AnyElement
fn into_any_element(self) -> AnyElement
AnyElement.Source§impl ParentElement for Button
impl ParentElement for Button
Source§fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>)
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>)
Source§fn child(self, child: impl IntoElement) -> Selfwhere
Self: Sized,
fn child(self, child: impl IntoElement) -> Selfwhere
Self: Sized,
Source§fn children(self, children: impl IntoIterator<Item = impl IntoElement>) -> Selfwhere
Self: Sized,
fn children(self, children: impl IntoIterator<Item = impl IntoElement>) -> Selfwhere
Self: Sized,
Source§impl RenderOnce for Button
impl RenderOnce for Button
Source§fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
Render::render() method
which takes a mutable reference.Auto Trait Implementations§
impl !RefUnwindSafe for Button
impl !Send for Button
impl !Sync for Button
impl !UnwindSafe for Button
impl Freeze for Button
impl Unpin for Button
impl UnsafeUnpin for Button
Blanket Implementations§
Source§impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
Source§fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_spring<T>(
self,
id: impl Into<ElementId>,
animation: SpringAnimation<T>,
animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static,
) -> SpringAnimationElement<Self>
fn with_spring<T>( self, id: impl Into<ElementId>, animation: SpringAnimation<T>, animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static, ) -> SpringAnimationElement<Self>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FluentBuilder for Twhere
T: IntoElement,
impl<T> FluentBuilder for Twhere
T: IntoElement,
Source§fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more