tappable only.Expand description
Makes any content respond to taps and long presses, by finger or mouse, without stopping a surrounding scrollable from scrolling.
A button captures the finger that presses it, so a list made of buttons can only be dragged from outside its rows. A tappable never captures a finger: it watches the press, and a finger that moves further than the slop is a drag, which cancels the tap and leaves the scrolling to the scrollable around it.
| Input | Result |
|---|---|
| Finger or left button pressed and lifted within the slop | on_tap |
| Finger or left button held for the hold time | on_long_press, and the lift is ignored |
| Right click | on_long_press |
| Finger moved beyond the slop, a second finger, or a lost finger | Cancelled |
Content gets every event first. A press on content that is interactive
under the pointer, such as a button or a tappable nested in the row,
belongs to the content: the row is not tapped as well. A nested button
also captures the finger, so a drag that starts on it does not scroll;
keep nested controls small, or make them tappables too. Links in rich
text count as interactive, so wrap such text in touch_clicks for a tap
to open them.
use iced::widget::text;
use iced_cube::tappable;
#[derive(Debug, Clone)]
enum Message { Open(u32), Menu(u32) }
let row: iced::Element<'_, Message> = tappable(text("Shopping list"))
.on_tap(Message::Open(7))
.on_long_press(Message::Menu(7))
.width(iced::Length::Fill)
.padding(12)
.into();Structs§
- Tappable
- A tappable builder. Convert it into an
Elementto render. - Tracker
- The gesture logic of a tappable, free of any widget, so it can be driven and tested directly.
Enums§
- Gesture
- What a finished interaction means.
- Pointer
- The finger or mouse button that started a press.
- Status
- The interaction state a tappable is drawn in.
Constants§
- DEFAULT_
HOLD - How long a press must be held to count as a long press.
- DEFAULT_
SLOP - How far, in logical pixels, a press may move and still be a tap.