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

Add basic file drag and drop support #1096

Merged
merged 2 commits into from
Jan 1, 2021
Merged

Conversation

ShadowMitia
Copy link
Contributor

Adds basic drag and drop support to bevy.

It simply exposes the relevant events already found in winit.
This has been tested on Linux, and because it simply wraps around the winit events, it should work on other systems just fine (hopefully!).

I still want to try wasm/web before merging. (Or someone else, I haven't played with wasm in rust or bevy much yet!)

Let me know if there's anything missing!

@Moxinilian Moxinilian added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets A-Windowing Platform-agnostic interface layer to run your app in and removed A-UI Graphical user interfaces, styles, layouts, and widgets labels Dec 20, 2020
Cargo.toml Outdated Show resolved Hide resolved
@@ -370,6 +400,7 @@ pub fn winit_runner(mut app: App) {
);
app.update();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other matches are not separated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you're saying here sorry, could you explain please?

@DJMcNab
Copy link
Member

DJMcNab commented Dec 22, 2020

Could you clarify in the title that this is file drag and drop support?

@ShadowMitia ShadowMitia changed the title Add basic drag and drop support Add basic file drag and drop support Dec 22, 2020
@ShadowMitia
Copy link
Contributor Author

@DJMcNab Will do. I'll update the commit message as well.

@ShadowMitia
Copy link
Contributor Author

I've tested on wasm, and this doesn't work unfortunently. But it looks like winit doesn't have it either https://github.com/rust-windowing/winit/blob/master/FEATURES.md#input-handling-1.

@ShadowMitia ShadowMitia marked this pull request as ready for review December 22, 2020 20:28
Cargo.toml Outdated Show resolved Hide resolved
}
WindowEvent::HoveredFile(path_buf) => {
let mut hovered_file_events =
app.resources.get_mut::<Events<HoveredFile>>().unwrap();
Copy link
Member

@cart cart Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably combine all drag and drop events into a single event. It seems like order of operations matters here (ex: when did the cancel happen relative to HoveredFile).

(not relevant to this pr, but there are a couple of other events here that we should revisit when it comes to combining/ordering, such as CursorLeft/CursorEntered)

@ShadowMitia ShadowMitia force-pushed the draganddrop branch 3 times, most recently from 52566de to 6d26499 Compare December 25, 2020 17:33
@ShadowMitia ShadowMitia marked this pull request as draft December 25, 2020 17:36
@ShadowMitia
Copy link
Contributor Author

ShadowMitia commented Dec 25, 2020

I took a stab at creating a simple plugin and resource to handle dropped files (and added it to `DefaultPlugins).
Is this the idea you had in mind @cart? I'm not completely satisfied with the interface, but then I'm still kinda new at Rust.

The plugin gives you a DragAndDrop resource, which you can iterate using a drain method.
Each file is a tuple of (PathBuf, and WindowId). If a path is a directory, the user is left to manage what to do.

I can't see the point of allowing direct access to HoveredFiles for now so I didn't create an interface for it, but maybe I'm wrong.
There is an is_hovered method if you want to do something special during hovering. (I'm thinking changing the cursor icon mainly or have some kind of feedback).

@ShadowMitia
Copy link
Contributor Author

ShadowMitia commented Dec 25, 2020

For reference, I'm also attempting to add file drag and drop for wasm into winit rust-windowing/winit#1808.
I hope I'm not falling into a rabbit hole 😁

@cart
Copy link
Member

cart commented Dec 31, 2020

I was more talking about combining the drag and drop events into a single event stream to preserve ordering (see the changes I just pushed).

I think the drag and drop plugin introduces a bit too much complexity for what it adds, so I reverted that in favor of the consolidated event.

@cart cart marked this pull request as ready for review December 31, 2020 22:27
@cart
Copy link
Member

cart commented Dec 31, 2020

Just rebased on master / resolved conflicts. I think this is good to go!

@ShadowMitia
Copy link
Contributor Author

I fixed the path in the README and changed the system name in the example to something a bit clearer.
Otheriwse I think it's all good (untill I get wasm working anyway, if it happens 😁 )

@cart cart merged commit a01f22e into bevyengine:master Jan 1, 2021
@ShadowMitia ShadowMitia deleted the draganddrop branch January 1, 2021 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants