Skip to main content

Button

Struct Button 

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

Button widget

Buttons can have custom content via button_with() or use the simple button("Label") constructor for text-only buttons.

The element is made when it is first asked for, so every fluent call made before that counts, in any order.

Implementations§

Source§

impl Button

Source

pub fn new(label: impl IntoReactive<String>) -> Button

Create a button with a text label.

The label can follow a signal; it is patched in place.

Source

pub fn with_content<F, E>(content: F) -> Button
where F: Fn(&ButtonLook) -> E + 'static, E: ElementBuilder + 'static,

Create a button holding the element content returns.

content is called once, when the button is built. It does not run again when the pointer state changes: text and icons inside take the button’s color as it changes.

Source

pub fn key(self, key: impl Into<String>) -> Button

Name the button’s pointer state, so it persists across rebuilds under a key of your choosing instead of one made from where it was created. Needed for buttons made in a loop from one place.

Source

pub fn style(self, style: &ElementStyle) -> Button

Apply an ElementStyle to the button’s element as its default tier, below an application stylesheet and below any fluent call made after it. Replayed in call order with the other fluent calls.

Source

pub fn bg_color(self, color: impl Into<Color>) -> Button

The fill, in every state: a fluent value wins over the default look’s rules, so this fixes the fill. To restyle by state, write rules.

Source

pub fn text_color(self, color: impl Into<Color>) -> Button

Colour of the label of a button made with button("Label"). For custom content, give the content’s own text a colour or set color in a rule.

Source

pub fn text_size(self, size: f32) -> Button

Set text size for simple text buttons created with button("Label")

Note: This has no effect on buttons created with button_with().

Source

pub fn disabled(self, disabled: impl IntoReactive<bool>) -> Button

Disable the button, for good or while a signal holds. A disabled button matches :disabled and does not click.

Source

pub fn on_click<F>(self, handler: F) -> Button
where F: Fn(&EventContext) + Send + Sync + 'static,

Source

pub fn id(self, id: &str) -> Button

Set the element ID for CSS selector targeting

Source

pub fn class(self, class: &str) -> Button

Add a CSS class for selector matching

Source§

impl Button

Source

pub fn px(self, v: f32) -> Button

Source

pub fn py(self, v: f32) -> Button

Source

pub fn p(self, v: f32) -> Button

Source

pub fn pt(self, v: f32) -> Button

Source

pub fn pb(self, v: f32) -> Button

Source

pub fn pl(self, v: f32) -> Button

Source

pub fn pr(self, v: f32) -> Button

Source

pub fn rounded(self, v: f32) -> Button

Source

pub fn border(self, width: f32, color: Color) -> Button

Source

pub fn border_color(self, color: Color) -> Button

Source

pub fn border_width(self, width: f32) -> Button

Source

pub fn w(self, v: f32) -> Button

Source

pub fn h(self, v: f32) -> Button

Source

pub fn w_full(self) -> Button

Source

pub fn h_full(self) -> Button

Source

pub fn w_fit(self) -> Button

Source

pub fn h_fit(self) -> Button

Source

pub fn mt(self, v: f32) -> Button

Source

pub fn mb(self, v: f32) -> Button

Source

pub fn ml(self, v: f32) -> Button

Source

pub fn mr(self, v: f32) -> Button

Source

pub fn mx(self, v: f32) -> Button

Source

pub fn my(self, v: f32) -> Button

Source

pub fn m(self, v: f32) -> Button

Source

pub fn gap(self, v: f32) -> Button

Source

pub fn items_center(self) -> Button

Source

pub fn items_start(self) -> Button

Source

pub fn items_end(self) -> Button

Source

pub fn justify_center(self) -> Button

Source

pub fn justify_start(self) -> Button

Source

pub fn justify_end(self) -> Button

Source

pub fn justify_between(self) -> Button

Source

pub fn flex_row(self) -> Button

Source

pub fn flex_col(self) -> Button

Source

pub fn flex_grow(self) -> Button

Source

pub fn flex_shrink(self) -> Button

Source

pub fn flex_shrink_0(self) -> Button

Source

pub fn shadow_sm(self) -> Button

Source

pub fn shadow_md(self) -> Button

Source

pub fn shadow_lg(self) -> Button

Source

pub fn shadow_xl(self) -> Button

Source

pub fn opacity(self, v: f32) -> Button

Trait Implementations§

Source§

impl ElementBuilder for Button

Source§

fn build(&self, tree: &mut LayoutTree) -> LayoutNodeId

Build this element into a layout tree, returning the node ID
Source§

fn render_props(&self) -> RenderProps

Get the render properties for this element
Source§

fn children_builders(&self) -> &[Box<dyn ElementBuilder>]

Get children builders (for recursive traversal)
Source§

fn element_type_id(&self) -> ElementTypeId

Get the element type identifier
Source§

fn semantic_type_name(&self) -> Option<&'static str>

Semantic HTML-like tag name for CSS type selectors (e.g., “button”, “a”, “ul”) Read more
Source§

fn element_id(&self) -> Option<&str>

Get the element ID for selector API queries Read more
Source§

fn element_classes(&self) -> &[Arc<str>]

Get the element’s CSS class list for selector matching. Read more
Source§

fn event_handlers(&self) -> Option<&EventHandlers>

Get event handlers for this element Read more
Source§

fn layout_style(&self) -> Option<&Style>

Get the layout style for this element Read more
Source§

fn as_any(&self) -> Option<&(dyn Any + 'static)>

Downcast handle, for a container that must read typed structure from its own children rather than just render them. Read more
Source§

fn text_render_info(&self) -> Option<TextRenderInfo>

Get text render info if this is a text element
Source§

fn styled_text_render_info(&self) -> Option<StyledTextRenderInfo>

Get styled text render info if this is a styled text element (rich_text)
Source§

fn svg_render_info(&self) -> Option<SvgRenderInfo>

Get SVG render info if this is an SVG element
Source§

fn image_render_info(&self) -> Option<ImageRenderInfo>

Get image render info if this is an image element
Source§

fn canvas_render_info( &self, ) -> Option<Rc<dyn Fn(&mut dyn DrawContext, CanvasBounds)>>

Get canvas render info if this is a canvas element
Source§

fn is_static_canvas(&self) -> bool

Whether this canvas’s render_fn produces deterministic output for a given bounds + closure captures, with no per-frame state (animations, timers, live signal reads). Static canvases get emitted to the bg batch normally but skip the per-frame overlay re-paint that would otherwise overdraw any children the walker layered on top of them in the static cache. They also don’t flip the had_canvas_painted gate, so the compositor fast path can still engage on frames where the only canvases are static. Read more
Source§

fn canvas_redraw_while(&self) -> Option<Rc<dyn Fn() -> bool>>

See crate::canvas::Canvas::redraw_while. Applies only when element_type_id is ElementTypeId::Canvas.
Source§

fn effective_layout_style(&self) -> Option<Style>

The taffy Style that this element actually installs on its layout node — i.e. the style after any widget-internal adjustments build() would apply. The default delegates to layout_style().cloned(), which is correct for elements whose build() just forwards self.style verbatim. Override when build() mutates the style before handing it to taffy (e.g. Notch::build adds scoop.depth to padding so children don’t render over the carved-out region). Read more
Source§

fn scroll_info(&self) -> Option<ScrollRenderInfo>

Get scroll render info if this is a scroll element
Source§

fn scroll_physics(&self) -> Option<Arc<Mutex<ScrollPhysics>>>

Get scroll physics handle if this is a scroll element
Source§

fn viewport_cull(&self) -> bool

Whether this element opts in to viewport culling for its descendants. The renderer skips painting any descendant whose post-scroll bounds don’t intersect the visible viewport (plus a small overscan buffer). Only meaningful on scroll containers.
Source§

fn motion_animation_for_child( &self, _child_index: usize, ) -> Option<MotionAnimation>

Get motion animation config for a child at given index Read more
Source§

fn motion_bindings(&self) -> Option<MotionBindings>

Get motion bindings for continuous animation Read more
Source§

fn motion_stable_id(&self) -> Option<&str>

Get stable ID for motion animation tracking Read more
Source§

fn motion_should_replay(&self) -> bool

Check if this motion should replay its animation Read more
Source§

fn motion_is_suspended(&self) -> bool

Check if this motion should start in suspended state Read more
Source§

fn motion_is_exiting(&self) -> bool

👎Deprecated since 0.1.0:

Use query_motion(key).exit() to explicitly trigger motion exit

DEPRECATED: Check if this motion should start its exit animation Read more
Source§

fn layout_bounds_storage(&self) -> Option<Arc<Mutex<Option<ElementBounds>>>>

Get layout bounds storage for this element Read more
Source§

fn layout_bounds_callback( &self, ) -> Option<Arc<dyn Fn(ElementBounds) + Send + Sync>>

Get layout bounds change callback for this element Read more
Source§

fn set_auto_id(&mut self, _id: String) -> bool

Set an auto-generated element ID (used by stateful containers for stable child IDs). Read more
Source§

fn children_builders_mut(&mut self) -> &mut [Box<dyn ElementBuilder>]

Get mutable access to children for auto-ID assignment
Source§

fn bound_scroll_ref(&self) -> Option<&ScrollRef>

Get the bound ScrollRef for programmatic scroll control Read more
Source§

fn bound_element_ref(&self) -> Option<&DivRef>

Get the bound crate::selector::DivRef, if the builder was given one. The renderer resolves it to this element’s node.
Source§

fn motion_on_ready_callback( &self, ) -> Option<Arc<dyn Fn(ElementBounds) + Send + Sync>>

Get the on_ready callback for this motion container Read more
Source§

fn layout_animation_config(&self) -> Option<LayoutAnimationConfig>

Get layout animation configuration for this element Read more
Source§

fn visual_animation_config(&self) -> Option<VisualAnimationConfig>

Get visual animation config for new FLIP-style animations (read-only layout) Read more

Auto Trait Implementations§

§

impl !Freeze for Button

§

impl !RefUnwindSafe for Button

§

impl !Send for Button

§

impl !Sync for Button

§

impl !UnwindSafe for Button

§

impl Unpin for Button

§

impl UnsafeUnpin for Button

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<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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoReactive<T> for T

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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