crude toggle touch impl
This commit is contained in:
parent
270b60f660
commit
dc09da8878
|
@ -1,11 +1,13 @@
|
||||||
//! Show toggle controls using togglers.
|
//! Show toggle controls using togglers.
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
use crate::touch::Finger;
|
||||||
use crate::{
|
use crate::{
|
||||||
event, layout, mouse, row, text, Align, Clipboard, Element, Event, Hasher,
|
event, layout, mouse, row, text, touch, Align, Clipboard, Element, Event,
|
||||||
HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
|
Hasher, HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
|
||||||
VerticalAlignment, Widget,
|
VerticalAlignment, Widget,
|
||||||
};
|
};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
/// A toggler widget
|
/// A toggler widget
|
||||||
///
|
///
|
||||||
|
@ -34,6 +36,8 @@ pub struct Toggler<Message, Renderer: self::Renderer + text::Renderer> {
|
||||||
spacing: u16,
|
spacing: u16,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
style: Renderer::Style,
|
style: Renderer::Style,
|
||||||
|
|
||||||
|
fingers_mid_press: HashSet<Finger>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message, Renderer: self::Renderer + text::Renderer>
|
impl<Message, Renderer: self::Renderer + text::Renderer>
|
||||||
|
@ -66,6 +70,8 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
|
||||||
spacing: 0,
|
spacing: 0,
|
||||||
font: Renderer::Font::default(),
|
font: Renderer::Font::default(),
|
||||||
style: Renderer::Style::default(),
|
style: Renderer::Style::default(),
|
||||||
|
|
||||||
|
fingers_mid_press: HashSet::with_capacity(2),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +182,44 @@ where
|
||||||
}
|
}
|
||||||
Event::Touch(x) => {
|
Event::Touch(x) => {
|
||||||
eprintln!("{:?}", 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
|
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,
|
_ => event::Status::Ignored,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue