Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
Olivier 'reivilibre' | 747715f588 | |
Olivier 'reivilibre' | 589f3beba5 | |
Olivier 'reivilibre' | 9e9baa725b | |
Olivier 'reivilibre' | 340601f526 | |
Olivier 'reivilibre' | 9cdd7c5527 | |
Olivier 'reivilibre' | 05abfc00cc | |
Olivier 'reivilibre' | 1d3010ca84 | |
Olivier 'reivilibre' | cdb828c4e5 | |
Olivier 'reivilibre' | dc09da8878 | |
Olivier 'reivilibre' | 270b60f660 |
|
@ -1,5 +1,5 @@
|
|||
//! Create interactive, native cross-platform applications.
|
||||
use crate::{mouse, Error, Executor, Runtime};
|
||||
use crate::{mouse, Error, Executor, Runtime, Vector};
|
||||
|
||||
pub use iced_winit::Application;
|
||||
|
||||
|
@ -187,6 +187,7 @@ async fn run_instance<A, E, C>(
|
|||
let statuses = user_interface.update(
|
||||
&events,
|
||||
state.cursor_position(),
|
||||
Vector::new(0.0, 0.0),
|
||||
&mut renderer,
|
||||
&mut clipboard,
|
||||
&mut messages,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{
|
||||
Clipboard, Color, Hasher, Layout, Length, Point, Rectangle, Widget,
|
||||
};
|
||||
|
@ -223,6 +223,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -231,6 +232,7 @@ where
|
|||
event,
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
@ -311,6 +313,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<B>,
|
||||
|
@ -321,6 +324,7 @@ where
|
|||
event,
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
&mut original_messages,
|
||||
|
@ -401,6 +405,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -409,6 +414,7 @@ where
|
|||
event,
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -7,7 +7,7 @@ pub use element::Element;
|
|||
pub use menu::Menu;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{Clipboard, Hasher, Layout, Point, Size};
|
||||
|
||||
/// An interactive component that can be displayed on top of other widgets.
|
||||
|
@ -67,6 +67,7 @@ where
|
|||
_event: Event,
|
||||
_layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
_messages: &mut Vec<Message>,
|
||||
|
|
|
@ -53,6 +53,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -61,6 +62,7 @@ where
|
|||
event,
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
@ -117,6 +119,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<B>,
|
||||
|
@ -127,6 +130,7 @@ where
|
|||
event,
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
&mut original_messages,
|
||||
|
|
|
@ -219,6 +219,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -227,6 +228,7 @@ where
|
|||
event.clone(),
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
@ -320,6 +322,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
_messages: &mut Vec<Message>,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
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
|
||||
|
@ -90,6 +91,7 @@ where
|
|||
&mut self,
|
||||
bounds: Size,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &mut P::Renderer,
|
||||
clipboard: &mut P::Clipboard,
|
||||
debug: &mut Debug,
|
||||
|
@ -108,6 +110,7 @@ where
|
|||
let _ = user_interface.update(
|
||||
&self.queued_events,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
&mut messages,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{Clipboard, Element, Layout, Point, Rectangle, Size};
|
||||
|
||||
use std::hash::Hasher;
|
||||
|
@ -194,6 +194,7 @@ where
|
|||
&mut self,
|
||||
events: &[Event],
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -216,6 +217,7 @@ where
|
|||
event,
|
||||
Layout::new(&layer.layout),
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
@ -247,6 +249,7 @@ where
|
|||
event,
|
||||
Layout::new(&self.base.layout),
|
||||
base_cursor,
|
||||
Vector::new(0.0, 0.0),
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -79,8 +79,8 @@ pub use toggler::Toggler;
|
|||
pub use tooltip::Tooltip;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{Clipboard, Hasher, Layout, Length, Point, Rectangle};
|
||||
|
||||
/// A component that displays information and allows interaction.
|
||||
|
@ -167,6 +167,7 @@ where
|
|||
_event: Event,
|
||||
_layout: Layout<'_>,
|
||||
_cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
_messages: &mut Vec<Message>,
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
//!
|
||||
//! A [`Button`] has some local [`State`].
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::overlay;
|
||||
use crate::touch;
|
||||
use crate::touch::Finger;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle,
|
||||
Widget,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use std::hash::Hash;
|
||||
|
||||
/// A generic widget that produces a message when pressed.
|
||||
|
@ -63,6 +65,7 @@ pub struct Button<'a, Message, Renderer: self::Renderer> {
|
|||
min_height: u32,
|
||||
padding: Padding,
|
||||
style: Renderer::Style,
|
||||
fingers_mid_press: HashSet<Finger>,
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> Button<'a, Message, Renderer>
|
||||
|
@ -86,6 +89,8 @@ where
|
|||
min_height: 0,
|
||||
padding: Renderer::DEFAULT_PADDING,
|
||||
style: Renderer::Style::default(),
|
||||
|
||||
fingers_mid_press: HashSet::with_capacity(2),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,6 +193,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -196,6 +202,7 @@ where
|
|||
event.clone(),
|
||||
layout.children().next().unwrap(),
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
@ -204,8 +211,7 @@ where
|
|||
}
|
||||
|
||||
match event {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
|
||||
| Event::Touch(touch::Event::FingerPressed { .. }) => {
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
||||
if self.on_press.is_some() {
|
||||
let bounds = layout.bounds();
|
||||
|
||||
|
@ -216,8 +222,7 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
|
||||
| Event::Touch(touch::Event::FingerLifted { .. }) => {
|
||||
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) => {
|
||||
if let Some(on_press) = self.on_press.clone() {
|
||||
let bounds = layout.bounds();
|
||||
|
||||
|
@ -232,8 +237,46 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
Event::Touch(touch::Event::FingerLost { .. }) => {
|
||||
self.state.is_pressed = false;
|
||||
Event::Touch(x) => {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
use std::hash::Hash;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::row;
|
||||
use crate::text;
|
||||
use crate::touch;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{
|
||||
Align, Clipboard, Color, Element, Hasher, HorizontalAlignment, Layout,
|
||||
Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget,
|
||||
|
@ -158,6 +158,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
use std::hash::Hash;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{
|
||||
Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
|
||||
Rectangle, Widget,
|
||||
|
@ -142,6 +142,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -154,6 +155,7 @@ where
|
|||
event.clone(),
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
use std::hash::Hash;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{
|
||||
Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
|
||||
Rectangle, Widget,
|
||||
|
@ -153,6 +153,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -161,6 +162,7 @@ where
|
|||
event,
|
||||
layout.children().next().unwrap(),
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -155,6 +155,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
_messages: &mut Vec<Message>,
|
||||
|
|
|
@ -362,6 +362,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -461,6 +462,7 @@ where
|
|||
event.clone(),
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::container;
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::pane_grid::{self, TitleBar};
|
||||
use crate::{container, Vector};
|
||||
use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size};
|
||||
|
||||
/// The content of a [`Pane`].
|
||||
|
@ -146,6 +146,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -159,6 +160,7 @@ where
|
|||
event.clone(),
|
||||
children.next().unwrap(),
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
@ -173,6 +175,7 @@ where
|
|||
event,
|
||||
body_layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::container;
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::pane_grid;
|
||||
use crate::{container, Vector};
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Padding, Point, Rectangle, Size,
|
||||
};
|
||||
|
@ -207,6 +207,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -224,6 +225,7 @@ where
|
|||
event.clone(),
|
||||
controls_layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
@ -236,6 +238,7 @@ where
|
|||
event,
|
||||
title_layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
//! Display a dropdown list of selectable values.
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::overlay;
|
||||
use crate::overlay::menu::{self, Menu};
|
||||
use crate::scrollable;
|
||||
use crate::text;
|
||||
use crate::touch;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle,
|
||||
Size, Widget,
|
||||
|
@ -211,6 +211,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
use std::hash::Hash;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::mouse;
|
||||
use crate::row;
|
||||
use crate::text;
|
||||
use crate::touch;
|
||||
use crate::{layout, Color};
|
||||
use crate::{mouse, Vector};
|
||||
use crate::{
|
||||
Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length,
|
||||
Point, Rectangle, Row, Text, VerticalAlignment, Widget,
|
||||
|
@ -172,6 +172,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Distribute content horizontally.
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::overlay;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{
|
||||
Align, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
|
||||
Rectangle, Widget,
|
||||
|
@ -141,6 +141,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -153,6 +154,7 @@ where
|
|||
event.clone(),
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -192,6 +192,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -235,6 +236,7 @@ where
|
|||
event.clone(),
|
||||
content,
|
||||
cursor_position,
|
||||
scroll_offset + Vector::new(0.0, self.state.offset.absolute(bounds, content_bounds)),
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
//!
|
||||
//! A [`Slider`] has some local [`State`].
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::touch;
|
||||
use crate::{layout, Vector};
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
||||
};
|
||||
|
@ -180,6 +180,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
|
|
@ -12,11 +12,11 @@ pub use value::Value;
|
|||
use editor::Editor;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::keyboard;
|
||||
use crate::layout;
|
||||
use crate::mouse::{self, click};
|
||||
use crate::text;
|
||||
use crate::touch;
|
||||
use crate::{keyboard, Vector};
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle,
|
||||
Size, Widget,
|
||||
|
@ -246,6 +246,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
_scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
|
|
@ -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,
|
||||
VerticalAlignment, Widget,
|
||||
event, layout, mouse, row, text, touch, Align, Clipboard, Element, Event,
|
||||
Hasher, HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
|
||||
Vector, 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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,6 +164,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
_renderer: &Renderer,
|
||||
_clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -174,6 +181,45 @@ where
|
|||
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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::widget::container;
|
|||
use crate::widget::text::{self, Text};
|
||||
use crate::{
|
||||
event, layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||
Widget,
|
||||
Vector, Widget,
|
||||
};
|
||||
|
||||
/// An element to display a widget over another.
|
||||
|
@ -120,6 +120,7 @@ where
|
|||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
scroll_offset: Vector<f32>,
|
||||
renderer: &Renderer,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
messages: &mut Vec<Message>,
|
||||
|
@ -128,6 +129,7 @@ where
|
|||
event,
|
||||
layout,
|
||||
cursor_position,
|
||||
scroll_offset,
|
||||
renderer,
|
||||
clipboard,
|
||||
messages,
|
||||
|
|
|
@ -3,8 +3,8 @@ mod state;
|
|||
|
||||
pub use state::State;
|
||||
|
||||
use crate::conversion;
|
||||
use crate::mouse;
|
||||
use crate::{conversion, Vector};
|
||||
use crate::{
|
||||
Clipboard, Color, Command, Debug, Error, Executor, Mode, Proxy, Runtime,
|
||||
Settings, Size, Subscription,
|
||||
|
@ -261,6 +261,7 @@ async fn run_instance<A, E, C>(
|
|||
let statuses = user_interface.update(
|
||||
&events,
|
||||
state.cursor_position(),
|
||||
Vector::new(0.0, 0.0),
|
||||
&mut renderer,
|
||||
&mut clipboard,
|
||||
&mut messages,
|
||||
|
|
Loading…
Reference in New Issue