Compare commits

..

10 Commits

25 changed files with 164 additions and 28 deletions

View File

@ -1,5 +1,5 @@
//! Create interactive, native cross-platform applications. //! Create interactive, native cross-platform applications.
use crate::{mouse, Error, Executor, Runtime}; use crate::{mouse, Error, Executor, Runtime, Vector};
pub use iced_winit::Application; pub use iced_winit::Application;
@ -187,6 +187,7 @@ async fn run_instance<A, E, C>(
let statuses = user_interface.update( let statuses = user_interface.update(
&events, &events,
state.cursor_position(), state.cursor_position(),
Vector::new(0.0, 0.0),
&mut renderer, &mut renderer,
&mut clipboard, &mut clipboard,
&mut messages, &mut messages,

View File

@ -1,6 +1,6 @@
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{layout, Vector};
use crate::{ use crate::{
Clipboard, Color, Hasher, Layout, Length, Point, Rectangle, Widget, Clipboard, Color, Hasher, Layout, Length, Point, Rectangle, Widget,
}; };
@ -223,6 +223,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -231,6 +232,7 @@ where
event, event,
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,
@ -311,6 +313,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<B>, messages: &mut Vec<B>,
@ -321,6 +324,7 @@ where
event, event,
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
&mut original_messages, &mut original_messages,
@ -401,6 +405,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -409,6 +414,7 @@ where
event, event,
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -7,7 +7,7 @@ pub use element::Element;
pub use menu::Menu; pub use menu::Menu;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::{layout, Vector};
use crate::{Clipboard, Hasher, Layout, Point, Size}; use crate::{Clipboard, Hasher, Layout, Point, Size};
/// An interactive component that can be displayed on top of other widgets. /// An interactive component that can be displayed on top of other widgets.
@ -67,6 +67,7 @@ where
_event: Event, _event: Event,
_layout: Layout<'_>, _layout: Layout<'_>,
_cursor_position: Point, _cursor_position: Point,
_scroll_offset: Vector<f32>,
_renderer: &Renderer, _renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
_messages: &mut Vec<Message>, _messages: &mut Vec<Message>,

View File

@ -53,6 +53,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -61,6 +62,7 @@ where
event, event,
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,
@ -117,6 +119,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<B>, messages: &mut Vec<B>,
@ -127,6 +130,7 @@ where
event, event,
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
&mut original_messages, &mut original_messages,

View File

@ -219,6 +219,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -227,6 +228,7 @@ where
event.clone(), event.clone(),
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,
@ -320,6 +322,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
_messages: &mut Vec<Message>, _messages: &mut Vec<Message>,

View File

@ -1,5 +1,6 @@
use crate::{ use crate::{
Cache, Command, Debug, Event, Point, Program, Renderer, Size, UserInterface, Cache, Command, Debug, Event, Point, Program, Renderer, Size,
UserInterface, Vector,
}; };
/// The execution state of a [`Program`]. It leverages caching, event /// The execution state of a [`Program`]. It leverages caching, event
@ -90,6 +91,7 @@ where
&mut self, &mut self,
bounds: Size, bounds: Size,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &mut P::Renderer, renderer: &mut P::Renderer,
clipboard: &mut P::Clipboard, clipboard: &mut P::Clipboard,
debug: &mut Debug, debug: &mut Debug,
@ -108,6 +110,7 @@ where
let _ = user_interface.update( let _ = user_interface.update(
&self.queued_events, &self.queued_events,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
&mut messages, &mut messages,

View File

@ -1,6 +1,6 @@
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{layout, Vector};
use crate::{Clipboard, Element, Layout, Point, Rectangle, Size}; use crate::{Clipboard, Element, Layout, Point, Rectangle, Size};
use std::hash::Hasher; use std::hash::Hasher;
@ -194,6 +194,7 @@ where
&mut self, &mut self,
events: &[Event], events: &[Event],
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -216,6 +217,7 @@ where
event, event,
Layout::new(&layer.layout), Layout::new(&layer.layout),
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,
@ -247,6 +249,7 @@ where
event, event,
Layout::new(&self.base.layout), Layout::new(&self.base.layout),
base_cursor, base_cursor,
Vector::new(0.0, 0.0),
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -79,8 +79,8 @@ pub use toggler::Toggler;
pub use tooltip::Tooltip; pub use tooltip::Tooltip;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{layout, Vector};
use crate::{Clipboard, Hasher, Layout, Length, Point, Rectangle}; use crate::{Clipboard, Hasher, Layout, Length, Point, Rectangle};
/// A component that displays information and allows interaction. /// A component that displays information and allows interaction.
@ -167,6 +167,7 @@ where
_event: Event, _event: Event,
_layout: Layout<'_>, _layout: Layout<'_>,
_cursor_position: Point, _cursor_position: Point,
_scroll_offset: Vector<f32>,
_renderer: &Renderer, _renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
_messages: &mut Vec<Message>, _messages: &mut Vec<Message>,

View File

@ -2,14 +2,16 @@
//! //!
//! A [`Button`] has some local [`State`]. //! A [`Button`] has some local [`State`].
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::mouse; use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::touch; use crate::touch;
use crate::touch::Finger;
use crate::{layout, Vector};
use crate::{ use crate::{
Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle,
Widget, Widget,
}; };
use std::collections::HashSet;
use std::hash::Hash; use std::hash::Hash;
/// A generic widget that produces a message when pressed. /// A generic widget that produces a message when pressed.
@ -63,6 +65,7 @@ pub struct Button<'a, Message, Renderer: self::Renderer> {
min_height: u32, min_height: u32,
padding: Padding, padding: Padding,
style: Renderer::Style, style: Renderer::Style,
fingers_mid_press: HashSet<Finger>,
} }
impl<'a, Message, Renderer> Button<'a, Message, Renderer> impl<'a, Message, Renderer> Button<'a, Message, Renderer>
@ -86,6 +89,8 @@ where
min_height: 0, min_height: 0,
padding: Renderer::DEFAULT_PADDING, padding: Renderer::DEFAULT_PADDING,
style: Renderer::Style::default(), style: Renderer::Style::default(),
fingers_mid_press: HashSet::with_capacity(2),
} }
} }
@ -188,6 +193,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -196,6 +202,7 @@ where
event.clone(), event.clone(),
layout.children().next().unwrap(), layout.children().next().unwrap(),
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,
@ -204,8 +211,7 @@ where
} }
match event { match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
| Event::Touch(touch::Event::FingerPressed { .. }) => {
if self.on_press.is_some() { if self.on_press.is_some() {
let bounds = layout.bounds(); let bounds = layout.bounds();
@ -216,8 +222,7 @@ where
} }
} }
} }
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) => {
| Event::Touch(touch::Event::FingerLifted { .. }) => {
if let Some(on_press) = self.on_press.clone() { if let Some(on_press) = self.on_press.clone() {
let bounds = layout.bounds(); let bounds = layout.bounds();
@ -232,8 +237,46 @@ where
} }
} }
} }
Event::Touch(touch::Event::FingerLost { .. }) => { Event::Touch(x) => {
self.state.is_pressed = false; eprintln!(
"B {:?} Bds {:?} P {:?}",
x,
layout.bounds(),
self.fingers_mid_press
);
match x {
touch::Event::FingerPressed { id, position } => {
if layout.bounds().contains(position + scroll_offset) {
eprintln!("ins");
let _ = self.fingers_mid_press.insert(id);
return event::Status::Captured;
}
}
touch::Event::FingerMoved { id, position } => {
if !layout.bounds().contains(position + scroll_offset) {
eprintln!("exited");
let _ = self.fingers_mid_press.remove(&id);
} else {
return event::Status::Captured;
}
}
touch::Event::FingerLifted { id, .. } => {
// !!! The finger position seems to be buggy on the Lift event.
if self.fingers_mid_press.remove(&id) {
eprintln!("lifted");
// this should be treated as a click
if let Some(on_press) = self.on_press.clone() {
messages.push(on_press);
}
return event::Status::Captured;
}
}
touch::Event::FingerLost { id, .. } => {
let _ = self.fingers_mid_press.remove(&id);
}
}
} }
_ => {} _ => {}
} }

View File

@ -2,11 +2,11 @@
use std::hash::Hash; use std::hash::Hash;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::mouse; use crate::mouse;
use crate::row; use crate::row;
use crate::text; use crate::text;
use crate::touch; use crate::touch;
use crate::{layout, Vector};
use crate::{ use crate::{
Align, Clipboard, Color, Element, Hasher, HorizontalAlignment, Layout, Align, Clipboard, Color, Element, Hasher, HorizontalAlignment, Layout,
Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget, Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget,
@ -158,6 +158,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_scroll_offset: Vector<f32>,
_renderer: &Renderer, _renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,

View File

@ -2,8 +2,8 @@
use std::hash::Hash; use std::hash::Hash;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{layout, Vector};
use crate::{ use crate::{
Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
Rectangle, Widget, Rectangle, Widget,
@ -142,6 +142,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -154,6 +155,7 @@ where
event.clone(), event.clone(),
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -2,8 +2,8 @@
use std::hash::Hash; use std::hash::Hash;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{layout, Vector};
use crate::{ use crate::{
Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
Rectangle, Widget, Rectangle, Widget,
@ -153,6 +153,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -161,6 +162,7 @@ where
event, event,
layout.children().next().unwrap(), layout.children().next().unwrap(),
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -155,6 +155,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
_messages: &mut Vec<Message>, _messages: &mut Vec<Message>,

View File

@ -362,6 +362,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -461,6 +462,7 @@ where
event.clone(), event.clone(),
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -1,8 +1,8 @@
use crate::container;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::overlay; use crate::overlay;
use crate::pane_grid::{self, TitleBar}; use crate::pane_grid::{self, TitleBar};
use crate::{container, Vector};
use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size}; use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size};
/// The content of a [`Pane`]. /// The content of a [`Pane`].
@ -146,6 +146,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -159,6 +160,7 @@ where
event.clone(), event.clone(),
children.next().unwrap(), children.next().unwrap(),
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,
@ -173,6 +175,7 @@ where
event, event,
body_layout, body_layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -1,8 +1,8 @@
use crate::container;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::overlay; use crate::overlay;
use crate::pane_grid; use crate::pane_grid;
use crate::{container, Vector};
use crate::{ use crate::{
Clipboard, Element, Hasher, Layout, Padding, Point, Rectangle, Size, Clipboard, Element, Hasher, Layout, Padding, Point, Rectangle, Size,
}; };
@ -207,6 +207,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -224,6 +225,7 @@ where
event.clone(), event.clone(),
controls_layout, controls_layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,
@ -236,6 +238,7 @@ where
event, event,
title_layout, title_layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -1,12 +1,12 @@
//! Display a dropdown list of selectable values. //! Display a dropdown list of selectable values.
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::mouse; use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::overlay::menu::{self, Menu}; use crate::overlay::menu::{self, Menu};
use crate::scrollable; use crate::scrollable;
use crate::text; use crate::text;
use crate::touch; use crate::touch;
use crate::{layout, Vector};
use crate::{ use crate::{
Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle,
Size, Widget, Size, Widget,
@ -211,6 +211,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_scroll_offset: Vector<f32>,
_renderer: &Renderer, _renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,

View File

@ -2,11 +2,11 @@
use std::hash::Hash; use std::hash::Hash;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::mouse;
use crate::row; use crate::row;
use crate::text; use crate::text;
use crate::touch; use crate::touch;
use crate::{layout, Color}; use crate::{layout, Color};
use crate::{mouse, Vector};
use crate::{ use crate::{
Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length, Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length,
Point, Rectangle, Row, Text, VerticalAlignment, Widget, Point, Rectangle, Row, Text, VerticalAlignment, Widget,
@ -172,6 +172,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_scroll_offset: Vector<f32>,
_renderer: &Renderer, _renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,

View File

@ -1,7 +1,7 @@
//! Distribute content horizontally. //! Distribute content horizontally.
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{layout, Vector};
use crate::{ use crate::{
Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
Rectangle, Widget, Rectangle, Widget,
@ -141,6 +141,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -153,6 +154,7 @@ where
event.clone(), event.clone(),
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -192,6 +192,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -235,6 +236,7 @@ where
event.clone(), event.clone(),
content, content,
cursor_position, cursor_position,
scroll_offset + Vector::new(0.0, self.state.offset.absolute(bounds, content_bounds)),
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -2,9 +2,9 @@
//! //!
//! A [`Slider`] has some local [`State`]. //! A [`Slider`] has some local [`State`].
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::mouse; use crate::mouse;
use crate::touch; use crate::touch;
use crate::{layout, Vector};
use crate::{ use crate::{
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
}; };
@ -180,6 +180,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_scroll_offset: Vector<f32>,
_renderer: &Renderer, _renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,

View File

@ -12,11 +12,11 @@ pub use value::Value;
use editor::Editor; use editor::Editor;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::keyboard;
use crate::layout; use crate::layout;
use crate::mouse::{self, click}; use crate::mouse::{self, click};
use crate::text; use crate::text;
use crate::touch; use crate::touch;
use crate::{keyboard, Vector};
use crate::{ use crate::{
Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle,
Size, Widget, Size, Widget,
@ -246,6 +246,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,

View File

@ -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, Vector, 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),
} }
} }
@ -158,6 +164,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
_renderer: &Renderer, _renderer: &Renderer,
_clipboard: &mut dyn Clipboard, _clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -174,6 +181,45 @@ where
event::Status::Ignored event::Status::Ignored
} }
} }
Event::Touch(x) => {
match x {
touch::Event::FingerPressed { id, position } => {
if layout.bounds().contains(position + scroll_offset) {
let _ = self.fingers_mid_press.insert(id);
event::Status::Captured
} else {
event::Status::Ignored
}
}
touch::Event::FingerMoved { id, position } => {
if !layout.bounds().contains(position + scroll_offset) {
let _ = self.fingers_mid_press.remove(&id);
event::Status::Captured
} else {
event::Status::Ignored
}
}
touch::Event::FingerLifted { id, .. } => {
// !!! The finger position seems to be buggy on the Lift event.
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,
} }
} }

View File

@ -7,7 +7,7 @@ use crate::widget::container;
use crate::widget::text::{self, Text}; use crate::widget::text::{self, Text};
use crate::{ use crate::{
event, layout, Clipboard, Element, Event, Hasher, Layout, Length, Point, event, layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Widget, Vector, Widget,
}; };
/// An element to display a widget over another. /// An element to display a widget over another.
@ -120,6 +120,7 @@ where
event: Event, event: Event,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
scroll_offset: Vector<f32>,
renderer: &Renderer, renderer: &Renderer,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>, messages: &mut Vec<Message>,
@ -128,6 +129,7 @@ where
event, event,
layout, layout,
cursor_position, cursor_position,
scroll_offset,
renderer, renderer,
clipboard, clipboard,
messages, messages,

View File

@ -3,8 +3,8 @@ mod state;
pub use state::State; pub use state::State;
use crate::conversion;
use crate::mouse; use crate::mouse;
use crate::{conversion, Vector};
use crate::{ use crate::{
Clipboard, Color, Command, Debug, Error, Executor, Mode, Proxy, Runtime, Clipboard, Color, Command, Debug, Error, Executor, Mode, Proxy, Runtime,
Settings, Size, Subscription, Settings, Size, Subscription,
@ -261,6 +261,7 @@ async fn run_instance<A, E, C>(
let statuses = user_interface.update( let statuses = user_interface.update(
&events, &events,
state.cursor_position(), state.cursor_position(),
Vector::new(0.0, 0.0),
&mut renderer, &mut renderer,
&mut clipboard, &mut clipboard,
&mut messages, &mut messages,