crude toggle touch impl
This commit is contained in:
parent
270b60f660
commit
dc09da8878
|
@ -1,11 +1,13 @@
|
|||
//! Show toggle controls using togglers.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::touch::Finger;
|
||||
use crate::{
|
||||
event, layout, mouse, row, text, Align, Clipboard, Element, Event, Hasher,
|
||||
HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
|
||||
event, layout, mouse, row, text, touch, Align, Clipboard, Element, Event,
|
||||
Hasher, HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
|
||||
VerticalAlignment, Widget,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// A toggler widget
|
||||
///
|
||||
|
@ -34,6 +36,8 @@ pub struct Toggler<Message, Renderer: self::Renderer + text::Renderer> {
|
|||
spacing: u16,
|
||||
font: Renderer::Font,
|
||||
style: Renderer::Style,
|
||||
|
||||
fingers_mid_press: HashSet<Finger>,
|
||||
}
|
||||
|
||||
impl<Message, Renderer: self::Renderer + text::Renderer>
|
||||
|
@ -66,6 +70,8 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
|
|||
spacing: 0,
|
||||
font: Renderer::Font::default(),
|
||||
style: Renderer::Style::default(),
|
||||
|
||||
fingers_mid_press: HashSet::with_capacity(2),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,8 +182,44 @@ where
|
|||
}
|
||||
Event::Touch(x) => {
|
||||
eprintln!("{:?}", x);
|
||||
|
||||
match x {
|
||||
touch::Event::FingerPressed { id, position } => {
|
||||
if layout.bounds().contains(position) {
|
||||
let _ = self.fingers_mid_press.insert(id);
|
||||
|
||||
event::Status::Captured
|
||||
} else {
|
||||
event::Status::Ignored
|
||||
}
|
||||
}
|
||||
touch::Event::FingerMoved { id, position } => {
|
||||
if !layout.bounds().contains(position) {
|
||||
let _ = self.fingers_mid_press.remove(&id);
|
||||
|
||||
event::Status::Captured
|
||||
} else {
|
||||
event::Status::Ignored
|
||||
}
|
||||
}
|
||||
touch::Event::FingerLifted { id, position } => {
|
||||
if self.fingers_mid_press.remove(&id)
|
||||
&& layout.bounds().contains(position)
|
||||
{
|
||||
// this should be treated as a click
|
||||
messages.push((self.on_toggle)(!self.is_active));
|
||||
|
||||
event::Status::Captured
|
||||
} else {
|
||||
event::Status::Ignored
|
||||
}
|
||||
}
|
||||
touch::Event::FingerLost { id, .. } => {
|
||||
let _ = self.fingers_mid_press.remove(&id);
|
||||
event::Status::Ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => event::Status::Ignored,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue