diff options
Diffstat (limited to '')
| -rw-r--r-- | native/src/widget/button.rs | 24 | ||||
| -rw-r--r-- | native/src/widget/checkbox.rs | 7 | ||||
| -rw-r--r-- | native/src/widget/radio.rs | 7 | ||||
| -rw-r--r-- | native/src/widget/scrollable.rs | 56 | ||||
| -rw-r--r-- | native/src/widget/slider.rs | 17 | ||||
| -rw-r--r-- | native/src/widget/text_input.rs | 7 | 
6 files changed, 85 insertions, 33 deletions
| diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index 8c397bc1..81dbe7c5 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -5,7 +5,7 @@  //! [`Button`]: struct.Button.html  //! [`State`]: struct.State.html  use crate::{ -    input::{mouse, touch::Touch, ButtonState}, +    input::{mouse, touch, ButtonState, Touch},      layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,      Rectangle, Widget,  }; @@ -189,16 +189,24 @@ where                  button: mouse::Button::Left,                  state: ButtonState::Pressed,              }) -            | Event::Touch(Touch::Started { .. }) => { -                let bounds = layout.bounds(); +            | Event::Touch(Touch { +                phase: touch::Phase::Started, +                .. +            }) => { +                if self.on_press.is_some() { +                    let bounds = layout.bounds(); -                self.state.is_pressed = bounds.contains(cursor_position); +                    self.state.is_pressed = bounds.contains(cursor_position); +                }              }              Event::Mouse(mouse::Event::Input {                  button: mouse::Button::Left,                  state: ButtonState::Released,              }) -            | Event::Touch(Touch::Ended { .. }) => { +            | Event::Touch(Touch { +                phase: touch::Phase::Ended, +                .. +            }) => {                  if let Some(on_press) = self.on_press.clone() {                      let bounds = layout.bounds();                      let is_clicked = self.state.is_pressed @@ -211,6 +219,12 @@ where                      }                  }              } +            Event::Touch(Touch { +                phase: touch::Phase::Canceled, +                .. +            }) => { +                self.state.is_pressed = false; +            }              _ => {}          }      } diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 26665d8b..7b2345de 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -2,7 +2,7 @@  use std::hash::Hash;  use crate::{ -    input::{mouse, touch::Touch, ButtonState}, +    input::{mouse, touch, ButtonState, Touch},      layout, row, text, Align, Clipboard, Element, Event, Font, Hasher,      HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,      VerticalAlignment, Widget, @@ -156,7 +156,10 @@ where                  button: mouse::Button::Left,                  state: ButtonState::Pressed,              }) -            | Event::Touch(Touch::Started { .. }) => { +            | Event::Touch(Touch { +                phase: touch::Phase::Started, +                .. +            }) => {                  let mouse_over = layout.bounds().contains(cursor_position);                  if mouse_over { diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index 8a9c02ce..46983db3 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -1,6 +1,6 @@  //! Create choices using radio buttons.  use crate::{ -    input::{mouse, touch, ButtonState}, +    input::{mouse, touch, ButtonState, Touch},      layout, row, text, Align, Clipboard, Element, Event, Font, Hasher,      HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,      VerticalAlignment, Widget, @@ -122,7 +122,10 @@ where                  button: mouse::Button::Left,                  state: ButtonState::Pressed,              }) -            | Event::Touch(touch::Touch::Started { .. }) => { +            | Event::Touch(Touch { +                phase: touch::Phase::Started, +                .. +            }) => {                  if layout.bounds().contains(cursor_position) {                      messages.push(self.on_click.clone());                  } diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 2a658bcc..2f5a4820 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -1,7 +1,7 @@  //! Navigate an endless amount of content with a scrollbar.  use crate::{      column, -    input::{mouse, touch, ButtonState}, +    input::{mouse, touch, ButtonState, Touch},      layout, Align, Clipboard, Column, Element, Event, Hasher, Layout, Length,      Point, Rectangle, Size, Widget,  }; @@ -175,22 +175,26 @@ where                          }                      }                  } -                Event::Touch(touch::Touch::Started { .. }) => { -                    self.state.scroll_box_touched_at = Some(cursor_position); -                } -                Event::Touch(touch::Touch::Moved { .. }) => { -                    if let Some(scroll_box_touched_at) = -                        self.state.scroll_box_touched_at -                    { -                        let delta = cursor_position.y - scroll_box_touched_at.y; -                        self.state.scroll(delta, bounds, content_bounds); +                Event::Touch(Touch { phase, .. }) => match phase { +                    touch::Phase::Started => {                          self.state.scroll_box_touched_at =                              Some(cursor_position);                      } -                } -                Event::Touch(touch::Touch::Ended { .. }) => { -                    self.state.scroll_box_touched_at = None; -                } +                    touch::Phase::Moved => { +                        if let Some(scroll_box_touched_at) = +                            self.state.scroll_box_touched_at +                        { +                            let delta = +                                cursor_position.y - scroll_box_touched_at.y; +                            self.state.scroll(delta, bounds, content_bounds); +                            self.state.scroll_box_touched_at = +                                Some(cursor_position); +                        } +                    } +                    touch::Phase::Ended | touch::Phase::Canceled => { +                        self.state.scroll_box_touched_at = None; +                    } +                },                  _ => {}              }          } @@ -208,14 +212,24 @@ where                      button: mouse::Button::Left,                      state: ButtonState::Released,                  }) -                | Event::Touch(touch::Touch::Ended { .. }) => { +                | Event::Touch(Touch { +                    phase: touch::Phase::Ended, +                    .. +                }) +                | Event::Touch(Touch { +                    phase: touch::Phase::Canceled, +                    .. +                }) => {                      self.state.scroller_grabbed_at = None;                  }                  Event::Mouse(mouse::Event::Input {                      button: mouse::Button::Left,                      state: ButtonState::Pressed,                  }) -                | Event::Touch(touch::Touch::Started { .. }) => { +                | Event::Touch(Touch { +                    phase: touch::Phase::Started, +                    .. +                }) => {                      self.state.scroll_to(                          cursor_position.y / (bounds.y + bounds.height),                          bounds, @@ -223,7 +237,10 @@ where                      );                  }                  Event::Mouse(mouse::Event::CursorMoved { .. }) -                | Event::Touch(touch::Touch::Moved { .. }) => { +                | Event::Touch(Touch { +                    phase: touch::Phase::Moved, +                    .. +                }) => {                      if let (Some(scrollbar), Some(scroller_grabbed_at)) =                          (scrollbar, self.state.scroller_grabbed_at)                      { @@ -245,7 +262,10 @@ where                      button: mouse::Button::Left,                      state: ButtonState::Pressed,                  }) -                | Event::Touch(touch::Touch::Started { .. }) => { +                | Event::Touch(Touch { +                    phase: touch::Phase::Started, +                    .. +                }) => {                      if let Some(scrollbar) = scrollbar {                          if let Some(scroller_grabbed_at) =                              scrollbar.grab_scroller(cursor_position) diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index 95f63921..c98cebb6 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -5,7 +5,7 @@  //! [`Slider`]: struct.Slider.html  //! [`State`]: struct.State.html  use crate::{ -    input::{mouse, touch::Touch, ButtonState}, +    input::{mouse, touch, ButtonState, Touch},      layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,      Rectangle, Size, Widget,  }; @@ -168,7 +168,10 @@ where                  button: mouse::Button::Left,                  state: ButtonState::Pressed,              }) -            | Event::Touch(Touch::Started { .. }) => { +            | Event::Touch(Touch { +                phase: touch::Phase::Started, +                .. +            }) => {                  if layout.bounds().contains(cursor_position) {                      change();                      self.state.is_dragging = true; @@ -178,11 +181,17 @@ where                  button: mouse::Button::Left,                  state: ButtonState::Released,              }) -            | Event::Touch(Touch::Ended { .. }) => { +            | Event::Touch(Touch { +                phase: touch::Phase::Ended, +                .. +            }) => {                  self.state.is_dragging = false;              }              Event::Mouse(mouse::Event::CursorMoved { .. }) -            | Event::Touch(Touch::Moved { .. }) => { +            | Event::Touch(Touch { +                phase: touch::Phase::Moved, +                .. +            }) => {                  if self.state.is_dragging {                      change();                  } diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 9cfc6bf0..c06a8cce 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -5,7 +5,7 @@  //! [`TextInput`]: struct.TextInput.html  //! [`State`]: struct.State.html  use crate::{ -    input::{keyboard, mouse, touch, ButtonState}, +    input::{keyboard, mouse, touch, ButtonState, Touch},      layout, Clipboard, Element, Event, Font, Hasher, Layout, Length, Point,      Rectangle, Size, Widget,  }; @@ -203,7 +203,10 @@ where                  button: mouse::Button::Left,                  state: ButtonState::Pressed,              }) -            | Event::Touch(touch::Touch::Started { .. }) => { +            | Event::Touch(Touch { +                phase: touch::Phase::Started, +                .. +            }) => {                  let is_clicked = layout.bounds().contains(cursor_position);                  if is_clicked { | 
