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
impl Button
Sourcepub fn hover_style(self, style: impl IntoProp<Style>) -> Button
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.
Sourcepub fn hovered(self, hovered: Signal<bool>) -> Button
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.
Sourcepub fn pressed_style(self, style: impl IntoProp<Style>) -> Button
pub fn pressed_style(self, style: impl IntoProp<Style>) -> Button
Sets the style laid over the hover style while the button is held down.
Sourcepub fn focus_style(self, style: impl IntoProp<Style>) -> Button
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.
Sourcepub fn on_key(
self,
handler: impl Fn(&Cx, &KeyEvent) -> bool + 'static,
) -> Button
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.
Sourcepub fn on_press(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_release(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_click(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_double_click(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_long_press(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_drag(self, handler: impl Fn(&Cx, Drag) + 'static) -> Button
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.
Sourcepub fn on_right_click(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_middle_click(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_back(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_forward(self, handler: impl Fn(&Cx) + 'static) -> Button
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.
Sourcepub fn on_scroll(self, handler: impl Fn(&Cx, i32) + 'static) -> Button
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.
Sourcepub fn on_wheel(self, handler: impl Fn(&Cx, Wheel) + 'static) -> Button
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.
Sourcepub fn pointer_position(self, position: Signal<Option<Point>>) -> Button
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.
Sourcepub fn enabled(self, enabled: impl IntoProp<bool>) -> Button
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.
Sourcepub fn focus(self, focus: impl IntoProp<bool>) -> Button
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.
Sourcepub fn drag_data<T: Clone + 'static>(
self,
data: impl IntoProp<Option<T>>,
) -> Button
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.
Sourcepub fn on_drop<T: Clone + 'static>(
self,
handler: impl Fn(&Cx, T) + 'static,
) -> Button
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.
Sourcepub fn drop_hovered(self, hovered: Signal<bool>) -> Button
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.
Sourcepub fn cursor(self, cursor: impl IntoProp<CursorShape>) -> Button
pub fn cursor(self, cursor: impl IntoProp<CursorShape>) -> Button
Sets the cursor shown over the button, instead of the pointing hand.
Sourcepub fn visible(self, visible: impl IntoProp<bool>) -> Self
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.
Sourcepub fn geometry(self, geometry: Signal<Rect>) -> Self
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.