Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set_cursor shortcut #359

Merged
merged 29 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c9115fa
feat: WIP Enhanced alignments
marc2332 Oct 14, 2023
5d67298
improvements
marc2332 Oct 14, 2023
c926baa
tweak
marc2332 Oct 14, 2023
74544bf
remove display attribute, remove 'both' direction, fix tests, fix doc…
marc2332 Oct 14, 2023
2cfc46a
feat: Updated examples
marc2332 Oct 15, 2023
736dda1
tests
marc2332 Oct 15, 2023
da4a1a2
fixed tests
marc2332 Oct 15, 2023
1bc2a53
Merge branch 'main' into feat/enhanced-alignments
marc2332 Oct 16, 2023
3d49e1d
update table component and example
marc2332 Oct 16, 2023
bb1de28
clean up
marc2332 Oct 17, 2023
981fe9a
clean up
marc2332 Oct 17, 2023
dcc3c57
improvements
marc2332 Oct 18, 2023
60e0ebf
improvements
marc2332 Oct 19, 2023
2e8056a
fixes
marc2332 Oct 19, 2023
f9e43b0
fix tests
marc2332 Oct 19, 2023
e9acaa3
tweak
marc2332 Oct 19, 2023
6503c07
tweaks
marc2332 Oct 20, 2023
2419b51
unsized alignment test
marc2332 Oct 21, 2023
9645714
document code
marc2332 Oct 21, 2023
bbf6c20
tweak
marc2332 Oct 21, 2023
00455d0
rename attributes
marc2332 Oct 22, 2023
d6e548f
fixes and cleanup
marc2332 Oct 22, 2023
24b22ce
Merge branch 'main' into feat/enhanced-alignments
marc2332 Oct 22, 2023
b0194ef
fixes and improvements
marc2332 Oct 22, 2023
3e8c68a
Merge branch 'feat/enhanced-alignments' of https://github.com/marc233…
marc2332 Oct 22, 2023
e7fb53f
Merge branch 'main' into feat/enhanced-alignments
marc2332 Oct 22, 2023
19b61aa
typo
marc2332 Oct 22, 2023
b433db0
feat: Easily change the cursor with use_platform
marc2332 Oct 22, 2023
9216358
Merge branch 'main' into feat/set-cursor-shortcut
marc2332 Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions crates/components/src/cursor_area.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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 @@ -47,27 +46,23 @@ pub fn CursorArea<'a>(cx: Scope<'a, CursorAreaProps<'a>>) -> Element<'a> {
to_owned![platform];
move |_| {
*is_hovering.write_silent() = true;
platform.send(EventMessage::SetCursorIcon(icon)).unwrap();
platform.set_cursor(icon);
}
};

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

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

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

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

pub fn request_animation_frame(&self) {
self.send(EventMessage::RequestRerender).ok();
}
Expand Down
Loading