Skip to main content

Button

Struct Button 

Source
pub struct Button {
    pub label: String,
    pub variant: ButtonVariant,
    pub disabled: bool,
    pub icon: Option<Box<dyn Widget>>,
    pub width: Option<f32>,
    pub height: f32,
    pub font_size: Option<f32>,
    pub radius: f32,
    /* private fields */
}
Expand description

A clickable labeled button.

Attach a callback with .on_press(|| ...). The callback fires when the button is clicked — no boilerplate needed.

Fields§

§label: String§variant: ButtonVariant§disabled: bool§icon: Option<Box<dyn Widget>>§width: Option<f32>§height: f32§font_size: Option<f32>

None = read from the active theme’s typography.label_large (D127 “environment” track — see Checkbox::resolved_font_size’s doc for the reasoning).

§radius: f32

Implementations§

Source§

impl Button

Source

pub fn new(label: impl Into<String>) -> Self

Source

pub fn variant(self, v: ButtonVariant) -> Self

Source

pub fn disabled(self) -> Self

Source

pub fn disabled_if(self, condition: bool) -> Self

Conditional form of Self::disabled (D116 Phase 28 Step 8) — the natural way to gate a submit button on form.is_valid() without an if/else at every call site: Button::new("Submit").disabled_if(!form.is_valid()).

Source

pub fn width(self, w: f32) -> Self

Source

pub fn height(self, h: f32) -> Self

Source

pub fn font_size(self, s: f32) -> Self

Source

pub fn background(self, c: Color) -> Self

Overrides the variant’s own fill color — for a one-off custom color outside the Primary/Secondary/Ghost/Danger/Success/Link palette.

Source

pub fn color(self, c: Color) -> Self

Overrides the variant’s own label/icon color.

Source

pub fn radius(self, r: f32) -> Self

Source

pub fn icon(self, w: impl Widget + 'static) -> Self

Source

pub fn on_press(self, f: impl Fn() + Send + Sync + 'static) -> Self

Set the click handler. The closure is called on every left-click inside the button’s bounds.

Trait Implementations§

Source§

impl Widget for Button

Source§

fn layout(&self, ctx: &LayoutCtx<'_>) -> Size

Measure under ctx.constraints and return a size within them. Read more
Source§

fn paint(&self, ctx: &mut PaintCtx<'_>)

Record draw commands for ctx.rect. Read more
Source§

fn children(&self) -> Children<'_>

Declare this widget’s children. Drives every default below.
Source§

fn flex_factor(&self) -> f32

Flex weight inside Row/Column. Wrappers are transparent by default.
Source§

fn into_element(self) -> Element
where Self: Sized + 'static,

Wrap this widget in an Element so it can be returned from Component::build().

Auto Trait Implementations§

Blanket Implementations§

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<W> FocusApi for W
where W: Widget + Send + Sync + 'static,

Source§

fn focus_node(self, node: FocusNode) -> WithFocus<Self>

Attach a focus node. This enables focus-ring rendering and explicit neighbor wiring.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<W> HeroApi for W
where W: Widget + Send + Sync + 'static,

Source§

fn hero_tag(self, tag: impl Into<String>) -> Hero<Self>

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<W> OverlayApi for W
where W: Widget + Send + Sync + 'static,

Source§

fn dropdown( self, open: Atom<bool>, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

fn sheet( self, open: Atom<bool>, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

fn dialog( self, open: Atom<bool>, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

fn rich_tooltip( self, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

fn toast( self, open: Atom<bool>, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

impl<W> PressApi for W
where W: Widget + Send + Sync + 'static,

Source§

fn on_press(self, f: impl Fn() + Send + Sync + 'static) -> Pressable<Self>

Source§

fn on_long_press( self, f: impl Fn() + Send + Sync + 'static, ) -> LongPressable<Self>

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<W> WidgetExt for W
where W: Widget + 'static,

Source§

fn tooltip(self, label: impl Into<String>) -> Tooltip

Show label while the pointer hovers this widget.