-
Notifications
You must be signed in to change notification settings - Fork 130
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
support WindowEvent::DroppedFile #524
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "dropped_file" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
floem = { path = "../.." } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use floem::{ | ||
event::EventListener, | ||
keyboard::{Key, Modifiers, NamedKey}, | ||
unit::UnitExt, | ||
views::{dyn_view, Decorators}, | ||
IntoView, View, | ||
}; | ||
|
||
fn app_view() -> impl IntoView { | ||
let view = dyn_view(move || format!("dropped file")).style(|s| { | ||
s.size(100.pct(), 100.pct()) | ||
.flex_col() | ||
.items_center() | ||
.justify_center() | ||
}); | ||
|
||
let id = view.id(); | ||
view.on_key_up(Key::Named(NamedKey::F11), Modifiers::empty(), move |_| { | ||
id.inspect() | ||
}) | ||
.on_event_stop(EventListener::PointerMove, |x| { | ||
println!("PointerMove {:?}", x.point()); | ||
}) | ||
.on_event_stop(EventListener::DroppedFile, |x| { | ||
println!("DroppedFile {:?}", x); | ||
}) | ||
.on_event_stop(EventListener::DroppedFileWithPosition, |x| { | ||
println!("DroppedFileWithPosition {:?}", x.point()); | ||
}) | ||
} | ||
|
||
fn main() { | ||
floem::launch(app_view); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use peniko::kurbo::Point; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct DroppedFileWithPositionEvent { | ||
pub path: PathBuf, | ||
pub pos: Point, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct DroppedFileEvent { | ||
pub path: PathBuf, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cursor position is stored in
self.cursor_position
. So we should be able to send the dropped file event with the cursor position when the dropped file event was trigger from winit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried. It's not accurate. The mouse coordinates are not updated when you drag and drop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's something at winit's end. It should be fixed when this is implemented rust-windowing/winit#3833
Does it always emit pointer move after the file was dropped? If so, we don't need the drop file event without mouse position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, my observation is this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we just have one event
DroppedFile
with both path and pos please?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I just kept DroppedFileWithPositionEvent