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: f32Implementations§
Source§impl Button
impl Button
pub fn new(label: impl Into<String>) -> Self
pub fn variant(self, v: ButtonVariant) -> Self
pub fn disabled(self) -> Self
Sourcepub fn disabled_if(self, condition: bool) -> Self
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()).
pub fn width(self, w: f32) -> Self
pub fn height(self, h: f32) -> Self
pub fn font_size(self, s: f32) -> Self
Sourcepub fn background(self, c: Color) -> Self
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.
pub fn radius(self, r: f32) -> Self
pub fn icon(self, w: impl Widget + 'static) -> Self
Trait Implementations§
Source§impl Widget for Button
impl Widget for Button
Source§fn layout(&self, ctx: &LayoutCtx<'_>) -> Size
fn layout(&self, ctx: &LayoutCtx<'_>) -> Size
Measure under
ctx.constraints and return a size within them. Read moreSource§fn children(&self) -> Children<'_>
fn children(&self) -> Children<'_>
Declare this widget’s children. Drives every default below.
Source§fn flex_factor(&self) -> f32
fn flex_factor(&self) -> f32
Flex weight inside Row/Column. Wrappers are transparent by default.
Auto Trait Implementations§
impl !RefUnwindSafe for Button
impl !UnwindSafe for Button
impl Freeze for Button
impl Send for Button
impl Sync for Button
impl Unpin for Button
impl UnsafeUnpin for Button
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<W> FocusApi for W
impl<W> FocusApi for W
Source§fn focus_node(self, node: FocusNode) -> WithFocus<Self>
fn focus_node(self, node: FocusNode) -> WithFocus<Self>
Attach a focus node. This enables focus-ring rendering and explicit
neighbor wiring.