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. A drag of this button or one inside it keeps it hovered until the release.

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_release(self, handler: impl Fn(&Cx) + 'static) -> Button

Runs handler when the left button comes up after going down on this button, wherever the pointer is by then, before on_click.

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, unless that ended a drag or a long press, or made a double click.

Source

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

Runs handler instead of a second on_click when a click comes within 400 ms and 5 logical pixels of the one before, as Qt’s defaults say. A third click starts over. Without it, every click runs on_click.

Source

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

Runs handler once the left button has been held on this button for 800 ms without moving 10 logical pixels, as Qt’s press and hold. The release after it doesn’t click, though moving on can still drag.

Source

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

Runs handler as the left button drags this button: a DragPhase::Start once it moves 10 logical pixels from where it went down, a Move for each motion after, and an End when it comes up, the pointer leaves the window, or the button is disabled. A button with no on_click, on_double_click or on_long_press starts at the press instead, so a slider moves from the first touch.

While it drags, the button gets every motion, even outside itself or the window, stays hovered, and doesn’t click.

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_back(self, handler: impl Fn(&Cx) + 'static) -> Button

Runs handler when the mouse’s back side button is pressed and released over this button.

Source

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

Runs handler when the mouse’s forward side 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. Sideways scrolling gives none.

Source

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

Runs handler with every scroll event while the pointer is over this button, on both axes: a wheel’s notches, a touchpad’s pixels, where it came from, and the stop when the fingers lift. Positive is down and right. With on_scroll too, both run.

Source

pub fn pointer_position(self, position: Signal<Option<Point>>) -> Button

Shares where the pointer is: the button writes position, in its own coordinates with (0, 0) at its top-left, while the pointer is over it or anything inside it, and None when it leaves. While a button inside it, or this one, is dragged, it follows the pointer wherever it goes, even outside the button. It is written only on a change.

Source

pub fn enabled(self, enabled: impl IntoProp<bool>) -> Button

Turns the button on or off; it is on by default. Off, none of its handlers run, it shows no hover, pressed or focus style and the default cursor, and Tab skips it. The pointer passes through it to the button around it, as through a disabled Qt MouseArea. Turning it off while it is held lets go, ending a drag with its End, and drops its focus.

Source

pub fn focus(self, focus: impl IntoProp<bool>) -> Button

Takes the keyboard focus whenever this turns true, as TextInput::focus does. Tab and a field may take it away again.

Source

pub fn drag_data<T: Clone + 'static>( self, data: impl IntoProp<Option<T>>, ) -> Button

Makes a drag of this button carry data, which a button whose on_drop takes a T is given when the drag is released over it. A closure is read as it changes, and a drop gets the value it holds at the release. While it holds a value, the button drags as one with on_drag does, and its on_drag still runs, so it can follow the pointer with a translate; its End says whether it was dropped. While it holds None, the button acts as if it had no data: it clicks, and drags only with its own on_drag, so editing.get().then_some(id) drags only in an edit mode. A drag carries data only within its window.

Source

pub fn on_drop<T: Clone + 'static>( self, handler: impl Fn(&Cx, T) + 'static, ) -> Button

Runs handler with a copy of the drag_data of a drag released over this button, or over anything inside it, when that data is a T. Data of any other type passes over it, as if it weren’t there. The deepest button under the pointer that takes it is the one dropped on, and the dragged button never takes its own.

Source

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

Shares whether a drop is waiting: the button writes hovered true while a drag whose data its on_drop would take is over it, as Qt’s DropArea.containsDrag, and false when the drag leaves, ends, or either button goes, is hidden or is turned off.

Source

pub fn cursor(self, cursor: impl IntoProp<CursorShape>) -> Button

Sets the cursor shown over the button, instead of the pointing hand.

Source

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

Sets the widget’s Style.

Source

pub fn visible(self, visible: impl IntoProp<bool>) -> Self

Shows or hides the widget. Hidden, it is taken out of the layout, so its space goes to the others, and it isn’t drawn, hit or reached by Tab; it drops the keyboard focus and the pointer. Its bindings and state stay, so it shows again as it was. Shown by default.

Source

pub fn geometry(self, geometry: Signal<Rect>) -> Self

Shares where the widget is: after each layout that moves or resizes it, its laid-out rectangle in the window’s logical pixels, scrolled with any scroll view around it but not moved by a style’s translate, scale or rotate, is written to geometry. A hidden widget writes nothing. An effect that reads it may change the layout: the window is laid out again at once, until nothing moves.

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