From 56095116e263b7e7377e169ee5b8a1118ece2073 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Wed, 23 Aug 2023 17:58:43 -0400 Subject: [PATCH] Fix tests --- packages/desktop/headless_tests/events.rs | 1 + packages/dioxus-tui/examples/colorpicker.rs | 11 ++-- packages/dioxus-tui/examples/hover.rs | 34 +++++------- packages/dioxus-tui/tests/events.rs | 59 +++++++-------------- packages/html/src/lib.rs | 1 + packages/rink/src/hooks.rs | 4 +- packages/rink/src/widgets/slider.rs | 4 +- 7 files changed, 43 insertions(+), 71 deletions(-) diff --git a/packages/desktop/headless_tests/events.rs b/packages/desktop/headless_tests/events.rs index ac62cd37b..d4439aec6 100644 --- a/packages/desktop/headless_tests/events.rs +++ b/packages/desktop/headless_tests/events.rs @@ -1,6 +1,7 @@ use dioxus::html::geometry::euclid::Vector3D; use dioxus::prelude::*; use dioxus_desktop::DesktopContext; +use dioxus_html::PointInteraction; pub(crate) fn check_app_exits(app: Component) { use dioxus_desktop::tao::window::WindowBuilder; diff --git a/packages/dioxus-tui/examples/colorpicker.rs b/packages/dioxus-tui/examples/colorpicker.rs index 00f8ef7e0..7a358da3e 100644 --- a/packages/dioxus-tui/examples/colorpicker.rs +++ b/packages/dioxus-tui/examples/colorpicker.rs @@ -1,5 +1,6 @@ use dioxus::core::RenderReturn; use dioxus::prelude::*; +use dioxus_html::PointInteraction; use dioxus_tui::DioxusElementToNodeId; use dioxus_tui::Query; use dioxus_tui::Size; @@ -15,21 +16,21 @@ fn app(cx: Scope) -> Element { let mapping: DioxusElementToNodeId = cx.consume_context().unwrap(); // disable templates so that every node has an id and can be queried cx.render(rsx! { - div{ + div { width: "100%", background_color: "hsl({hue}, 70%, {brightness}%)", onmousemove: move |evt| { if let RenderReturn::Ready(node) = cx.root_node() { if let Some(id) = node.root_ids.borrow().get(0).cloned() { let node = tui_query.get(mapping.get_node_id(id).unwrap()); - let Size{width, height} = node.size().unwrap(); + let Size { width, height } = node.size().unwrap(); let pos = evt.inner().element_coordinates(); - hue.set((pos.x as f32/width as f32)*255.0); - brightness.set((pos.y as f32/height as f32)*100.0); + hue.set((pos.x as f32 / width as f32) * 255.0); + brightness.set((pos.y as f32 / height as f32) * 100.0); } } }, - "hsl({hue}, 70%, {brightness}%)", + "hsl({hue}, 70%, {brightness}%)" } }) } diff --git a/packages/dioxus-tui/examples/hover.rs b/packages/dioxus-tui/examples/hover.rs index 3af2d1616..3c29521e5 100644 --- a/packages/dioxus-tui/examples/hover.rs +++ b/packages/dioxus-tui/examples/hover.rs @@ -1,5 +1,6 @@ use dioxus::{events::MouseData, prelude::*}; use dioxus_core::Event; +use dioxus_html::PointInteraction; use std::convert::TryInto; use std::fmt::Write; use std::rc::Rc; @@ -52,15 +53,9 @@ fn app(cx: Scope) -> Element { }; cx.render(rsx! { - div { - width: "100%", - height: "100%", - flex_direction: "column", + div { width: "100%", height: "100%", flex_direction: "column", - div { - width: "100%", - height: "50%", - flex_direction: "row", + div { width: "100%", height: "50%", flex_direction: "row", div { border_width: "1px", width: "50%", @@ -71,7 +66,7 @@ fn app(cx: Scope) -> Element { onmouseenter: move |m| q1_color.set([get_brightness(m.inner()), 0, 0]), onmousedown: move |m| q1_color.set([get_brightness(m.inner()), 0, 0]), onmouseup: move |m| q1_color.set([get_brightness(m.inner()), 0, 0]), - onwheel: move |w| q1_color.set([q1_color[0] + (10.0*w.delta().strip_units().y) as i32, 0, 0]), + onwheel: move |w| q1_color.set([q1_color[0] + (10.0 * w.delta().strip_units().y) as i32, 0, 0]), onmouseleave: move |_| q1_color.set([200; 3]), onmousemove: update_data, "click me" @@ -85,17 +80,14 @@ fn app(cx: Scope) -> Element { onmouseenter: move |m| q2_color.set([get_brightness(m.inner()); 3]), onmousedown: move |m| q2_color.set([get_brightness(m.inner()); 3]), onmouseup: move |m| q2_color.set([get_brightness(m.inner()); 3]), - onwheel: move |w| q2_color.set([q2_color[0] + (10.0*w.delta().strip_units().y) as i32;3]), + onwheel: move |w| q2_color.set([q2_color[0] + (10.0 * w.delta().strip_units().y) as i32; 3]), onmouseleave: move |_| q2_color.set([200; 3]), onmousemove: update_data, "click me" } } - div { - width: "100%", - height: "50%", - flex_direction: "row", + div { width: "100%", height: "50%", flex_direction: "row", div { width: "50%", height: "100%", @@ -105,7 +97,7 @@ fn app(cx: Scope) -> Element { onmouseenter: move |m| q3_color.set([0, get_brightness(m.inner()), 0]), onmousedown: move |m| q3_color.set([0, get_brightness(m.inner()), 0]), onmouseup: move |m| q3_color.set([0, get_brightness(m.inner()), 0]), - onwheel: move |w| q3_color.set([0, q3_color[1] + (10.0*w.delta().strip_units().y) as i32, 0]), + onwheel: move |w| q3_color.set([0, q3_color[1] + (10.0 * w.delta().strip_units().y) as i32, 0]), onmouseleave: move |_| q3_color.set([200; 3]), onmousemove: update_data, "click me" @@ -119,16 +111,16 @@ fn app(cx: Scope) -> Element { onmouseenter: move |m| q4_color.set([0, 0, get_brightness(m.inner())]), onmousedown: move |m| q4_color.set([0, 0, get_brightness(m.inner())]), onmouseup: move |m| q4_color.set([0, 0, get_brightness(m.inner())]), - onwheel: move |w| q4_color.set([0, 0, q4_color[2] + (10.0*w.delta().strip_units().y) as i32]), + onwheel: move |w| q4_color.set([0, 0, q4_color[2] + (10.0 * w.delta().strip_units().y) as i32]), onmouseleave: move |_| q4_color.set([200; 3]), onmousemove: update_data, "click me" } - }, - div {"Page coordinates: {page_coordinates}"}, - div {"Element coordinates: {element_coordinates}"}, - div {"Buttons: {buttons}"}, - div {"Modifiers: {modifiers}"}, + } + div { "Page coordinates: {page_coordinates}" } + div { "Element coordinates: {element_coordinates}" } + div { "Buttons: {buttons}" } + div { "Modifiers: {modifiers}" } } }) } diff --git a/packages/dioxus-tui/tests/events.rs b/packages/dioxus-tui/tests/events.rs index 671cfc349..01fea9934 100644 --- a/packages/dioxus-tui/tests/events.rs +++ b/packages/dioxus-tui/tests/events.rs @@ -1,6 +1,7 @@ use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent}; use dioxus::prelude::*; use dioxus_html::input_data::keyboard_types::Code; +use dioxus_html::PointInteraction; use dioxus_tui::TuiContext; use std::future::Future; use std::pin::Pin; @@ -63,7 +64,7 @@ fn key_down() { onkeydown: move |evt| { assert_eq!(evt.data.code(), Code::KeyA); tui_ctx.quit(); - }, + } } }) } @@ -95,9 +96,11 @@ fn mouse_down() { width: "100%", height: "100%", onmousedown: move |evt| { - assert!(evt.data.held_buttons().contains(dioxus_html::input_data::MouseButton::Primary)); + assert!( + evt.data.held_buttons().contains(dioxus_html::input_data::MouseButton::Primary) + ); tui_ctx.quit(); - }, + } } }) } @@ -131,13 +134,9 @@ fn mouse_up() { modifiers: KeyModifiers::NONE, })); cx.render(rsx! { - div { - width: "100%", - height: "100%", - onmouseup: move |_| { + div { width: "100%", height: "100%", onmouseup: move |_| { tui_ctx.quit(); - }, - } + } } }) } } @@ -170,13 +169,9 @@ fn mouse_enter() { modifiers: KeyModifiers::NONE, })); cx.render(rsx! { - div { - width: "50%", - height: "50%", - onmouseenter: move |_| { + div { width: "50%", height: "50%", onmouseenter: move |_| { tui_ctx.quit(); - }, - } + } } }) } } @@ -209,13 +204,9 @@ fn mouse_exit() { modifiers: KeyModifiers::NONE, })); cx.render(rsx! { - div { - width: "50%", - height: "50%", - onmouseenter: move |_| { + div { width: "50%", height: "50%", onmouseenter: move |_| { tui_ctx.quit(); - }, - } + } } }) } } @@ -248,13 +239,9 @@ fn mouse_move() { modifiers: KeyModifiers::NONE, })); cx.render(rsx! { - div { - width: "100%", - height: "100%", - onmousemove: move |_|{ + div { width: "100%", height: "100%", onmousemove: move |_| { tui_ctx.quit(); - }, - } + } } }) } } @@ -293,7 +280,7 @@ fn wheel() { onwheel: move |evt| { assert!(evt.data.delta().strip_units().y > 0.0); tui_ctx.quit(); - }, + } } }) } @@ -327,13 +314,9 @@ fn click() { modifiers: KeyModifiers::NONE, })); cx.render(rsx! { - div { - width: "100%", - height: "100%", - onclick: move |_|{ + div { width: "100%", height: "100%", onclick: move |_| { tui_ctx.quit(); - }, - } + } } }) } } @@ -366,13 +349,9 @@ fn context_menu() { modifiers: KeyModifiers::NONE, })); cx.render(rsx! { - div { - width: "100%", - height: "100%", - oncontextmenu: move |_|{ + div { width: "100%", height: "100%", oncontextmenu: move |_| { tui_ctx.quit(); - }, - } + } } }) } } diff --git a/packages/html/src/lib.rs b/packages/html/src/lib.rs index 5866ed28a..973d6e750 100644 --- a/packages/html/src/lib.rs +++ b/packages/html/src/lib.rs @@ -36,6 +36,7 @@ pub use transit::*; pub use elements::*; pub use events::*; pub use global_attributes::*; +pub use point_interaction::PointInteraction; pub use render_template::*; mod eval; diff --git a/packages/rink/src/hooks.rs b/packages/rink/src/hooks.rs index a8c611c50..106e0dc41 100644 --- a/packages/rink/src/hooks.rs +++ b/packages/rink/src/hooks.rs @@ -14,8 +14,8 @@ use dioxus_html::input_data::keyboard_types::{Code, Key, Location, Modifiers}; use dioxus_html::input_data::{ MouseButton as DioxusMouseButton, MouseButtonSet as DioxusMouseButtons, }; -use dioxus_html::point_interaction::{PointData, PointInteraction}; -use dioxus_html::{event_bubbles, FocusData, KeyboardData, MouseData, WheelData}; +use dioxus_html::point_interaction::PointData; +use dioxus_html::{event_bubbles, FocusData, KeyboardData, MouseData, PointInteraction, WheelData}; use std::any::Any; use std::collections::HashMap; use std::{ diff --git a/packages/rink/src/widgets/slider.rs b/packages/rink/src/widgets/slider.rs index 5b24e180d..4a78f2a79 100644 --- a/packages/rink/src/widgets/slider.rs +++ b/packages/rink/src/widgets/slider.rs @@ -1,8 +1,6 @@ use std::collections::HashMap; -use dioxus_html::{ - input_data::keyboard_types::Key, point_interaction::PointInteraction, KeyboardData, MouseData, -}; +use dioxus_html::{input_data::keyboard_types::Key, KeyboardData, MouseData, PointInteraction}; use dioxus_native_core::{ custom_element::CustomElement, node::{OwnedAttributeDiscription, OwnedAttributeValue},