From 2ae93c40ab896f31d9976df0c86242b813205722 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 13 Apr 2022 16:13:24 +0200 Subject: [PATCH] Move examples out of `eframe/examples` into `examples/` (#1486) * Move examples out of eframe/examples into examples/ Give each example a `Cargo.toml` and `src/main.rs`. This makes it easier for people to use as templates. * Update README.md with more deps needed on vanilla Ubuntu * Install libgtk-3-dev on CI, hoping that will fix something --- .github/workflows/rust.yml | 4 +- CHANGELOG.md | 2 +- Cargo.lock | 92 ++++++++++++++++-- Cargo.toml | 10 ++ README.md | 10 +- eframe/Cargo.toml | 16 --- eframe/README.md | 2 +- eframe/src/lib.rs | 10 +- egui/examples/README.md | 5 +- egui_glium/examples/native_texture.rs | 2 +- epi/src/lib.rs | 2 +- examples/README.md | 7 +- examples/confirm_exit/Cargo.toml | 12 +++ examples/confirm_exit/README.md | 3 + .../confirm_exit/src/main.rs | 8 +- examples/custom_3d_glow/Cargo.toml | 14 +++ examples/custom_3d_glow/README.md | 15 +++ .../custom_3d_glow/src/main.rs | 11 --- examples/custom_3d_three-d/Cargo.toml | 15 +++ examples/custom_3d_three-d/README.md | 16 +++ .../custom_3d_three-d/src/main.rs | 11 --- examples/custom_font/Cargo.toml | 12 +++ examples/custom_font/README.md | 3 + .../custom_font/src/main.rs | 2 +- examples/custom_window_frame/Cargo.toml | 12 +++ examples/custom_window_frame/README.md | 3 + .../custom_window_frame/src/main.rs | 0 examples/download_image/Cargo.toml | 16 +++ examples/download_image/README.md | 3 + .../download_image/src/main.rs | 0 examples/file_dialog/Cargo.toml | 13 +++ examples/file_dialog/README.md | 5 + .../file_dialog/src/main.rs | 0 examples/hello_world/Cargo.toml | 12 +++ examples/hello_world/README.md | 3 + .../hello_world/src/main.rs | 0 examples/retained_image/Cargo.toml | 14 +++ examples/retained_image/README.md | 3 + .../retained_image/src/main.rs | 0 .../retained_image/src}/rust-logo-256x256.png | Bin .../retained_image/src}/rust-logo-license.txt | 0 examples/svg/Cargo.toml | 13 +++ examples/svg/README.md | 6 ++ .../svg.rs => examples/svg/src/main.rs | 0 examples/svg/src/rust-logo-license.txt | 1 + .../svg/src}/rustacean-flat-happy.svg | 0 46 files changed, 317 insertions(+), 71 deletions(-) create mode 100644 examples/confirm_exit/Cargo.toml create mode 100644 examples/confirm_exit/README.md rename eframe/examples/confirm_exit.rs => examples/confirm_exit/src/main.rs (100%) create mode 100644 examples/custom_3d_glow/Cargo.toml create mode 100644 examples/custom_3d_glow/README.md rename eframe/examples/custom_3d_glow.rs => examples/custom_3d_glow/src/main.rs (92%) create mode 100644 examples/custom_3d_three-d/Cargo.toml create mode 100644 examples/custom_3d_three-d/README.md rename eframe/examples/custom_3d_three-d.rs => examples/custom_3d_three-d/src/main.rs (90%) create mode 100644 examples/custom_font/Cargo.toml create mode 100644 examples/custom_font/README.md rename eframe/examples/custom_font.rs => examples/custom_font/src/main.rs (94%) create mode 100644 examples/custom_window_frame/Cargo.toml create mode 100644 examples/custom_window_frame/README.md rename eframe/examples/custom_window_frame.rs => examples/custom_window_frame/src/main.rs (100%) create mode 100644 examples/download_image/Cargo.toml create mode 100644 examples/download_image/README.md rename eframe/examples/download_image.rs => examples/download_image/src/main.rs (100%) create mode 100644 examples/file_dialog/Cargo.toml create mode 100644 examples/file_dialog/README.md rename eframe/examples/file_dialog.rs => examples/file_dialog/src/main.rs (100%) create mode 100644 examples/hello_world/Cargo.toml create mode 100644 examples/hello_world/README.md rename eframe/examples/hello_world.rs => examples/hello_world/src/main.rs (100%) create mode 100644 examples/retained_image/Cargo.toml create mode 100644 examples/retained_image/README.md rename eframe/examples/image.rs => examples/retained_image/src/main.rs (100%) rename {eframe/examples => examples/retained_image/src}/rust-logo-256x256.png (100%) rename {eframe/examples => examples/retained_image/src}/rust-logo-license.txt (100%) create mode 100644 examples/svg/Cargo.toml create mode 100644 examples/svg/README.md rename eframe/examples/svg.rs => examples/svg/src/main.rs (100%) create mode 100644 examples/svg/src/rust-logo-license.txt rename {eframe/examples => examples/svg/src}/rustacean-flat-happy.svg (100%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 81be5ede..114ce4fe 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,7 +20,7 @@ jobs: profile: minimal toolchain: 1.60.0 override: true - - run: sudo apt-get update && sudo apt-get install libspeechd-dev + - run: sudo apt-get update && sudo apt-get install libspeechd-dev libgtk-3-dev - uses: actions-rs/cargo@v1 with: command: check @@ -35,7 +35,7 @@ jobs: profile: minimal toolchain: 1.60.0 override: true - - run: sudo apt-get update && sudo apt-get install libspeechd-dev + - run: sudo apt-get update && sudo apt-get install libspeechd-dev libgtk-3-dev - uses: actions-rs/cargo@v1 with: command: check diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f1f1543..ebc10051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w ## Unreleased ### Added ⭐ -* Added `Shape::Callback` for backend-specific painting, [with an example](https://github.com/emilk/egui/blob/master/eframe/examples/custom_3d_three-d.rs) ([#1351](https://github.com/emilk/egui/pull/1351)). +* Added `Shape::Callback` for backend-specific painting, [with an example](https://github.com/emilk/egui/blob/master/examples/custom_3d_three/) ([#1351](https://github.com/emilk/egui/pull/1351)). * Added `Frame::canvas` ([#1362](https://github.com/emilk/egui/pull/1362)). * `Context::request_repaint` will wake up UI thread, if integrations has called `Context::set_request_repaint_callback` ([#1366](https://github.com/emilk/egui/pull/1366)). * Added `Plot::allow_scroll`, `Plot::allow_zoom` no longer affects scrolling ([#1382](https://github.com/emilk/egui/pull/1382)). diff --git a/Cargo.lock b/Cargo.lock index 6e03615e..1e2ba61a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -608,6 +608,13 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "confirm_exit" +version = "0.1.0" +dependencies = [ + "eframe", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -817,6 +824,39 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" +[[package]] +name = "custom_3d_glow" +version = "0.1.0" +dependencies = [ + "eframe", + "egui_glow", + "glow", +] + +[[package]] +name = "custom_3d_three-d" +version = "0.1.0" +dependencies = [ + "eframe", + "egui_glow", + "glow", + "three-d", +] + +[[package]] +name = "custom_font" +version = "0.1.0" +dependencies = [ + "eframe", +] + +[[package]] +name = "custom_window_frame" +version = "0.1.0" +dependencies = [ + "eframe", +] + [[package]] name = "dark-light" version = "0.2.1" @@ -980,6 +1020,17 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +[[package]] +name = "download_image" +version = "0.1.0" +dependencies = [ + "eframe", + "egui_extras", + "ehttp", + "image", + "poll-promise", +] + [[package]] name = "dyn-clonable" version = "0.9.0" @@ -1019,18 +1070,9 @@ version = "0.17.0" dependencies = [ "egui", "egui-winit", - "egui_extras", "egui_glow", "egui_web", - "ehttp", "epi", - "glow", - "image", - "poll-promise", - "puffin", - "puffin_http", - "rfd", - "three-d", ] [[package]] @@ -1301,6 +1343,14 @@ dependencies = [ "instant", ] +[[package]] +name = "file_dialog" +version = "0.1.0" +dependencies = [ + "eframe", + "rfd", +] + [[package]] name = "flate2" version = "1.0.22" @@ -1702,6 +1752,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +[[package]] +name = "hello_world" +version = "0.1.0" +dependencies = [ + "eframe", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -2727,6 +2784,15 @@ dependencies = [ "usvg", ] +[[package]] +name = "retained_image" +version = "0.1.0" +dependencies = [ + "eframe", + "egui_extras", + "image", +] + [[package]] name = "rfd" version = "0.8.0" @@ -3128,6 +3194,14 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "svg" +version = "0.1.0" +dependencies = [ + "eframe", + "egui_extras", +] + [[package]] name = "svgfilters" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index bb600940..bf7e74b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,17 @@ members = [ "epaint", "epi", + "examples/confirm_exit", + "examples/custom_3d_glow", + "examples/custom_3d_three-d", + "examples/custom_font", + "examples/custom_window_frame", + "examples/download_image", + "examples/file_dialog", + "examples/hello_world", "examples/puffin_profiler", + "examples/retained_image", + "examples/svg", ] [profile.dev] diff --git a/README.md b/README.md index 861a7d52..f83aea47 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ ui.label(format!("Hello '{}', age {}", name, age)); ## Quick start -If you just want to write a GUI application in Rust (for the web or for native), go to and follow the instructions there! The official docs are at . For inspiration, check out the [the egui web demo](https://www.egui.rs/#demo) and follow the links in it to its source code. There is also an excellent tutorial video at . +There are simple examples in [the `examples/` folder](https://github.com/emilk/egui/blob/master/examples/). If you want to write a web app, then go to and follow the instructions. The official docs are at . For inspiration and more examples, check out the [the egui web demo](https://www.egui.rs/#demo) and follow the links in it to its source code. If you want to integrate egui into an existing engine, go to the [Integrations](#integrations) section. @@ -64,7 +64,7 @@ To test the demo app locally, run `cargo run --release -p egui_demo_app`. The native backend is [`egui_glow`](https://github.com/emilk/egui/tree/master/egui_glow) (using [`glow`](https://crates.io/crates/glow)) and should work out-of-the-box on Mac and Windows, but on Linux you need to first run: -`sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev` +`sudo apt-get install -y libclang-dev libgtk-3-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev` On Fedora Rawhide you need to run: @@ -312,7 +312,7 @@ Here is an example (from https://github.com/AlexxxRu/TinyPomodoro): If you call `.await` in your GUI code, the UI will freeze, with is very bad UX. Instead, keep the GUI thread non-blocking and communicate with any concurrent tasks (`async` tasks or other threads) with something like: * Channels (e.g. [`std::sync::mpsc::channel`](https://doc.rust-lang.org/std/sync/mpsc/fn.channel.html)). Make sure to use [`try_recv`](https://doc.rust-lang.org/std/sync/mpsc/struct.Receiver.html#method.try_recv) so you don't block the gui thread! * `Arc>` (background thread sets a value; GUI thread reads it) -* [`poll_promise::Promise`](https://docs.rs/poll-promise) (example: [`eframe/examples/download_image.rs`](https://github.com/emilk/egui/blob/master/eframe/examples/download_image.rs)) +* [`poll_promise::Promise`](https://docs.rs/poll-promise) (example: [`examples/download_image/`](https://github.com/emilk/egui/blob/master/examples/download_image/)) * [`eventuals::Eventual`](https://docs.rs/eventuals/latest/eventuals/struct.Eventual.html) * [`tokio::sync::watch::channel`](https://docs.rs/tokio/latest/tokio/sync/watch/fn.channel.html) @@ -338,8 +338,8 @@ If you want to embed 3D into an egui view there are two options. #### `Shape::Callback` Examples: -* -* +* +* `Shape::Callback` will call your code when egui gets painted, to show anything using whatever the background rendering context is. When using [`eframe`](https://github.com/emilk/egui/tree/master/eframe) this will be [`glow`](https://github.com/grovesNL/glow). Other integrations will give you other rendering contexts, if they support `Shape::Callback` at all. diff --git a/eframe/Cargo.toml b/eframe/Cargo.toml index 4b1f4569..177f2f9a 100644 --- a/eframe/Cargo.toml +++ b/eframe/Cargo.toml @@ -67,19 +67,3 @@ egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = fa # web: [target.'cfg(target_arch = "wasm32")'.dependencies] egui_web = { version = "0.17.0", path = "../egui_web", default-features = false } - - -[dev-dependencies] -# For examples: -egui_extras = { path = "../egui_extras", features = ["image", "svg"] } -ehttp = "0.2" -glow = "0.11" -image = { version = "0.24", default-features = false, features = [ - "jpeg", - "png", -] } -poll-promise = "0.1" -puffin = "0.13" -puffin_http = "0.10" -rfd = "0.8" -three-d = { version = "0.11", default-features = false } diff --git a/eframe/README.md b/eframe/README.md index b38e0c0b..432240e8 100644 --- a/eframe/README.md +++ b/eframe/README.md @@ -8,7 +8,7 @@ `eframe` is the official framework library for writing apps using [`egui`](https://github.com/emilk/egui). The app can be compiled both to run natively (cross platform) or be compiled to a web app (using WASM). -To get started, see the [crate examples](https://github.com/emilk/egui/tree/master/examples) and [single-file examples](https://github.com/emilk/egui/tree/master/eframe/examples). +To get started, see the [examples](https://github.com/emilk/egui/tree/master/examples). To learn how to set up `eframe` for web and native, go to and follow the instructions there! There is also a tutorial video at . diff --git a/eframe/src/lib.rs b/eframe/src/lib.rs index 45ff0f73..f732ce0b 100644 --- a/eframe/src/lib.rs +++ b/eframe/src/lib.rs @@ -4,14 +4,14 @@ //! and are happy with just using egui for all visuals, //! Then `eframe` is for you! //! -//! To get started, see the [crate examples](https://github.com/emilk/egui/tree/master/examples) and [single-file examples](https://github.com/emilk/egui/tree/master/eframe/examples). +//! To get started, see the [examples](https://github.com/emilk/egui/tree/master/examples). //! To learn how to set up `eframe` for web and native, go to and follow the instructions there! //! -//! You write your application code for [`epi`] (implementing [`epi::App`]) and then -//! call from [`crate::run_native`] your `main.rs`, and/or call `eframe::start_web` from your `lib.rs`. +//! In short, you implement [`App`] and then +//! call [`crate::run_native`] from your `main.rs`, and/or call `eframe::start_web` from your `lib.rs`. //! //! `eframe` is implemented using [`egui_web`](https://github.com/emilk/egui/tree/master/egui_web) for web and -//! [`egui_glium`](https://github.com/emilk/egui/tree/master/egui_glium) or [`egui_glow`](https://github.com/emilk/egui/tree/master/egui_glow) for native. +//! [`egui_glow`](https://github.com/emilk/egui/tree/master/egui_glow) for native. //! //! ## Usage, native: //! ``` no_run @@ -100,7 +100,7 @@ pub fn start_web(canvas_id: &str, app_creator: AppCreator) -> Result<(), wasm_bi /// This is how you start a native (desktop) app. /// /// The first argument is name of your app, used for the title bar of the native window -/// and the save location of persistence (see [`epi::App::save`]). +/// and the save location of persistence (see [`App::save`]). /// /// Call from `fn main` like this: /// ``` no_run diff --git a/egui/examples/README.md b/egui/examples/README.md index cdc7a211..a29996b2 100644 --- a/egui/examples/README.md +++ b/egui/examples/README.md @@ -1,6 +1,7 @@ There are no stand-alone egui examples, because egui is not stand-alone! -There are plenty of examples in [the online demo](https://www.egui.rs/#demo). You can find the source code for it at . +See the top-level [examples](https://github.com/emilk/egui/tree/master/examples/) folder instead. + +There are also plenty of examples in [the online demo](https://www.egui.rs/#demo). You can find the source code for it at . -If you are using `eframe`, the [crate examples](https://github.com/emilk/egui/tree/master/examples) and [single-file examples](https://github.com/emilk/egui/tree/master/eframe/examples). To learn how to set up `eframe` for web and native, go to and follow the instructions there! diff --git a/egui_glium/examples/native_texture.rs b/egui_glium/examples/native_texture.rs index abaafd46..4750d48b 100644 --- a/egui_glium/examples/native_texture.rs +++ b/egui_glium/examples/native_texture.rs @@ -10,7 +10,7 @@ fn main() { let mut egui_glium = egui_glium::EguiGlium::new(&display); - let png_data = include_bytes!("../../eframe/examples/rust-logo-256x256.png"); + let png_data = include_bytes!("../../examples/retained_image/src/rust-logo-256x256.png"); let image = load_glium_image(png_data); let image_size = egui::Vec2::new(image.width as f32, image.height as f32); // Load to gpu memory diff --git a/epi/src/lib.rs b/epi/src/lib.rs index 2b25696f..bbc0e838 100644 --- a/epi/src/lib.rs +++ b/epi/src/lib.rs @@ -72,7 +72,7 @@ pub trait App { /// /// A scenario where this method will be run is after pressing the close button on a native /// window, which allows you to ask the user whether they want to do something before exiting. - /// See the example `eframe/examples/confirm_exit.rs` for practical usage. + /// See the example at for practical usage. /// /// It will _not_ be called on the web or when the window is forcefully closed. fn on_exit_event(&mut self) -> bool { diff --git a/examples/README.md b/examples/README.md index 7bde00f6..141e2869 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1 +1,6 @@ -Examples of how to use [`eframe`](https://github.com/emilk/egui/tree/master/eframe) and [`egui`](https://github.com/emilk/egui/). +# `egui` and `eframe` examples +All the examples in this folder uses [`eframe`](https://github.com/emilk/egui/tree/master/eframe) to set up a window for [`egui`](https://github.com/emilk/egui/). Some examples are specific to `eframe`, but many are applicable to any `egui` integration. + +There are a lot more examples at , and it has links to the source code of each example. + +Also check out the official docs at and . diff --git a/examples/confirm_exit/Cargo.toml b/examples/confirm_exit/Cargo.toml new file mode 100644 index 00000000..a6dee834 --- /dev/null +++ b/examples/confirm_exit/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "confirm_exit" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } diff --git a/examples/confirm_exit/README.md b/examples/confirm_exit/README.md new file mode 100644 index 00000000..b159db58 --- /dev/null +++ b/examples/confirm_exit/README.md @@ -0,0 +1,3 @@ +```sh +cargo run -p confirm_exit +``` diff --git a/eframe/examples/confirm_exit.rs b/examples/confirm_exit/src/main.rs similarity index 100% rename from eframe/examples/confirm_exit.rs rename to examples/confirm_exit/src/main.rs index 70f317d3..27c6832d 100644 --- a/eframe/examples/confirm_exit.rs +++ b/examples/confirm_exit/src/main.rs @@ -34,14 +34,14 @@ impl eframe::App for MyApp { .resizable(false) .show(ctx, |ui| { ui.horizontal(|ui| { + if ui.button("Not yet").clicked() { + self.is_exiting = false; + } + if ui.button("Yes!").clicked() { self.can_exit = true; frame.quit(); } - - if ui.button("Not yet").clicked() { - self.is_exiting = false; - } }); }); } diff --git a/examples/custom_3d_glow/Cargo.toml b/examples/custom_3d_glow/Cargo.toml new file mode 100644 index 00000000..74268e5f --- /dev/null +++ b/examples/custom_3d_glow/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "custom_3d_glow" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } +egui_glow = { path = "../../egui_glow" } +glow = "0.11" diff --git a/examples/custom_3d_glow/README.md b/examples/custom_3d_glow/README.md new file mode 100644 index 00000000..41a5e12b --- /dev/null +++ b/examples/custom_3d_glow/README.md @@ -0,0 +1,15 @@ +This demo shows how to embed 3D rendering using [`glow`](https://github.com/grovesNL/glow) in `eframe`. + +This is very advanced usage, and you need to be careful. + +If you want an easier way to show 3D graphics with egui, take a look at the `custom_3d_three-d.rs` example. + +If you are content of having egui sit on top of a 3D background, take a look at: + +* [`bevy_egui`](https://github.com/mvlabat/bevy_egui) +* [`three-d`](https://github.com/asny/three-d) + + +```sh +cargo run -p custom_3d_glow +``` diff --git a/eframe/examples/custom_3d_glow.rs b/examples/custom_3d_glow/src/main.rs similarity index 92% rename from eframe/examples/custom_3d_glow.rs rename to examples/custom_3d_glow/src/main.rs index 22ace326..f6ed237f 100644 --- a/eframe/examples/custom_3d_glow.rs +++ b/examples/custom_3d_glow/src/main.rs @@ -1,14 +1,3 @@ -//! This demo shows how to embed 3D rendering using [`glow`](https://github.com/grovesNL/glow) in `eframe`. -//! -//! This is very advanced usage, and you need to be careful. -//! -//! If you want an easier way to show 3D graphics with egui, take a look at the `custom_3d_three-d.rs` example. -//! -//! If you are content of having egui sit on top of a 3D background, take a look at: -//! -//! * [`bevy_egui`](https://github.com/mvlabat/bevy_egui) -//! * [`three-d`](https://github.com/asny/three-d) - #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![allow(unsafe_code)] diff --git a/examples/custom_3d_three-d/Cargo.toml b/examples/custom_3d_three-d/Cargo.toml new file mode 100644 index 00000000..83ec88ba --- /dev/null +++ b/examples/custom_3d_three-d/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "custom_3d_three-d" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } +egui_glow = { path = "../../egui_glow" } +glow = "0.11" +three-d = { version = "0.11", default-features = false } diff --git a/examples/custom_3d_three-d/README.md b/examples/custom_3d_three-d/README.md new file mode 100644 index 00000000..c6de521f --- /dev/null +++ b/examples/custom_3d_three-d/README.md @@ -0,0 +1,16 @@ +This demo shows how to embed 3D rendering using [`three-d`](https://github.com/asny/three-d) in `eframe`. + +Any 3D library built on top of [`glow`](https://github.com/grovesNL/glow) can be used in `eframe`. + +Alternatively you can render 3D stuff to a texture and display it using [`egui::Ui::image`]. + +If you are content of having egui sit on top of a 3D background, take a look at: + +* [`bevy_egui`](https://github.com/mvlabat/bevy_egui) +* [`three-d`](https://github.com/asny/three-d) + + + +```sh +cargo run -p custom_3d_three-d +``` diff --git a/eframe/examples/custom_3d_three-d.rs b/examples/custom_3d_three-d/src/main.rs similarity index 90% rename from eframe/examples/custom_3d_three-d.rs rename to examples/custom_3d_three-d/src/main.rs index e91a5652..4386ef7c 100644 --- a/eframe/examples/custom_3d_three-d.rs +++ b/examples/custom_3d_three-d/src/main.rs @@ -1,14 +1,3 @@ -//! This demo shows how to embed 3D rendering using [`three-d`](https://github.com/asny/three-d) in `eframe`. -//! -//! Any 3D library built on top of [`glow`](https://github.com/grovesNL/glow) can be used in `eframe`. -//! -//! Alternatively you can render 3D stuff to a texture and display it using [`egui::Ui::image`]. -//! -//! If you are content of having egui sit on top of a 3D background, take a look at: -//! -//! * [`bevy_egui`](https://github.com/mvlabat/bevy_egui) -//! * [`three-d`](https://github.com/asny/three-d) - #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release use eframe::egui; diff --git a/examples/custom_font/Cargo.toml b/examples/custom_font/Cargo.toml new file mode 100644 index 00000000..9c9bf122 --- /dev/null +++ b/examples/custom_font/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "custom_font" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } diff --git a/examples/custom_font/README.md b/examples/custom_font/README.md new file mode 100644 index 00000000..20258b58 --- /dev/null +++ b/examples/custom_font/README.md @@ -0,0 +1,3 @@ +```sh +cargo run -p custom_font +``` diff --git a/eframe/examples/custom_font.rs b/examples/custom_font/src/main.rs similarity index 94% rename from eframe/examples/custom_font.rs rename to examples/custom_font/src/main.rs index d705fc99..a24fc1f6 100644 --- a/eframe/examples/custom_font.rs +++ b/examples/custom_font/src/main.rs @@ -19,7 +19,7 @@ fn setup_custom_fonts(ctx: &egui::Context) { // .ttf and .otf files supported. fonts.font_data.insert( "my_font".to_owned(), - egui::FontData::from_static(include_bytes!("../../epaint/fonts/Hack-Regular.ttf")), + egui::FontData::from_static(include_bytes!("../../../epaint/fonts/Hack-Regular.ttf")), ); // Put my font first (highest priority) for proportional text: diff --git a/examples/custom_window_frame/Cargo.toml b/examples/custom_window_frame/Cargo.toml new file mode 100644 index 00000000..93d8aecc --- /dev/null +++ b/examples/custom_window_frame/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "custom_window_frame" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } diff --git a/examples/custom_window_frame/README.md b/examples/custom_window_frame/README.md new file mode 100644 index 00000000..dc1d02a8 --- /dev/null +++ b/examples/custom_window_frame/README.md @@ -0,0 +1,3 @@ +```sh +cargo run -p custom_window_frame +``` diff --git a/eframe/examples/custom_window_frame.rs b/examples/custom_window_frame/src/main.rs similarity index 100% rename from eframe/examples/custom_window_frame.rs rename to examples/custom_window_frame/src/main.rs diff --git a/examples/download_image/Cargo.toml b/examples/download_image/Cargo.toml new file mode 100644 index 00000000..cbe5f7d7 --- /dev/null +++ b/examples/download_image/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "download_image" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } +egui_extras = { path = "../../egui_extras", features = ["image"] } +ehttp = "0.2" +image = { version = "0.24", default-features = false, features = ["jpeg"] } +poll-promise = "0.1" diff --git a/examples/download_image/README.md b/examples/download_image/README.md new file mode 100644 index 00000000..a2123b58 --- /dev/null +++ b/examples/download_image/README.md @@ -0,0 +1,3 @@ +```sh +cargo run -p download_image +``` diff --git a/eframe/examples/download_image.rs b/examples/download_image/src/main.rs similarity index 100% rename from eframe/examples/download_image.rs rename to examples/download_image/src/main.rs diff --git a/examples/file_dialog/Cargo.toml b/examples/file_dialog/Cargo.toml new file mode 100644 index 00000000..74db8f27 --- /dev/null +++ b/examples/file_dialog/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "file_dialog" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } +rfd = "0.8" diff --git a/examples/file_dialog/README.md b/examples/file_dialog/README.md new file mode 100644 index 00000000..470004f1 --- /dev/null +++ b/examples/file_dialog/README.md @@ -0,0 +1,5 @@ +How to show a file dialog using [`rfd`](https://github.com/PolyMeilex/rfd). + +```sh +cargo run -p file_dialog +``` diff --git a/eframe/examples/file_dialog.rs b/examples/file_dialog/src/main.rs similarity index 100% rename from eframe/examples/file_dialog.rs rename to examples/file_dialog/src/main.rs diff --git a/examples/hello_world/Cargo.toml b/examples/hello_world/Cargo.toml new file mode 100644 index 00000000..c0514741 --- /dev/null +++ b/examples/hello_world/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "hello_world" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } diff --git a/examples/hello_world/README.md b/examples/hello_world/README.md new file mode 100644 index 00000000..d528b1bc --- /dev/null +++ b/examples/hello_world/README.md @@ -0,0 +1,3 @@ +```sh +cargo run -p hello_world +``` diff --git a/eframe/examples/hello_world.rs b/examples/hello_world/src/main.rs similarity index 100% rename from eframe/examples/hello_world.rs rename to examples/hello_world/src/main.rs diff --git a/examples/retained_image/Cargo.toml b/examples/retained_image/Cargo.toml new file mode 100644 index 00000000..fc647c41 --- /dev/null +++ b/examples/retained_image/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "retained_image" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } +egui_extras = { path = "../../egui_extras", features = ["image"] } +image = { version = "0.24", default-features = false, features = ["png"] } diff --git a/examples/retained_image/README.md b/examples/retained_image/README.md new file mode 100644 index 00000000..2896e9ac --- /dev/null +++ b/examples/retained_image/README.md @@ -0,0 +1,3 @@ +```sh +cargo run -p retained_image +``` diff --git a/eframe/examples/image.rs b/examples/retained_image/src/main.rs similarity index 100% rename from eframe/examples/image.rs rename to examples/retained_image/src/main.rs diff --git a/eframe/examples/rust-logo-256x256.png b/examples/retained_image/src/rust-logo-256x256.png similarity index 100% rename from eframe/examples/rust-logo-256x256.png rename to examples/retained_image/src/rust-logo-256x256.png diff --git a/eframe/examples/rust-logo-license.txt b/examples/retained_image/src/rust-logo-license.txt similarity index 100% rename from eframe/examples/rust-logo-license.txt rename to examples/retained_image/src/rust-logo-license.txt diff --git a/examples/svg/Cargo.toml b/examples/svg/Cargo.toml new file mode 100644 index 00000000..0e2cdba3 --- /dev/null +++ b/examples/svg/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "svg" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.60" +publish = false + + +[dependencies] +eframe = { path = "../../eframe" } +egui_extras = { path = "../../egui_extras", features = ["svg"] } diff --git a/examples/svg/README.md b/examples/svg/README.md new file mode 100644 index 00000000..7fedd163 --- /dev/null +++ b/examples/svg/README.md @@ -0,0 +1,6 @@ +Example how to show an SVG image. + + +```sh +cargo run -p svg +``` diff --git a/eframe/examples/svg.rs b/examples/svg/src/main.rs similarity index 100% rename from eframe/examples/svg.rs rename to examples/svg/src/main.rs diff --git a/examples/svg/src/rust-logo-license.txt b/examples/svg/src/rust-logo-license.txt new file mode 100644 index 00000000..7efaf759 --- /dev/null +++ b/examples/svg/src/rust-logo-license.txt @@ -0,0 +1 @@ +Rust logo by Mozilla, from https://github.com/rust-lang/rust-artwork diff --git a/eframe/examples/rustacean-flat-happy.svg b/examples/svg/src/rustacean-flat-happy.svg similarity index 100% rename from eframe/examples/rustacean-flat-happy.svg rename to examples/svg/src/rustacean-flat-happy.svg