Automatically generate screenshots for all examples (#2379)
|
|
@ -1147,6 +1147,7 @@ dependencies = [
|
||||||
"egui_glow",
|
"egui_glow",
|
||||||
"glow",
|
"glow",
|
||||||
"glutin",
|
"glutin",
|
||||||
|
"image",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"puffin",
|
"puffin",
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,10 @@ puffin = ["dep:puffin", "egui_glow?/puffin", "egui-wgpu?/puffin"]
|
||||||
## Enable screen reader support (requires `ctx.options().screen_reader = true;`)
|
## Enable screen reader support (requires `ctx.options().screen_reader = true;`)
|
||||||
screen_reader = ["egui-winit/screen_reader", "tts"]
|
screen_reader = ["egui-winit/screen_reader", "tts"]
|
||||||
|
|
||||||
|
## If set, eframe will look for the env-var `EFRAME_SCREENSHOT_TO` and write a screenshot to that location, and then quit.
|
||||||
|
## This is used to generate images for the examples.
|
||||||
|
__screenshot = ["dep:image"]
|
||||||
|
|
||||||
## Use [`wgpu`](https://docs.rs/wgpu) for painting (via [`egui-wgpu`](https://github.com/emilk/egui/tree/master/crates/egui-wgpu)).
|
## Use [`wgpu`](https://docs.rs/wgpu) for painting (via [`egui-wgpu`](https://github.com/emilk/egui/tree/master/crates/egui-wgpu)).
|
||||||
## This overrides the `glow` feature.
|
## This overrides the `glow` feature.
|
||||||
wgpu = ["dep:wgpu", "dep:egui-wgpu"]
|
wgpu = ["dep:wgpu", "dep:egui-wgpu"]
|
||||||
|
|
@ -89,6 +93,9 @@ directories-next = { version = "2", optional = true }
|
||||||
egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true, features = [
|
egui-wgpu = { version = "0.19.0", path = "../egui-wgpu", optional = true, features = [
|
||||||
"winit",
|
"winit",
|
||||||
] }
|
] }
|
||||||
|
image = { version = "0.24", optional = true, default-features = false, features = [
|
||||||
|
"png",
|
||||||
|
] }
|
||||||
puffin = { version = "0.14", optional = true }
|
puffin = { version = "0.14", optional = true }
|
||||||
wgpu = { version = "0.14", optional = true }
|
wgpu = { version = "0.14", optional = true }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,12 @@ mod native;
|
||||||
pub fn run_native(app_name: &str, native_options: NativeOptions, app_creator: AppCreator) {
|
pub fn run_native(app_name: &str, native_options: NativeOptions, app_creator: AppCreator) {
|
||||||
let renderer = native_options.renderer;
|
let renderer = native_options.renderer;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "__screenshot"))]
|
||||||
|
assert!(
|
||||||
|
std::env::var("EFRAME_SCREENSHOT_TO").is_err(),
|
||||||
|
"EFRAME_SCREENSHOT_TO found without compiling with the '__screenshot' feature"
|
||||||
|
);
|
||||||
|
|
||||||
match renderer {
|
match renderer {
|
||||||
#[cfg(feature = "glow")]
|
#[cfg(feature = "glow")]
|
||||||
Renderer::Glow => {
|
Renderer::Glow => {
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn centere_window_pos(
|
fn center_window_pos(
|
||||||
monitor: Option<winit::monitor::MonitorHandle>,
|
monitor: Option<winit::monitor::MonitorHandle>,
|
||||||
native_options: &mut epi::NativeOptions,
|
native_options: &mut epi::NativeOptions,
|
||||||
) {
|
) {
|
||||||
|
|
@ -308,6 +308,8 @@ mod glow_integration {
|
||||||
// suspends and resumes.
|
// suspends and resumes.
|
||||||
app_creator: Option<epi::AppCreator>,
|
app_creator: Option<epi::AppCreator>,
|
||||||
is_focused: bool,
|
is_focused: bool,
|
||||||
|
|
||||||
|
frame_nr: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlowWinitApp {
|
impl GlowWinitApp {
|
||||||
|
|
@ -324,6 +326,7 @@ mod glow_integration {
|
||||||
running: None,
|
running: None,
|
||||||
app_creator: Some(app_creator),
|
app_creator: Some(app_creator),
|
||||||
is_focused: true,
|
is_focused: true,
|
||||||
|
frame_nr: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -517,6 +520,26 @@ mod glow_integration {
|
||||||
|
|
||||||
integration.post_present(window);
|
integration.post_present(window);
|
||||||
|
|
||||||
|
#[cfg(feature = "__screenshot")]
|
||||||
|
// give it time to settle:
|
||||||
|
if self.frame_nr == 2 {
|
||||||
|
if let Ok(path) = std::env::var("EFRAME_SCREENSHOT_TO") {
|
||||||
|
assert!(
|
||||||
|
path.ends_with(".png"),
|
||||||
|
"Expected EFRAME_SCREENSHOT_TO to end with '.png', got {path:?}"
|
||||||
|
);
|
||||||
|
let [w, h] = screen_size_in_pixels;
|
||||||
|
let pixels = painter.read_screen_rgba(screen_size_in_pixels);
|
||||||
|
let image = image::RgbaImage::from_vec(w, h, pixels).unwrap();
|
||||||
|
let image = image::imageops::flip_vertical(&image);
|
||||||
|
image.save(&path).unwrap_or_else(|err| {
|
||||||
|
panic!("Failed to save screenshot to {path:?}: {err}");
|
||||||
|
});
|
||||||
|
eprintln!("Screenshot saved to {path:?}.");
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let control_flow = if integration.should_close() {
|
let control_flow = if integration.should_close() {
|
||||||
EventResult::Exit
|
EventResult::Exit
|
||||||
} else if repaint_after.is_zero() {
|
} else if repaint_after.is_zero() {
|
||||||
|
|
@ -546,6 +569,8 @@ mod glow_integration {
|
||||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.frame_nr += 1;
|
||||||
|
|
||||||
control_flow
|
control_flow
|
||||||
} else {
|
} else {
|
||||||
EventResult::Wait
|
EventResult::Wait
|
||||||
|
|
@ -659,7 +684,7 @@ mod glow_integration {
|
||||||
if native_options.run_and_return {
|
if native_options.run_and_return {
|
||||||
with_event_loop(native_options, |event_loop, mut native_options| {
|
with_event_loop(native_options, |event_loop, mut native_options| {
|
||||||
if native_options.centered {
|
if native_options.centered {
|
||||||
centere_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
center_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
let glow_eframe =
|
let glow_eframe =
|
||||||
|
|
@ -670,7 +695,7 @@ mod glow_integration {
|
||||||
let event_loop = create_event_loop_builder(&mut native_options).build();
|
let event_loop = create_event_loop_builder(&mut native_options).build();
|
||||||
|
|
||||||
if native_options.centered {
|
if native_options.centered {
|
||||||
centere_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
center_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
||||||
|
|
@ -718,6 +743,12 @@ mod wgpu_integration {
|
||||||
native_options: epi::NativeOptions,
|
native_options: epi::NativeOptions,
|
||||||
app_creator: epi::AppCreator,
|
app_creator: epi::AppCreator,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
#[cfg(feature = "__screenshot")]
|
||||||
|
assert!(
|
||||||
|
std::env::var("EFRAME_SCREENSHOT_TO").is_err(),
|
||||||
|
"EFRAME_SCREENSHOT_TO not yet implemented for wgpu backend"
|
||||||
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
repaint_proxy: Arc::new(std::sync::Mutex::new(event_loop.create_proxy())),
|
repaint_proxy: Arc::new(std::sync::Mutex::new(event_loop.create_proxy())),
|
||||||
app_name: app_name.to_owned(),
|
app_name: app_name.to_owned(),
|
||||||
|
|
@ -1050,7 +1081,7 @@ mod wgpu_integration {
|
||||||
if native_options.run_and_return {
|
if native_options.run_and_return {
|
||||||
with_event_loop(native_options, |event_loop, mut native_options| {
|
with_event_loop(native_options, |event_loop, mut native_options| {
|
||||||
if native_options.centered {
|
if native_options.centered {
|
||||||
centere_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
center_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
let wgpu_eframe =
|
let wgpu_eframe =
|
||||||
|
|
@ -1061,7 +1092,7 @@ mod wgpu_integration {
|
||||||
let event_loop = create_event_loop_builder(&mut native_options).build();
|
let event_loop = create_event_loop_builder(&mut native_options).build();
|
||||||
|
|
||||||
if native_options.centered {
|
if native_options.centered {
|
||||||
centere_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
center_window_pos(event_loop.available_monitors().next(), &mut native_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
||||||
|
|
|
||||||
|
|
@ -605,6 +605,38 @@ impl Painter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_screen_rgba(&self, [w, h]: [u32; 2]) -> Vec<u8> {
|
||||||
|
let mut pixels = vec![0_u8; (w * h * 4) as usize];
|
||||||
|
unsafe {
|
||||||
|
self.gl.read_pixels(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
w as _,
|
||||||
|
h as _,
|
||||||
|
glow::RGBA,
|
||||||
|
glow::UNSIGNED_BYTE,
|
||||||
|
glow::PixelPackData::Slice(&mut pixels),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pixels
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_screen_rgb(&self, [w, h]: [u32; 2]) -> Vec<u8> {
|
||||||
|
let mut pixels = vec![0_u8; (w * h * 3) as usize];
|
||||||
|
unsafe {
|
||||||
|
self.gl.read_pixels(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
w as _,
|
||||||
|
h as _,
|
||||||
|
glow::RGB,
|
||||||
|
glow::UNSIGNED_BYTE,
|
||||||
|
glow::PixelPackData::Slice(&mut pixels),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pixels
|
||||||
|
}
|
||||||
|
|
||||||
unsafe fn destroy_gl(&self) {
|
unsafe fn destroy_gl(&self) {
|
||||||
self.gl.delete_program(self.program);
|
self.gl.delete_program(self.program);
|
||||||
for tex in self.textures.values() {
|
for tex in self.textures.values() {
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,6 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
Example how to show a confirm dialog before exiting an application.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p confirm_exit
|
cargo run -p confirm_exit
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 3.0 KiB |
|
|
@ -3,7 +3,10 @@
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = eframe::NativeOptions::default();
|
let options = eframe::NativeOptions {
|
||||||
|
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"Confirm exit",
|
"Confirm exit",
|
||||||
options,
|
options,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe", features = ["glow"] }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
egui_glow = { path = "../../crates/egui_glow" }
|
egui_glow = { path = "../../crates/egui_glow" }
|
||||||
glow = "0.11"
|
glow = "0.11"
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,5 @@ If you are content of having egui sit on top of a 3D background, take a look at:
|
||||||
```sh
|
```sh
|
||||||
cargo run -p custom_3d_glow
|
cargo run -p custom_3d_glow
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 34 KiB |
|
|
@ -11,7 +11,9 @@ publish = false
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe", features = ["glow"] }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
egui_glow = { path = "../../crates/egui_glow" }
|
egui_glow = { path = "../../crates/egui_glow" }
|
||||||
glow = "0.11"
|
glow = "0.11"
|
||||||
three-d = { version = "0.13", default-features = false }
|
three-d = { version = "0.13", default-features = false }
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,5 @@ cargo run -p custom_3d_three-d
|
||||||
```
|
```
|
||||||
wasm-pack build examples/custom_3d_three-d --target web
|
wasm-pack build examples/custom_3d_three-d --target web
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 52 KiB |
|
|
@ -9,4 +9,6 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
Example of how to use custom fonts.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p custom_font
|
cargo run -p custom_font
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 5.5 KiB |
|
|
@ -3,7 +3,10 @@
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = eframe::NativeOptions::default();
|
let options = eframe::NativeOptions {
|
||||||
|
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"egui example: custom font",
|
"egui example: custom font",
|
||||||
options,
|
options,
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,6 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
|
Example how to define custom test styles.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p custom_font_style
|
cargo run -p custom_font_style
|
||||||
```
|
```
|
||||||

|
|
||||||
|

|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
|
@ -9,4 +9,6 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
Example how to show a custom window frame instead of the default OS window chrome decorations.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p custom_window_frame
|
cargo run -p custom_window_frame
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 8.2 KiB |
|
|
@ -11,6 +11,7 @@ fn main() {
|
||||||
// To have rounded corners we need transparency:
|
// To have rounded corners we need transparency:
|
||||||
transparent: true,
|
transparent: true,
|
||||||
min_window_size: Some(egui::vec2(320.0, 100.0)),
|
min_window_size: Some(egui::vec2(320.0, 100.0)),
|
||||||
|
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
egui_extras = { path = "../../crates/egui_extras", features = ["image"] }
|
egui_extras = { path = "../../crates/egui_extras", features = ["image"] }
|
||||||
ehttp = "0.2"
|
ehttp = "0.2"
|
||||||
image = { version = "0.24", default-features = false, features = ["jpeg"] }
|
image = { version = "0.24", default-features = false, features = ["jpeg"] }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
Example how to download and show an image with eframe/egui.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p download_image
|
cargo run -p download_image
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 353 KiB |
|
|
@ -9,5 +9,7 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
rfd = "0.10"
|
rfd = "0.10"
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,5 @@ How to show a file dialog using [`rfd`](https://github.com/PolyMeilex/rfd).
|
||||||
```sh
|
```sh
|
||||||
cargo run -p file_dialog
|
cargo run -p file_dialog
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 3.8 KiB |
|
|
@ -5,6 +5,7 @@ use eframe::egui;
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
drag_and_drop_support: true,
|
drag_and_drop_support: true,
|
||||||
|
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,7 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
tracing-subscriber = "0.3"
|
tracing-subscriber = "0.3"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
Example showing some UI controls like `Label`, `TextEdit`, `Slider`, `Button`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p hello_world
|
cargo run -p hello_world
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 7.5 KiB |
|
|
@ -6,7 +6,10 @@ fn main() {
|
||||||
// Log to stdout (if you run with `RUST_LOG=debug`).
|
// Log to stdout (if you run with `RUST_LOG=debug`).
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
let options = eframe::NativeOptions::default();
|
let options = eframe::NativeOptions {
|
||||||
|
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"My egui App",
|
"My egui App",
|
||||||
options,
|
options,
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,7 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
tracing-subscriber = "0.3"
|
tracing-subscriber = "0.3"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
```sh
|
```sh
|
||||||
cargo run -p hello_world
|
cargo run -p hello_world
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 7.3 KiB |
|
|
@ -9,6 +9,8 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe", features = ["puffin"] }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
puffin = "0.14"
|
puffin = "0.14"
|
||||||
puffin_http = "0.11"
|
puffin_http = "0.11"
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,5 @@ cargo run -p puffin_profiler &
|
||||||
cargo install puffin_viewer
|
cargo install puffin_viewer
|
||||||
puffin_viewer --url 127.0.0.1:8585
|
puffin_viewer --url 127.0.0.1:8585
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 20 KiB |
|
|
@ -9,6 +9,8 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
egui_extras = { path = "../../crates/egui_extras", features = ["image"] }
|
egui_extras = { path = "../../crates/egui_extras", features = ["image"] }
|
||||||
image = { version = "0.24", default-features = false, features = ["png"] }
|
image = { version = "0.24", default-features = false, features = ["png"] }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
Example how to show an image with eframe/egui.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p retained_image
|
cargo run -p retained_image
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 148 KiB |
|
|
@ -5,7 +5,7 @@ use egui_extras::RetainedImage;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
initial_window_size: Some(egui::vec2(500.0, 900.0)),
|
initial_window_size: Some(egui::vec2(300.0, 900.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
egui_extras = { path = "../../crates/egui_extras", features = ["image"] }
|
egui_extras = { path = "../../crates/egui_extras", features = ["image"] }
|
||||||
itertools = "0.10.3"
|
itertools = "0.10.3"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
Example how to take screenshots and display them with eframe/egui.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p screenshot
|
cargo run -p screenshot
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 6.5 KiB |
|
|
@ -74,23 +74,25 @@ impl eframe::App for MyApp {
|
||||||
|
|
||||||
self.take_screenshot = false;
|
self.take_screenshot = false;
|
||||||
if let Some(gl) = frame.gl() {
|
if let Some(gl) = frame.gl() {
|
||||||
let mut buf = vec![0u8; screen_size_px[0] as usize * screen_size_px[1] as usize * 4];
|
let [w, h] = screen_size_px;
|
||||||
|
let mut buf = vec![0u8; w as usize * h as usize * 4];
|
||||||
let pixels = glow::PixelPackData::Slice(&mut buf[..]);
|
let pixels = glow::PixelPackData::Slice(&mut buf[..]);
|
||||||
unsafe {
|
unsafe {
|
||||||
gl.read_pixels(
|
gl.read_pixels(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
screen_size_px[0] as i32,
|
w as i32,
|
||||||
screen_size_px[1] as i32,
|
h as i32,
|
||||||
glow::RGBA,
|
glow::RGBA,
|
||||||
glow::UNSIGNED_BYTE,
|
glow::UNSIGNED_BYTE,
|
||||||
pixels,
|
pixels,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flip vertically:
|
||||||
let mut rows: Vec<Vec<u8>> = buf
|
let mut rows: Vec<Vec<u8>> = buf
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chunks(screen_size_px[0] as usize * 4)
|
.chunks(w as usize * 4)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|chunk| chunk.collect())
|
.map(|chunk| chunk.collect())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,6 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,5 @@ See also <https://github.com/emilk/egui/issues/1918>.
|
||||||
```sh
|
```sh
|
||||||
cargo run -p serial_windows
|
cargo run -p serial_windows
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 1.6 KiB |
|
|
@ -9,6 +9,7 @@ fn main() {
|
||||||
|
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
run_and_return: true,
|
run_and_return: true,
|
||||||
|
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,7 @@ publish = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = { path = "../../crates/eframe" }
|
eframe = { path = "../../crates/eframe", features = [
|
||||||
|
"__screenshot", # __screenshot is so we can dump a ascreenshot using EFRAME_SCREENSHOT_TO
|
||||||
|
] }
|
||||||
egui_extras = { path = "../../crates/egui_extras", features = ["svg"] }
|
egui_extras = { path = "../../crates/egui_extras", features = ["svg"] }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
Example how to show an SVG image.
|
Example how to show an SVG image.
|
||||||
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo run -p svg
|
cargo run -p svg
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
|
After Width: | Height: | Size: 59 KiB |
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# This script generates screenshots for all the examples in examples/
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
||||||
|
cd "$script_path/.."
|
||||||
|
|
||||||
|
cd examples
|
||||||
|
for VARIABLE in $(ls -1d */ | sed 's/\/$//'); do
|
||||||
|
EFRAME_SCREENSHOT_TO="$VARIABLE/screenshot.png" cargo run -p $VARIABLE
|
||||||
|
done
|
||||||