Skip to content

Commit

Permalink
Revert "feat: Easily change the cursor with use_platform (#352)"
Browse files Browse the repository at this point in the history
This reverts commit f801af8.
  • Loading branch information
marc2332 authored Oct 23, 2023
1 parent b5fb10f commit fafbac7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 8 additions & 3 deletions crates/components/src/cursor_area.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use dioxus::prelude::*;
use freya_common::EventMessage;
use freya_elements::elements as dioxus_elements;
use freya_hooks::use_platform;
use winit::window::CursorIcon;
Expand Down Expand Up @@ -46,23 +47,27 @@ pub fn CursorArea<'a>(cx: Scope<'a, CursorAreaProps<'a>>) -> Element<'a> {
to_owned![platform];
move |_| {
*is_hovering.write_silent() = true;
platform.set_cursor(icon);
platform.send(EventMessage::SetCursorIcon(icon)).unwrap();
}
};

let onmouseleave = {
to_owned![platform];
move |_| {
*is_hovering.write_silent() = false;
platform.set_cursor(CursorIcon::default());
platform
.send(EventMessage::SetCursorIcon(CursorIcon::default()))
.unwrap();
}
};

use_on_unmount(cx, {
to_owned![is_hovering];
move || {
if *is_hovering.read() {
platform.set_cursor(CursorIcon::default());
platform
.send(EventMessage::SetCursorIcon(CursorIcon::default()))
.unwrap();
}
}
});
Expand Down
6 changes: 1 addition & 5 deletions crates/hooks/src/use_platform.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dioxus_core::ScopeState;
use freya_common::EventMessage;
use tokio::sync::mpsc::UnboundedSender;
use winit::{event_loop::EventLoopProxy, window::CursorIcon};
use winit::event_loop::EventLoopProxy;

#[derive(Clone)]
pub struct UsePlatform {
Expand All @@ -28,10 +28,6 @@ impl UsePlatform {
}
Ok(())
}

pub fn set_cursor(&self, cursor_icon: CursorIcon) {
self.send(EventMessage::SetCursorIcon(cursor_icon)).ok();
}
}

pub fn use_platform(cx: &ScopeState) -> UsePlatform {
Expand Down

0 comments on commit fafbac7

Please sign in to comment.