fix: use floats for pointer events (#4708)
* fix: use f64 for PointerInteraction * make clippy happy on beta --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
12fab0f9f7
commit
f48aec7eff
11 files changed
+51
-91
No files matched your search
@@ -1,4 +1,3 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use dioxus::prelude::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
@@ -71,36 +70,3 @@ impl Display for Sort {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct User {
|
||||
id: usize,
|
||||
email: String,
|
||||
username: String,
|
||||
password: String,
|
||||
name: FullName,
|
||||
phone: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct FullName {
|
||||
firstname: String,
|
||||
lastname: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
struct Cart {
|
||||
id: usize,
|
||||
#[serde(rename = "userId")]
|
||||
user_id: usize,
|
||||
data: String,
|
||||
products: Vec<ProductInCart>,
|
||||
date: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
struct ProductInCart {
|
||||
#[serde(rename = "productId")]
|
||||
product_id: usize,
|
||||
quantity: usize,
|
||||
}
|
||||
@@ -8,6 +8,7 @@ license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/dioxuslabs/dioxus"
|
||||
homepage = "https://dioxuslabs.com/learn/0.5/getting_started"
|
||||
keywords = ["const", "serialize"]
|
||||
rust-version = "1.80.0"
|
||||
|
||||
[dependencies]
|
||||
const-serialize-macro = { workspace = true }
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -7,7 +7,7 @@ description = "A box backed by a generational runtime"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/DioxusLabs/dioxus/"
|
||||
keywords = ["generational", "box", "memory", "allocator"]
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
rust-version = "1.80.0"
|
||||
|
||||
[dependencies]
|
||||
parking_lot = { workspace = true }
|
||||
|
||||
@@ -22,19 +22,15 @@ type RwLockStorageEntryMut = RwLockWriteGuard<'static, StorageEntry<RwLockStorag
|
||||
type AnyRef = MappedRwLockReadGuard<'static, Box<dyn Any + Send + Sync + 'static>>;
|
||||
type AnyRefMut = MappedRwLockWriteGuard<'static, Box<dyn Any + Send + Sync + 'static>>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) enum RwLockStorageEntryData {
|
||||
Reference(GenerationalPointer<SyncStorage>),
|
||||
Rc(RcStorageEntry<Box<dyn Any + Send + Sync>>),
|
||||
Data(Box<dyn Any + Send + Sync>),
|
||||
#[default]
|
||||
Empty,
|
||||
}
|
||||
|
||||
impl Default for RwLockStorageEntryData {
|
||||
fn default() -> Self {
|
||||
Self::Empty
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for RwLockStorageEntryData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
||||
@@ -21,10 +21,12 @@ thread_local! {
|
||||
static UNSYNC_RUNTIME: RefCell<Vec<&'static UnsyncStorage>> = const { RefCell::new(Vec::new()) };
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) enum RefCellStorageEntryData {
|
||||
Reference(GenerationalPointer<UnsyncStorage>),
|
||||
Rc(RcStorageEntry<Box<dyn Any>>),
|
||||
Data(Box<dyn Any>),
|
||||
#[default]
|
||||
Empty,
|
||||
}
|
||||
|
||||
@@ -39,12 +41,6 @@ impl Debug for RefCellStorageEntryData {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RefCellStorageEntryData {
|
||||
fn default() -> Self {
|
||||
Self::Empty
|
||||
}
|
||||
}
|
||||
|
||||
/// A unsync storage. This is the default storage type.
|
||||
#[derive(Default)]
|
||||
pub struct UnsyncStorage {
|
||||
|
||||
@@ -75,10 +75,10 @@ pub trait HasPointerData: PointerInteraction {
|
||||
fn pointer_id(&self) -> i32;
|
||||
|
||||
/// Gets the width (magnitude on the X axis), in CSS pixels, of the contact geometry of the pointer.
|
||||
fn width(&self) -> i32;
|
||||
fn width(&self) -> f64;
|
||||
|
||||
/// Gets the height (magnitude on the Y axis), in CSS pixels, of the contact geometry of the pointer.
|
||||
fn height(&self) -> i32;
|
||||
fn height(&self) -> f64;
|
||||
|
||||
/// Gets the normalized pressure of the pointer input in the range of 0 to 1,
|
||||
fn pressure(&self) -> f32;
|
||||
@@ -145,12 +145,12 @@ impl PointerData {
|
||||
}
|
||||
|
||||
/// Gets the width (magnitude on the X axis), in CSS pixels, of the contact geometry of the pointer.
|
||||
pub fn width(&self) -> i32 {
|
||||
pub fn width(&self) -> f64 {
|
||||
self.inner.width()
|
||||
}
|
||||
|
||||
/// Gets the height (magnitude on the Y axis), in CSS pixels, of the contact geometry of the pointer.
|
||||
pub fn height(&self) -> i32 {
|
||||
pub fn height(&self) -> f64 {
|
||||
self.inner.height()
|
||||
}
|
||||
|
||||
@@ -238,10 +238,10 @@ pub struct SerializedPointerData {
|
||||
pointer_id: i32,
|
||||
|
||||
/// The width (magnitude on the X axis), in CSS pixels, of the contact geometry of the pointer.
|
||||
width: i32,
|
||||
width: f64,
|
||||
|
||||
/// The height (magnitude on the Y axis), in CSS pixels, of the contact geometry of the pointer.
|
||||
height: i32,
|
||||
height: f64,
|
||||
|
||||
/// The normalized pressure of the pointer input in the range of 0 to 1,
|
||||
pressure: f32,
|
||||
@@ -271,11 +271,11 @@ impl HasPointerData for SerializedPointerData {
|
||||
self.pointer_id
|
||||
}
|
||||
|
||||
fn width(&self) -> i32 {
|
||||
fn width(&self) -> f64 {
|
||||
self.width
|
||||
}
|
||||
|
||||
fn height(&self) -> i32 {
|
||||
fn height(&self) -> f64 {
|
||||
self.height
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ impl ScrollData {
|
||||
self.inner.as_any().downcast_ref::<T>()
|
||||
}
|
||||
|
||||
pub fn scroll_top(&self) -> i32 {
|
||||
pub fn scroll_top(&self) -> f64 {
|
||||
self.inner.scroll_top()
|
||||
}
|
||||
|
||||
pub fn scroll_left(&self) -> i32 {
|
||||
pub fn scroll_left(&self) -> f64 {
|
||||
self.inner.scroll_left()
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ impl PartialEq for ScrollData {
|
||||
/// A serialized version of ScrollData
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct SerializedScrollData {
|
||||
pub scroll_top: i32,
|
||||
pub scroll_left: i32,
|
||||
pub scroll_top: f64,
|
||||
pub scroll_left: f64,
|
||||
pub scroll_width: i32,
|
||||
pub scroll_height: i32,
|
||||
pub client_width: i32,
|
||||
@@ -107,11 +107,11 @@ impl HasScrollData for SerializedScrollData {
|
||||
self
|
||||
}
|
||||
|
||||
fn scroll_top(&self) -> i32 {
|
||||
fn scroll_top(&self) -> f64 {
|
||||
self.scroll_top
|
||||
}
|
||||
|
||||
fn scroll_left(&self) -> i32 {
|
||||
fn scroll_left(&self) -> f64 {
|
||||
self.scroll_left
|
||||
}
|
||||
|
||||
@@ -154,10 +154,10 @@ pub trait HasScrollData: std::any::Any {
|
||||
fn as_any(&self) -> &dyn std::any::Any;
|
||||
|
||||
/// Get the vertical scroll position
|
||||
fn scroll_top(&self) -> i32;
|
||||
fn scroll_top(&self) -> f64;
|
||||
|
||||
/// Get the horizontal scroll position
|
||||
fn scroll_left(&self) -> i32;
|
||||
fn scroll_left(&self) -> f64;
|
||||
|
||||
/// Get the total scrollable width
|
||||
fn scroll_width(&self) -> i32;
|
||||
|
||||
@@ -70,12 +70,12 @@ pub struct SerializedPointInteraction {
|
||||
/// The horizontal coordinate within the application's viewport at which the event occurred (as opposed to the coordinate within the page).
|
||||
///
|
||||
/// For example, clicking on the left edge of the viewport will always result in a mouse event with a clientX value of 0, regardless of whether the page is scrolled horizontally.
|
||||
pub client_x: i32,
|
||||
pub client_x: f64,
|
||||
|
||||
/// The vertical coordinate within the application's viewport at which the event occurred (as opposed to the coordinate within the page).
|
||||
///
|
||||
/// For example, clicking on the top edge of the viewport will always result in a mouse event with a clientY value of 0, regardless of whether the page is scrolled vertically.
|
||||
pub client_y: i32,
|
||||
pub client_y: f64,
|
||||
|
||||
/// True if the control key was down when the mouse event was fired.
|
||||
pub ctrl_key: bool,
|
||||
@@ -84,26 +84,26 @@ pub struct SerializedPointInteraction {
|
||||
pub meta_key: bool,
|
||||
|
||||
/// The offset in the X coordinate of the mouse pointer between that event and the padding edge of the target node.
|
||||
pub offset_x: i32,
|
||||
pub offset_x: f64,
|
||||
|
||||
/// The offset in the Y coordinate of the mouse pointer between that event and the padding edge of the target node.
|
||||
pub offset_y: i32,
|
||||
pub offset_y: f64,
|
||||
|
||||
/// The X (horizontal) coordinate (in pixels) of the mouse, relative to the left edge of the entire document. This includes any portion of the document not currently visible.
|
||||
///
|
||||
/// Being based on the edge of the document as it is, this property takes into account any horizontal scrolling of the page. For example, if the page is scrolled such that 200 pixels of the left side of the document are scrolled out of view, and the mouse is clicked 100 pixels inward from the left edge of the view, the value returned by pageX will be 300.
|
||||
pub page_x: i32,
|
||||
pub page_x: f64,
|
||||
|
||||
/// The Y (vertical) coordinate in pixels of the event relative to the whole document.
|
||||
///
|
||||
/// See `page_x`.
|
||||
pub page_y: i32,
|
||||
pub page_y: f64,
|
||||
|
||||
/// The X coordinate of the mouse pointer in global (screen) coordinates.
|
||||
pub screen_x: i32,
|
||||
pub screen_x: f64,
|
||||
|
||||
/// The Y coordinate of the mouse pointer in global (screen) coordinates.
|
||||
pub screen_y: i32,
|
||||
pub screen_y: f64,
|
||||
|
||||
/// True if the shift key was down when the mouse event was fired.
|
||||
pub shift_key: bool,
|
||||
@@ -122,10 +122,10 @@ impl SerializedPointInteraction {
|
||||
let meta_key = modifiers.contains(Modifiers::META);
|
||||
let shift_key = modifiers.contains(Modifiers::SHIFT);
|
||||
|
||||
let [client_x, client_y]: [i32; 2] = coordinates.client().cast().into();
|
||||
let [offset_x, offset_y]: [i32; 2] = coordinates.element().cast().into();
|
||||
let [page_x, page_y]: [i32; 2] = coordinates.page().cast().into();
|
||||
let [screen_x, screen_y]: [i32; 2] = coordinates.screen().cast().into();
|
||||
let [client_x, client_y]: [f64; 2] = coordinates.client().cast().into();
|
||||
let [offset_x, offset_y]: [f64; 2] = coordinates.element().cast().into();
|
||||
let [page_x, page_y]: [f64; 2] = coordinates.page().cast().into();
|
||||
let [screen_x, screen_y]: [f64; 2] = coordinates.screen().cast().into();
|
||||
Self {
|
||||
button: trigger_button
|
||||
.map_or(MouseButton::default(), |b| b)
|
||||
@@ -194,21 +194,21 @@ impl ModifiersInteraction for SerializedPointInteraction {
|
||||
#[cfg(feature = "serialize")]
|
||||
impl InteractionLocation for SerializedPointInteraction {
|
||||
fn client_coordinates(&self) -> ClientPoint {
|
||||
ClientPoint::new(self.client_x.into(), self.client_y.into())
|
||||
ClientPoint::new(self.client_x, self.client_y)
|
||||
}
|
||||
|
||||
fn screen_coordinates(&self) -> ScreenPoint {
|
||||
ScreenPoint::new(self.screen_x.into(), self.screen_y.into())
|
||||
ScreenPoint::new(self.screen_x, self.screen_y)
|
||||
}
|
||||
|
||||
fn page_coordinates(&self) -> PagePoint {
|
||||
PagePoint::new(self.page_x.into(), self.page_y.into())
|
||||
PagePoint::new(self.page_x, self.page_y)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl InteractionElementOffset for SerializedPointInteraction {
|
||||
fn element_coordinates(&self) -> ElementPoint {
|
||||
ElementPoint::new(self.offset_x.into(), self.offset_y.into())
|
||||
ElementPoint::new(self.offset_x, self.offset_y)
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,12 @@ impl HasPointerData for Synthetic<PointerEvent> {
|
||||
self.event.pointer_id()
|
||||
}
|
||||
|
||||
fn width(&self) -> i32 {
|
||||
self.event.width()
|
||||
fn width(&self) -> f64 {
|
||||
self.event.width() as _
|
||||
}
|
||||
|
||||
fn height(&self) -> i32 {
|
||||
self.event.height()
|
||||
fn height(&self) -> f64 {
|
||||
self.event.height() as _
|
||||
}
|
||||
|
||||
fn pressure(&self) -> f32 {
|
||||
|
||||
@@ -9,32 +9,32 @@ impl HasScrollData for Synthetic<Event> {
|
||||
&self.event
|
||||
}
|
||||
|
||||
fn scroll_top(&self) -> i32 {
|
||||
fn scroll_top(&self) -> f64 {
|
||||
if let Some(target) = self.event.target().as_ref() {
|
||||
if let Some(element) = target.dyn_ref::<Element>() {
|
||||
return element.scroll_top();
|
||||
return element.scroll_top() as f64;
|
||||
} else if let Some(element) = target
|
||||
.dyn_ref::<Document>()
|
||||
.and_then(|document| document.document_element())
|
||||
{
|
||||
return element.scroll_top();
|
||||
return element.scroll_top() as f64;
|
||||
}
|
||||
}
|
||||
0
|
||||
0f64
|
||||
}
|
||||
|
||||
fn scroll_left(&self) -> i32 {
|
||||
fn scroll_left(&self) -> f64 {
|
||||
if let Some(target) = self.event.target().as_ref() {
|
||||
if let Some(element) = target.dyn_ref::<Element>() {
|
||||
return element.scroll_left();
|
||||
return element.scroll_left() as f64;
|
||||
} else if let Some(element) = target
|
||||
.dyn_ref::<Document>()
|
||||
.and_then(|document| document.document_element())
|
||||
{
|
||||
return element.scroll_left();
|
||||
return element.scroll_left() as f64;
|
||||
}
|
||||
}
|
||||
0
|
||||
0f64
|
||||
}
|
||||
|
||||
fn scroll_width(&self) -> i32 {
|
||||
|
||||
Reference in new issue
Block a user