Skip to main content

Button

Struct Button 

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

A clickable box around one child, which it centers.

While the pointer is over it, hover_style is laid over its style, and while it is also held down, pressed_style on top of that. Handlers run on the main thread and receive the button’s Cx. A handler that panics is logged and never called again.

Implementations§

Source§

impl Button

Source

pub fn new(child: impl Widget) -> Button

A button around child.

Source

pub fn hover_style(self, style: impl IntoProp<Style>) -> Button

Sets the style laid over the normal one while the pointer is over the button.

Source

pub fn hovered(self, hovered: Signal<bool>) -> Button

Shares whether the pointer is over the button: the button sets hovered to true while the pointer is over it or anything inside it, buttons too, and back to false when it leaves, the window loses it, or the button goes. Unlike hover_style, which only the deepest button under the pointer shows, an outer button stays hovered while the pointer is over one inside it, so it can show controls on hover.

Source

pub fn pressed_style(self, style: impl IntoProp<Style>) -> Button

Sets the style laid over the hover style while the button is held down.

Source

pub fn focus_style(self, style: impl IntoProp<Style>) -> Button

Sets the style laid over the normal one while the button has the keyboard focus, which Tab moves between buttons.

Source

pub fn on_key( self, handler: impl Fn(&Cx, &KeyEvent) -> bool + 'static, ) -> Button

Runs handler for each key pressed while the button has the keyboard focus. It returns true when it used the key; otherwise the window’s on_key gets it, and then Tab, Enter and Space do what they do by default.

Source

pub fn on_press(self, handler: impl Fn(&Cx) + 'static) -> Button

Runs handler as soon as the left button goes down over this button, while it is held: the time to call Cx::start_move, as a title bar does.

Source

pub fn on_click(self, handler: impl Fn(&Cx) + 'static) -> Button

Runs handler when the left button is pressed and released over this button.

Source

pub fn on_right_click(self, handler: impl Fn(&Cx) + 'static) -> Button

Runs handler when the right button is pressed and released over this button.

Source

pub fn on_middle_click(self, handler: impl Fn(&Cx) + 'static) -> Button

Runs handler when the middle button is pressed and released over this button.

Source

pub fn on_scroll(self, handler: impl Fn(&Cx, i32) + 'static) -> Button

Runs handler with whole scroll steps while the pointer is over this button: positive for up, negative for down. A mouse wheel gives one step per notch; touchpad scrolling gives one step per 15 logical pixels.

Source

pub fn style(self, style: impl IntoProp<Style>) -> Self

Sets the widget’s Style.

Trait Implementations§

Source§

impl Widget for Button

Source§

fn into_element(self: Box<Self>) -> Element

Turns the description, and everything inside it, into the element the window builds nodes from. It runs when the window is created or a list item first appears, before the window’s tree is touched and without recording what it reads, so it only describes.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Button

§

impl !Send for Button

§

impl !Sync for Button

§

impl !UnwindSafe for Button

§

impl Forget for Button

§

impl Freeze for Button

§

impl Move 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<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, 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> 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