From bb9ccc4f62ceea08dc1ef0c6c4d3d219897e44a1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 30 Apr 2020 05:04:45 +0200 Subject: Remove inconsistent `input` module in `iced_native` --- native/src/event.rs | 5 +-- native/src/input.rs | 3 -- native/src/input/keyboard.rs | 2 - native/src/input/mouse.rs | 6 --- native/src/input/mouse/click.rs | 76 ------------------------------------ native/src/keyboard.rs | 2 + native/src/lib.rs | 3 +- native/src/mouse.rs | 6 +++ native/src/mouse/click.rs | 76 ++++++++++++++++++++++++++++++++++++ native/src/user_interface.rs | 4 +- native/src/widget/button.rs | 4 +- native/src/widget/checkbox.rs | 2 +- native/src/widget/pane_grid.rs | 5 +-- native/src/widget/pane_grid/state.rs | 2 +- native/src/widget/radio.rs | 2 +- native/src/widget/scrollable.rs | 4 +- native/src/widget/slider.rs | 4 +- native/src/widget/text_input.rs | 12 +++--- 18 files changed, 104 insertions(+), 114 deletions(-) delete mode 100644 native/src/input.rs delete mode 100644 native/src/input/keyboard.rs delete mode 100644 native/src/input/mouse.rs delete mode 100644 native/src/input/mouse/click.rs create mode 100644 native/src/keyboard.rs create mode 100644 native/src/mouse.rs create mode 100644 native/src/mouse/click.rs (limited to 'native') diff --git a/native/src/event.rs b/native/src/event.rs index b2550ead..606a71d6 100644 --- a/native/src/event.rs +++ b/native/src/event.rs @@ -1,7 +1,4 @@ -use crate::{ - input::{keyboard, mouse}, - window, -}; +use crate::{keyboard, mouse, window}; /// A user interface event. /// diff --git a/native/src/input.rs b/native/src/input.rs deleted file mode 100644 index ad8ed252..00000000 --- a/native/src/input.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Map your system events into input events that the runtime can understand. -pub mod keyboard; -pub mod mouse; diff --git a/native/src/input/keyboard.rs b/native/src/input/keyboard.rs deleted file mode 100644 index 012538e3..00000000 --- a/native/src/input/keyboard.rs +++ /dev/null @@ -1,2 +0,0 @@ -//! Track keyboard events. -pub use iced_core::keyboard::*; diff --git a/native/src/input/mouse.rs b/native/src/input/mouse.rs deleted file mode 100644 index 9ee406cf..00000000 --- a/native/src/input/mouse.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Track mouse events. - -pub mod click; - -pub use click::Click; -pub use iced_core::mouse::*; diff --git a/native/src/input/mouse/click.rs b/native/src/input/mouse/click.rs deleted file mode 100644 index d27bc67e..00000000 --- a/native/src/input/mouse/click.rs +++ /dev/null @@ -1,76 +0,0 @@ -//! Track mouse clicks. -use crate::Point; -use std::time::Instant; - -/// A mouse click. -#[derive(Debug, Clone, Copy)] -pub struct Click { - kind: Kind, - position: Point, - time: Instant, -} - -/// The kind of mouse click. -#[derive(Debug, Clone, Copy)] -pub enum Kind { - /// A single click - Single, - - /// A double click - Double, - - /// A triple click - Triple, -} - -impl Kind { - fn next(&self) -> Kind { - match self { - Kind::Single => Kind::Double, - Kind::Double => Kind::Triple, - Kind::Triple => Kind::Double, - } - } -} - -impl Click { - /// Creates a new [`Click`] with the given position and previous last - /// [`Click`]. - /// - /// [`Click`]: struct.Click.html - pub fn new(position: Point, previous: Option) -> Click { - let time = Instant::now(); - - let kind = if let Some(previous) = previous { - if previous.is_consecutive(position, time) { - previous.kind.next() - } else { - Kind::Single - } - } else { - Kind::Single - }; - - Click { - kind, - position, - time, - } - } - - /// Returns the [`Kind`] of [`Click`]. - /// - /// [`Kind`]: enum.Kind.html - /// [`Click`]: struct.Click.html - pub fn kind(&self) -> Kind { - self.kind - } - - fn is_consecutive(&self, new_position: Point, time: Instant) -> bool { - self.position == new_position - && time - .checked_duration_since(self.time) - .map(|duration| duration.as_millis() <= 300) - .unwrap_or(false) - } -} diff --git a/native/src/keyboard.rs b/native/src/keyboard.rs new file mode 100644 index 00000000..012538e3 --- /dev/null +++ b/native/src/keyboard.rs @@ -0,0 +1,2 @@ +//! Track keyboard events. +pub use iced_core::keyboard::*; diff --git a/native/src/lib.rs b/native/src/lib.rs index a3b581b3..88bf4423 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -39,8 +39,9 @@ #![deny(unused_results)] #![forbid(unsafe_code)] #![forbid(rust_2018_idioms)] -pub mod input; +pub mod keyboard; pub mod layout; +pub mod mouse; pub mod renderer; pub mod subscription; pub mod widget; diff --git a/native/src/mouse.rs b/native/src/mouse.rs new file mode 100644 index 00000000..9ee406cf --- /dev/null +++ b/native/src/mouse.rs @@ -0,0 +1,6 @@ +//! Track mouse events. + +pub mod click; + +pub use click::Click; +pub use iced_core::mouse::*; diff --git a/native/src/mouse/click.rs b/native/src/mouse/click.rs new file mode 100644 index 00000000..d27bc67e --- /dev/null +++ b/native/src/mouse/click.rs @@ -0,0 +1,76 @@ +//! Track mouse clicks. +use crate::Point; +use std::time::Instant; + +/// A mouse click. +#[derive(Debug, Clone, Copy)] +pub struct Click { + kind: Kind, + position: Point, + time: Instant, +} + +/// The kind of mouse click. +#[derive(Debug, Clone, Copy)] +pub enum Kind { + /// A single click + Single, + + /// A double click + Double, + + /// A triple click + Triple, +} + +impl Kind { + fn next(&self) -> Kind { + match self { + Kind::Single => Kind::Double, + Kind::Double => Kind::Triple, + Kind::Triple => Kind::Double, + } + } +} + +impl Click { + /// Creates a new [`Click`] with the given position and previous last + /// [`Click`]. + /// + /// [`Click`]: struct.Click.html + pub fn new(position: Point, previous: Option) -> Click { + let time = Instant::now(); + + let kind = if let Some(previous) = previous { + if previous.is_consecutive(position, time) { + previous.kind.next() + } else { + Kind::Single + } + } else { + Kind::Single + }; + + Click { + kind, + position, + time, + } + } + + /// Returns the [`Kind`] of [`Click`]. + /// + /// [`Kind`]: enum.Kind.html + /// [`Click`]: struct.Click.html + pub fn kind(&self) -> Kind { + self.kind + } + + fn is_consecutive(&self, new_position: Point, time: Instant) -> bool { + self.position == new_position + && time + .checked_duration_since(self.time) + .map(|duration| duration.as_millis() <= 300) + .unwrap_or(false) + } +} diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs index 5d9221e9..48cd6111 100644 --- a/native/src/user_interface.rs +++ b/native/src/user_interface.rs @@ -1,6 +1,4 @@ -use crate::{ - input::mouse, layout, Clipboard, Element, Event, Layout, Point, Size, -}; +use crate::{layout, mouse, Clipboard, Element, Event, Layout, Point, Size}; use std::hash::Hasher; diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index 5d414023..c932da2b 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -5,8 +5,8 @@ //! [`Button`]: struct.Button.html //! [`State`]: struct.State.html use crate::{ - input::mouse, layout, Clipboard, Element, Event, Hasher, Layout, Length, - Point, Rectangle, Widget, + layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length, Point, + Rectangle, Widget, }; use std::hash::Hash; diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index c49ac707..5fb13290 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, layout, row, text, Align, Clipboard, Element, Event, Hasher, + layout, mouse, row, text, Align, Clipboard, Element, Event, Hasher, HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget, }; diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index fe2bbe07..c398a30b 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -22,9 +22,8 @@ pub use split::Split; pub use state::{Focus, State}; use crate::{ - input::{keyboard, mouse}, - layout, Clipboard, Element, Event, Hasher, Layout, Length, Point, Size, - Widget, + keyboard, layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length, + Point, Size, Widget, }; /// A collection of panes distributed using either vertical or horizontal splits diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 0a8b8419..ed2813b8 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -1,5 +1,5 @@ use crate::{ - input::keyboard, + keyboard, pane_grid::{node::Node, Axis, Direction, Pane, Split}, Hasher, Point, Rectangle, Size, }; diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index deea7034..ab5bcf32 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, layout, row, text, Align, Clipboard, Element, Event, Hasher, + layout, mouse, row, text, Align, Clipboard, Element, Event, Hasher, HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget, }; diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index da11c50c..3c8e5e5b 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, layout, Align, Clipboard, Column, Element, Event, - Hasher, Layout, Length, Point, Rectangle, Size, Widget, + column, layout, mouse, Align, Clipboard, Column, Element, Event, Hasher, + Layout, Length, Point, Rectangle, Size, Widget, }; use std::{f32, hash::Hash, u32}; diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index a00d7c8d..8cdfc3de 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -5,8 +5,8 @@ //! [`Slider`]: struct.Slider.html //! [`State`]: struct.State.html use crate::{ - input::mouse, layout, Clipboard, Element, Event, Hasher, Layout, Length, - Point, Rectangle, Size, Widget, + layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length, Point, + Rectangle, Size, Widget, }; use std::{hash::Hash, ops::RangeInclusive}; diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index b11269db..1cdbe007 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -15,12 +15,10 @@ pub use value::Value; use editor::Editor; use crate::{ - input::{ - keyboard, - mouse::{self, click}, - }, - layout, Clipboard, Element, Event, Font, Hasher, Layout, Length, Point, - Rectangle, Size, Widget, + keyboard, layout, + mouse::{self, click}, + Clipboard, Element, Event, Font, Hasher, Layout, Length, Point, Rectangle, + Size, Widget, }; use std::u32; @@ -739,7 +737,7 @@ fn find_cursor_position( } mod platform { - use crate::input::keyboard; + use crate::keyboard; pub fn is_jump_modifier_pressed( modifiers: keyboard::ModifiersState, -- cgit