1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-28 07:23:13 -04:00

Merge branch 'master' of https://github.com/emilk/egui into multiples_viewports

This commit is contained in:
Konkitoman
2023-09-19 17:22:31 +03:00
91 changed files with 3056 additions and 1525 deletions

View File

@@ -1,21 +0,0 @@
[package]
name = "download_image"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.70"
publish = false
[dependencies]
eframe = { path = "../../crates/eframe", features = [
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
] }
egui_extras = { path = "../../crates/egui_extras", features = [
"http",
"image",
"log",
] }
env_logger = "0.10"
image = { version = "0.24", default-features = false, features = ["jpeg"] }

View File

@@ -1,7 +0,0 @@
Example how to download and show an image with eframe/egui.
```sh
cargo run -p download_image
```
![](screenshot.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 KiB

View File

@@ -1,41 +0,0 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions::default();
eframe::run_native(
"Download and show an image with eframe/egui",
options,
Box::new(|cc| {
// Without the following call, the `Image2` created below
// will simply output `not supported` error messages.
egui_extras::loaders::install(&cc.egui_ctx);
Box::new(MyApp)
}),
)
}
#[derive(Default)]
struct MyApp;
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
let width = ui.available_width();
let half_height = ui.available_height() / 2.0;
ui.allocate_ui(egui::Vec2::new(width, half_height), |ui| {
ui.add(egui::Image2::from_uri(
"https://picsum.photos/seed/1.759706314/1024",
))
});
ui.allocate_ui(egui::Vec2::new(width, half_height), |ui| {
ui.add(egui::Image2::from_uri(
"https://this-is-hopefully-not-a-real-website.rs/image.png",
))
});
});
}
}

View File

@@ -1,7 +1,7 @@
[package]
name = "retained_image"
name = "images"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
authors = ["Jan Procházka <github.com/jprochazk>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.70"
@@ -10,8 +10,11 @@ publish = false
[dependencies]
eframe = { path = "../../crates/eframe", features = [
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
] }
egui_extras = { path = "../../crates/egui_extras", features = ["image", "log"] }
egui_extras = { path = "../../crates/egui_extras", features = ["all_loaders"] }
env_logger = "0.10"
image = { version = "0.24", default-features = false, features = ["png"] }
image = { version = "0.24", default-features = false, features = [
"jpeg",
"png",
] }

View File

@@ -0,0 +1,7 @@
Example showing how to show images with eframe/egui.
```sh
cargo run -p images
```
![](screenshot.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

View File

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -0,0 +1,38 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(600.0, 800.0)),
..Default::default()
};
eframe::run_native(
"Image Viewer",
options,
Box::new(|cc| {
// The following call is needed to load images when using `ui.image` and `egui::Image`:
egui_extras::install_image_loaders(&cc.egui_ctx);
Box::<MyApp>::default()
}),
)
}
#[derive(Default)]
struct MyApp {}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
egui::ScrollArea::new([true, true]).show(ui, |ui| {
ui.image(egui::include_image!("ferris.svg"));
ui.add(
egui::Image::new("https://picsum.photos/seed/1.759706314/1024")
.rounding(egui::Rounding::same(10.0)),
);
});
});
}
}

View File

@@ -56,6 +56,12 @@ fn start_puffin_server() {
Ok(puffin_server) => {
eprintln!("Run: cargo install puffin_viewer && puffin_viewer --url 127.0.0.1:8585");
std::process::Command::new("puffin_viewer")
.arg("--url")
.arg("127.0.0.1:8585")
.spawn()
.ok();
// We can store the server if we want, but in this case we just want
// it to keep running. Dropping it closes the server, so let's not drop it!
#[allow(clippy::mem_forget)]

View File

@@ -1,7 +0,0 @@
Example how to show an image with eframe/egui.
```sh
cargo run -p retained_image
```
![](screenshot.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

View File

@@ -1,84 +0,0 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::egui;
use egui_extras::RetainedImage;
fn main() -> Result<(), eframe::Error> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(400.0, 1000.0)),
..Default::default()
};
eframe::run_native(
"Show an image with eframe/egui",
options,
Box::new(|_cc| Box::<MyApp>::default()),
)
}
struct MyApp {
image: RetainedImage,
rounding: f32,
tint: egui::Color32,
}
impl Default for MyApp {
fn default() -> Self {
Self {
// crab image is CC0, found on https://stocksnap.io/search/crab
image: RetainedImage::from_image_bytes("crab.png", include_bytes!("crab.png")).unwrap(),
rounding: 32.0,
tint: egui::Color32::from_rgb(100, 200, 200),
}
}
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let Self {
image,
rounding,
tint,
} = self;
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("This is an image:");
image.show(ui);
ui.add_space(32.0);
ui.heading("This is a tinted image with rounded corners:");
ui.add(
egui::Image::new(image.texture_id(ctx), image.size_vec2())
.tint(*tint)
.rounding(*rounding),
);
ui.horizontal(|ui| {
ui.label("Tint:");
egui::color_picker::color_edit_button_srgba(
ui,
tint,
egui::color_picker::Alpha::BlendOrAdditive,
);
ui.add_space(16.0);
ui.label("Rounding:");
ui.add(
egui::DragValue::new(rounding)
.speed(1.0)
.clamp_range(0.0..=0.5 * image.size_vec2().min_elem()),
);
});
ui.add_space(32.0);
ui.heading("This is an image you can click:");
ui.add(egui::ImageButton::new(
image.texture_id(ctx),
image.size_vec2(),
));
});
}
}

View File

@@ -63,7 +63,7 @@ impl eframe::App for MyApp {
});
if let Some(texture) = self.texture.as_ref() {
ui.image(texture, ui.available_size());
ui.image((texture.id(), ui.available_size()));
} else {
ui.spinner();
}

View File

@@ -1,16 +0,0 @@
[package]
name = "svg"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.70"
publish = false
[dependencies]
eframe = { path = "../../crates/eframe", features = [
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
] }
egui_extras = { path = "../../crates/egui_extras", features = ["log", "svg"] }
env_logger = "0.10"

View File

@@ -1,7 +0,0 @@
Example how to show an SVG image.
```sh
cargo run -p svg
```
![](screenshot.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

View File

@@ -1,47 +0,0 @@
//! A good way of displaying an SVG image in egui.
//!
//! Requires the dependency `egui_extras` with the `svg` feature.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(1000.0, 700.0)),
..Default::default()
};
eframe::run_native(
"svg example",
options,
Box::new(|cc| {
// Without the following call, the `Image2` created below
// will simply output a `not supported` error message.
egui_extras::loaders::install(&cc.egui_ctx);
Box::new(MyApp)
}),
)
}
struct MyApp;
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("SVG example");
ui.label("The SVG is rasterized and displayed as a texture.");
ui.separator();
let max_size = ui.available_size();
ui.add(
egui::Image2::from_static_bytes(
"ferris.svg",
include_bytes!("rustacean-flat-happy.svg"),
)
.size_hint(max_size),
);
});
}
}

View File

@@ -1 +0,0 @@
Rust logo by Mozilla, from https://github.com/rust-lang/rust-artwork