Skip to main content

Button

Struct Button 

Source
pub struct Button { /* private fields */ }
Expand description

HeroUI Button.

Implementations§

Source§

impl Button

Source

pub fn new(id: impl Into<ElementId>) -> Self

Source

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.

Source

pub fn label(self, label: impl Into<SharedString>) -> Self

Source

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.

Source

pub fn size(self, size: Size) -> Self

Source

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.

Source

pub fn is_icon_only(self, v: bool) -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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-…".

Source

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.

Source

pub fn recipe(self, name: impl Into<SharedString>) -> Self

Named theme overlay from herogpui_theme::ComponentThemes::button. Stackable; a missing name adds no override.

Source

pub fn is_disabled(self, v: bool) -> Self

Source

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.

Source

pub fn on_press( self, handler: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, ) -> Self

Trait Implementations§

Source§

impl IntoElement for Button

Source§

type Element = ViewElement<Button>

The specific type of element into which the implementing type is converted. Useful for converting other types into elements automatically, like Strings
Source§

fn into_element(self) -> Self::Element

Convert self into a type that implements Element.
Source§

fn into_any_element(self) -> AnyElement

Convert self into a dynamically-typed AnyElement.
Source§

impl ParentElement for Button

Source§

fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>)

Extend this element’s children with the given child elements.
Source§

fn child(self, child: impl IntoElement) -> Self
where Self: Sized,

Add a single child element to this element.
Source§

fn children(self, children: impl IntoIterator<Item = impl IntoElement>) -> Self
where Self: Sized,

Add multiple child elements to this element.
Source§

impl RenderOnce for Button

Source§

fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement

Render this component into an element tree. Note that this method takes ownership of self, as compared to 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 E
where 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,

Render this component or element with an animation
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,

Render this component or element with a chain of animations
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>
where Self: Sized, T: SpringTarget, <T as SpringTarget>::Output: 'static,

Renders this component or element at the value produced by a spring. Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> FluentBuilder for T
where T: IntoElement,

Source§

fn map<U>(self, f: impl FnOnce(Self) -> U) -> U
where Self: Sized,

Imperatively modify self with the given closure.
Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
where Self: Sized,

Conditionally modify self with the given closure.
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
where Self: Sized,

Conditionally modify self with the given closure.
Source§

fn when_some<T>( self, option: Option<T>, then: impl FnOnce(Self, T) -> Self, ) -> Self
where Self: Sized,

Conditionally unwrap and modify self with the given closure, if the given option is Some.
Source§

fn when_none<T>( self, option: &Option<T>, then: impl FnOnce(Self) -> Self, ) -> Self
where Self: Sized,

Conditionally unwrap and modify self with the given closure, if the given option is None.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> View for T
where T: RenderOnce,

Source§

fn entity_id(&self) -> Option<EntityId>

This view’s identity, if it has one. A view typically holds the backing entity as a field and returns its EntityId here. Read more
Source§

fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement

Render this view into an element tree, consuming self.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more