egui icon indicating copy to clipboard operation
egui copied to clipboard

Update file dialog example to be non-blocking.

Open hydra opened this issue 10 months ago • 7 comments

This PR updates the file dialog example to be non-blocking, additionally:

  • the 'Open file...' button is disabled while picking.
  • the main windows is responsive while picking - you can still drag files onto it and resize it just fine.
  • the picked file message is removed if the dialog is cancelled (try picking, then picking again and cancelling)
  • added 'try_lock' to mutex API, with tests.

The result of a pick is recorded and kept in the state as before.

Video: https://github.com/user-attachments/assets/29dd4cd9-b769-44f2-abe2-bd533728cdba

Related issues:

  • https://github.com/emilk/egui/issues/270

Related discussions:

  • https://github.com/emilk/egui/discussions/987#discussioncomment-1862596

  • https://github.com/emilk/egui/discussions/5621

  • [x] I have followed the instructions in the PR template

hydra avatar Feb 08 '25 16:02 hydra

This is my first PR for egui, be gentle 😄

hydra avatar Feb 08 '25 16:02 hydra

Also, I know this is just an example, but perhaps after merging this you might be interested in a PR to move the FilePicker from this PR into the main code base somewhere and expanding the API for the common use cases (files, directories, specification of path and file types).

I note that other GUI frameworks I've used have 'rfd' features and similar APIs. Cushy - https://github.com/khonsulabs/cushy/blob/main/src/dialog.rs#L352-L464

hydra avatar Feb 08 '25 17:02 hydra

Also, I know this is just an example, but perhaps after merging this you might be interested in a PR to move the FilePicker from this PR into the main code base somewhere and expanding the API for the common use cases (files, directories, specification of path and file types).

I note that other GUI frameworks I've used have 'rfd' features and similar APIs. Cushy - https://github.com/khonsulabs/cushy/blob/main/src/dialog.rs#L352-L464

I think it would be hard to implement this in a way that covers all the use cases of egui. For example, on wasm you can't spawn threads, so you have to use async, and then in rfd you have to pick which async backend you're using (async-std or tokio). Then there's the game engines and such. There are a couple of file pickers implemented as egui widgets instead of using rfd, as third-party crates. They are listed in the wiki.

YgorSouza avatar Feb 08 '25 20:02 YgorSouza

Also, I know this is just an example, but perhaps after merging this you might be interested in a PR to move the FilePicker from this PR into the main code base somewhere and expanding the API for the common use cases (files, directories, specification of path and file types).

I note that other GUI frameworks I've used have 'rfd' features and similar APIs. Cushy - https://github.com/khonsulabs/cushy/blob/main/src/dialog.rs#L352-L464

Also, I know this is just an example, but perhaps after merging this you might be interested in a PR to move the FilePicker from this PR into the main code base somewhere and expanding the API for the common use cases (files, directories, specification of path and file types). I note that other GUI frameworks I've used have 'rfd' features and similar APIs. Cushy - https://github.com/khonsulabs/cushy/blob/main/src/dialog.rs#L352-L464

I think it would be hard to implement this in a way that covers all the use cases of egui. For example, on wasm you can't spawn threads, so you have to use async, and then in rfd you have to pick which async backend you're using (async-std or tokio). Then there's the game engines and such. There are a couple of file pickers implemented as egui widgets instead of using rfd, as third-party crates. They are listed in the wiki.

Yes, I understand that there's various backends for async and limitations with wasm. I feel it would still be ok to provide solution for the common native desktop use-case however, along with appropriate module documentation containing links to the wiki of course. This feels like it would serve the community better rather than requiring each egui developer to implement, test and debug their own API for a common use-case no?

hydra avatar Feb 09 '25 09:02 hydra

IMO this should supplement the existing blocking example, possibly as a button indicating a blocking dialog and another indicating non-blocking.

landaire avatar Feb 11 '25 03:02 landaire

@emilk ok, thanks for the response and the link. I'll try and crate a separate example once I've worked out a good way of doing it.

hydra avatar Feb 17 '25 14:02 hydra

Preview available at https://egui-pr-preview.github.io/pr/5697-file-dialog-non-blocking-1 Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

github-actions[bot] avatar Feb 18 '25 15:02 github-actions[bot]