chore(rustfmt): use nightly (#2325)
Stable rustfmt lacks a lot of features resulting in worse formatted code, thus use nightly formatter.
This commit is contained in:
parent
7006c7ceca
commit
7b0c7b6cb2
154 changed files with 3439 additions and 5891 deletions
|
|
@ -11,8 +11,9 @@ use std::time::Duration;
|
|||
|
||||
use cursor_icon::CursorIcon;
|
||||
use js_sys::{Array, Object};
|
||||
use wasm_bindgen::closure::Closure;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::{closure::Closure, JsCast};
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::{
|
||||
Blob, Document, DomException, HtmlCanvasElement, HtmlImageElement, ImageBitmap,
|
||||
|
|
@ -29,15 +30,8 @@ use crate::platform::web::CustomCursorError;
|
|||
#[derive(Debug)]
|
||||
pub(crate) enum CustomCursorSource {
|
||||
Image(CursorImage),
|
||||
Url {
|
||||
url: String,
|
||||
hotspot_x: u16,
|
||||
hotspot_y: u16,
|
||||
},
|
||||
Animation {
|
||||
duration: Duration,
|
||||
cursors: Vec<RootCustomCursor>,
|
||||
},
|
||||
Url { url: String, hotspot_x: u16, hotspot_y: u16 },
|
||||
Animation { duration: Duration, cursors: Vec<RootCustomCursor> },
|
||||
}
|
||||
|
||||
impl CustomCursorSource {
|
||||
|
|
@ -79,18 +73,10 @@ impl CustomCursor {
|
|||
match source {
|
||||
CustomCursorSource::Image(image) => Self::build_spawn(
|
||||
event_loop,
|
||||
from_rgba(
|
||||
event_loop.runner.window(),
|
||||
event_loop.runner.document().clone(),
|
||||
&image,
|
||||
),
|
||||
from_rgba(event_loop.runner.window(), event_loop.runner.document().clone(), &image),
|
||||
false,
|
||||
),
|
||||
CustomCursorSource::Url {
|
||||
url,
|
||||
hotspot_x,
|
||||
hotspot_y,
|
||||
} => Self::build_spawn(
|
||||
CustomCursorSource::Url { url, hotspot_x, hotspot_y } => Self::build_spawn(
|
||||
event_loop,
|
||||
from_url(UrlType::Plain(url), hotspot_x, hotspot_y),
|
||||
false,
|
||||
|
|
@ -130,9 +116,7 @@ impl CustomCursor {
|
|||
async move {
|
||||
let result = task.await;
|
||||
|
||||
let this = weak
|
||||
.upgrade()
|
||||
.expect("`CursorHandler` invalidated without aborting");
|
||||
let this = weak.upgrade().expect("`CursorHandler` invalidated without aborting");
|
||||
let mut this = this.get(main_thread).borrow_mut();
|
||||
|
||||
match result {
|
||||
|
|
@ -143,7 +127,7 @@ impl CustomCursor {
|
|||
unreachable!("found invalid state");
|
||||
};
|
||||
notifier.notify(Ok(()));
|
||||
}
|
||||
},
|
||||
Err(error) => {
|
||||
let ImageState::Loading { notifier, .. } =
|
||||
mem::replace(this.deref_mut(), ImageState::Failed(error.clone()))
|
||||
|
|
@ -151,7 +135,7 @@ impl CustomCursor {
|
|||
unreachable!("found invalid state");
|
||||
};
|
||||
notifier.notify(Err(error));
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -175,11 +159,7 @@ impl CustomCursor {
|
|||
let notified = notifier.notified();
|
||||
drop(binding);
|
||||
|
||||
CustomCursorFuture {
|
||||
notified,
|
||||
animation,
|
||||
state: Some(state),
|
||||
}
|
||||
CustomCursorFuture { notified, animation, state: Some(state) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -199,15 +179,9 @@ impl Future for CustomCursorFuture {
|
|||
}
|
||||
|
||||
let result = ready!(Pin::new(&mut self.notified).poll(cx));
|
||||
let state = self
|
||||
.state
|
||||
.take()
|
||||
.expect("`CustomCursorFuture` polled after completion");
|
||||
let state = self.state.take().expect("`CustomCursorFuture` polled after completion");
|
||||
|
||||
Poll::Ready(result.map(|_| CustomCursor {
|
||||
animation: self.animation,
|
||||
state,
|
||||
}))
|
||||
Poll::Ready(result.map(|_| CustomCursor { animation: self.animation, state }))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -244,10 +218,8 @@ impl CursorHandler {
|
|||
match cursor {
|
||||
Cursor::Icon(icon) => {
|
||||
if let SelectedCursor::Icon(old_icon)
|
||||
| SelectedCursor::Loading {
|
||||
previous: Previous::Icon(old_icon),
|
||||
..
|
||||
} = &this.cursor
|
||||
| SelectedCursor::Loading { previous: Previous::Icon(old_icon), .. } =
|
||||
&this.cursor
|
||||
{
|
||||
if *old_icon == icon {
|
||||
return;
|
||||
|
|
@ -256,17 +228,13 @@ impl CursorHandler {
|
|||
|
||||
this.cursor = SelectedCursor::Icon(icon);
|
||||
this.set_style();
|
||||
}
|
||||
},
|
||||
Cursor::Custom(cursor) => {
|
||||
let cursor = cursor.inner;
|
||||
|
||||
if let SelectedCursor::Loading {
|
||||
cursor: old_cursor, ..
|
||||
}
|
||||
if let SelectedCursor::Loading { cursor: old_cursor, .. }
|
||||
| SelectedCursor::Image(old_cursor)
|
||||
| SelectedCursor::Animation {
|
||||
cursor: old_cursor, ..
|
||||
} = &this.cursor
|
||||
| SelectedCursor::Animation { cursor: old_cursor, .. } = &this.cursor
|
||||
{
|
||||
if *old_cursor == cursor {
|
||||
return;
|
||||
|
|
@ -299,17 +267,17 @@ impl CursorHandler {
|
|||
previous: mem::take(&mut this.cursor).into(),
|
||||
_handle: handle,
|
||||
};
|
||||
}
|
||||
},
|
||||
ImageState::Failed(error) => {
|
||||
tracing::error!(
|
||||
"trying to load custom cursor that has failed to load: {error}"
|
||||
)
|
||||
}
|
||||
},
|
||||
ImageState::Image(_) => {
|
||||
drop(state);
|
||||
this.cursor = SelectedCursor::Image(cursor);
|
||||
this.set_style();
|
||||
}
|
||||
},
|
||||
ImageState::Animation(animation) => {
|
||||
let canvas: &CanvasAnimateExt = this.canvas.unchecked_ref();
|
||||
let animation = canvas.animate_with_keyframe_animation_options(
|
||||
|
|
@ -327,9 +295,9 @@ impl CursorHandler {
|
|||
cursor,
|
||||
};
|
||||
this.set_style();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -355,37 +323,29 @@ impl Inner {
|
|||
if self.visible {
|
||||
match &self.cursor {
|
||||
SelectedCursor::Icon(icon)
|
||||
| SelectedCursor::Loading {
|
||||
previous: Previous::Icon(icon),
|
||||
..
|
||||
} => self.style.set("cursor", icon.name()),
|
||||
SelectedCursor::Loading {
|
||||
previous: Previous::Image(cursor),
|
||||
..
|
||||
}
|
||||
| SelectedCursor::Loading { previous: Previous::Icon(icon), .. } => {
|
||||
self.style.set("cursor", icon.name())
|
||||
},
|
||||
SelectedCursor::Loading { previous: Previous::Image(cursor), .. }
|
||||
| SelectedCursor::Image(cursor) => {
|
||||
match cursor.state.get(self.main_thread).borrow().deref() {
|
||||
ImageState::Image(Image { style, .. }) => self.style.set("cursor", style),
|
||||
_ => unreachable!("found invalid saved state"),
|
||||
}
|
||||
}
|
||||
},
|
||||
SelectedCursor::Loading {
|
||||
previous: Previous::Animation { animation, .. },
|
||||
..
|
||||
previous: Previous::Animation { animation, .. }, ..
|
||||
}
|
||||
| SelectedCursor::Animation { animation, .. } => {
|
||||
self.style.remove("cursor");
|
||||
animation.0.play()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn notify(&mut self) {
|
||||
let SelectedCursor::Loading {
|
||||
cursor, previous, ..
|
||||
} = mem::take(&mut self.cursor)
|
||||
else {
|
||||
let SelectedCursor::Loading { cursor, previous, .. } = mem::take(&mut self.cursor) else {
|
||||
unreachable!("found wrong state")
|
||||
};
|
||||
|
||||
|
|
@ -395,7 +355,7 @@ impl Inner {
|
|||
drop(state);
|
||||
self.cursor = SelectedCursor::Image(cursor);
|
||||
self.set_style();
|
||||
}
|
||||
},
|
||||
ImageState::Animation(animation) => {
|
||||
let canvas: &CanvasAnimateExt = self.canvas.unchecked_ref();
|
||||
let animation = canvas.animate_with_keyframe_animation_options(
|
||||
|
|
@ -408,16 +368,14 @@ impl Inner {
|
|||
animation.cancel();
|
||||
}
|
||||
|
||||
self.cursor = SelectedCursor::Animation {
|
||||
animation: AnimationDropper(animation),
|
||||
cursor,
|
||||
};
|
||||
self.cursor =
|
||||
SelectedCursor::Animation { animation: AnimationDropper(animation), cursor };
|
||||
self.set_style();
|
||||
}
|
||||
},
|
||||
ImageState::Failed(error) => {
|
||||
tracing::error!("custom cursor failed to load: {error}");
|
||||
self.cursor = previous.into()
|
||||
}
|
||||
},
|
||||
ImageState::Loading { .. } => unreachable!("notified without being ready"),
|
||||
}
|
||||
}
|
||||
|
|
@ -426,16 +384,9 @@ impl Inner {
|
|||
#[derive(Debug)]
|
||||
enum SelectedCursor {
|
||||
Icon(CursorIcon),
|
||||
Loading {
|
||||
cursor: CustomCursor,
|
||||
previous: Previous,
|
||||
_handle: DropAbortHandle,
|
||||
},
|
||||
Loading { cursor: CustomCursor, previous: Previous, _handle: DropAbortHandle },
|
||||
Image(CustomCursor),
|
||||
Animation {
|
||||
cursor: CustomCursor,
|
||||
animation: AnimationDropper,
|
||||
},
|
||||
Animation { cursor: CustomCursor, animation: AnimationDropper },
|
||||
}
|
||||
|
||||
impl Default for SelectedCursor {
|
||||
|
|
@ -458,10 +409,7 @@ impl From<Previous> for SelectedCursor {
|
|||
enum Previous {
|
||||
Icon(CursorIcon),
|
||||
Image(CustomCursor),
|
||||
Animation {
|
||||
cursor: CustomCursor,
|
||||
animation: AnimationDropper,
|
||||
},
|
||||
Animation { cursor: CustomCursor, animation: AnimationDropper },
|
||||
}
|
||||
|
||||
impl From<SelectedCursor> for Previous {
|
||||
|
|
@ -472,17 +420,14 @@ impl From<SelectedCursor> for Previous {
|
|||
SelectedCursor::Image(image) => Self::Image(image),
|
||||
SelectedCursor::Animation { cursor, animation } => {
|
||||
Self::Animation { cursor, animation }
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ImageState {
|
||||
Loading {
|
||||
notifier: Notifier<Result<(), CustomCursorError>>,
|
||||
_handle: DropAbortHandle,
|
||||
},
|
||||
Loading { notifier: Notifier<Result<(), CustomCursorError>>, _handle: DropAbortHandle },
|
||||
Failed(CustomCursorError),
|
||||
Image(Image),
|
||||
Animation(Animation),
|
||||
|
|
@ -601,23 +546,13 @@ fn from_rgba(
|
|||
.expect("unexpected exception in `createImageBitmap()`"),
|
||||
);
|
||||
|
||||
let CursorImage {
|
||||
width,
|
||||
height,
|
||||
hotspot_x,
|
||||
hotspot_y,
|
||||
..
|
||||
} = *image;
|
||||
let CursorImage { width, height, hotspot_x, hotspot_y, .. } = *image;
|
||||
async move {
|
||||
let bitmap: ImageBitmap = bitmap
|
||||
.await
|
||||
.expect("found invalid state in `ImageData`")
|
||||
.unchecked_into();
|
||||
let bitmap: ImageBitmap =
|
||||
bitmap.await.expect("found invalid state in `ImageData`").unchecked_into();
|
||||
|
||||
let canvas: HtmlCanvasElement = document
|
||||
.create_element("canvas")
|
||||
.expect("invalid tag name")
|
||||
.unchecked_into();
|
||||
let canvas: HtmlCanvasElement =
|
||||
document.create_element("canvas").expect("invalid tag name").unchecked_into();
|
||||
#[allow(clippy::disallowed_methods)]
|
||||
canvas.set_width(width as u32);
|
||||
#[allow(clippy::disallowed_methods)]
|
||||
|
|
@ -724,7 +659,7 @@ async fn from_animation(
|
|||
let notified = notifier.notified();
|
||||
drop(state);
|
||||
notified.await?;
|
||||
}
|
||||
},
|
||||
ImageState::Failed(error) => return Err(error.clone()),
|
||||
ImageState::Image(_) => drop(state),
|
||||
ImageState::Animation(_) => unreachable!("check in `CustomCursorSource` failed"),
|
||||
|
|
@ -750,11 +685,7 @@ async fn from_animation(
|
|||
options.set_duration(duration.as_millis() as f64);
|
||||
options.set_iterations(f64::INFINITY);
|
||||
|
||||
Ok(Animation {
|
||||
keyframes,
|
||||
options,
|
||||
_images: images,
|
||||
})
|
||||
Ok(Animation { keyframes, options, _images: images })
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue