summaryrefslogtreecommitdiffstats
path: root/winit/src/conversion.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-22 22:14:39 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-22 22:14:48 +0100
commit580891dda76f7e9174913eb75e3bee4261866d71 (patch)
tree55226317e51fdb951b29c6ba7a056f9368ea939f /winit/src/conversion.rs
parent6a0e442ad68c2b104b7e91ef80798610a79aca6b (diff)
downloadiced-580891dda76f7e9174913eb75e3bee4261866d71.tar.gz
iced-580891dda76f7e9174913eb75e3bee4261866d71.tar.bz2
iced-580891dda76f7e9174913eb75e3bee4261866d71.zip
Write docs for `iced_winit`
Diffstat (limited to '')
-rw-r--r--winit/src/conversion.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs
index e73fa008..03d583fb 100644
--- a/winit/src/conversion.rs
+++ b/winit/src/conversion.rs
@@ -1,6 +1,16 @@
-use crate::input::{keyboard::KeyCode, mouse, ButtonState};
-use crate::MouseCursor;
+//! Convert [`winit`] types to [`iced_native`] types, and viceversa.
+//!
+//! [`winit`]: https://github.com/rust-windowing/winit
+//! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
+use crate::{
+ input::{keyboard::KeyCode, mouse, ButtonState},
+ MouseCursor,
+};
+/// Convert a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
+///
+/// [`winit`]: https://github.com/rust-windowing/winit
+/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
pub fn mouse_cursor(mouse_cursor: MouseCursor) -> winit::window::CursorIcon {
match mouse_cursor {
MouseCursor::OutOfBounds => winit::window::CursorIcon::Default,
@@ -13,6 +23,10 @@ pub fn mouse_cursor(mouse_cursor: MouseCursor) -> winit::window::CursorIcon {
}
}
+/// Convert a `MouseButton` from [`winit`] to an [`iced_native`] mouse button.
+///
+/// [`winit`]: https://github.com/rust-windowing/winit
+/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
match mouse_button {
winit::event::MouseButton::Left => mouse::Button::Left,
@@ -22,6 +36,10 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
}
}
+/// Convert an `ElementState` from [`winit`] to an [`iced_native`] button state.
+///
+/// [`winit`]: https://github.com/rust-windowing/winit
+/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
pub fn button_state(element_state: winit::event::ElementState) -> ButtonState {
match element_state {
winit::event::ElementState::Pressed => ButtonState::Pressed,
@@ -29,6 +47,10 @@ pub fn button_state(element_state: winit::event::ElementState) -> ButtonState {
}
}
+/// Convert a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code.
+///
+/// [`winit`]: https://github.com/rust-windowing/winit
+/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
pub fn key_code(virtual_keycode: winit::event::VirtualKeyCode) -> KeyCode {
match virtual_keycode {
winit::event::VirtualKeyCode::Key1 => KeyCode::Key1,