1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

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

This commit is contained in:
Konkitoman
2023-08-15 02:17:12 +03:00
159 changed files with 2536 additions and 1163 deletions

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -153,7 +153,7 @@ impl RotatingTriangle {
let shader = gl
.create_shader(*shader_type)
.expect("Cannot create shader");
gl.shader_source(shader, &format!("{}\n{}", shader_version, shader_source));
gl.shader_source(shader, &format!("{shader_version}\n{shader_source}"));
gl.compile_shader(shader);
assert!(
gl.get_shader_compile_status(shader),

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["tami5 <kkharji@proton.me>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -67,8 +67,7 @@ fn parse_response(response: ehttp::Response) -> Result<RetainedImage, String> {
RetainedImage::from_image_bytes(&response.url, &response.bytes)
} else {
Err(format!(
"Expected image, found content-type {:?}",
content_type
"Expected image, found content-type {content_type:?}"
))
}
}

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Maxim Osipenko <maxim1999max@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -62,7 +62,7 @@ fn new_worker(
) -> (JoinHandle<()>, mpsc::SyncSender<egui::Context>) {
let (show_tx, show_rc) = mpsc::sync_channel(0);
let handle = std::thread::Builder::new()
.name(format!("EguiPanelWorker {}", thread_nr))
.name(format!("EguiPanelWorker {thread_nr}"))
.spawn(move || {
let mut state = ThreadState::new(thread_nr);
while let Ok(ctx) = show_rc.recv() {

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Jose Palazon <jose@palako.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -71,7 +71,7 @@ fn start_puffin_server() {
std::mem::forget(puffin_server);
}
Err(err) => {
eprintln!("Failed to start puffin server: {}", err);
eprintln!("Failed to start puffin server: {err}");
}
};
}

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -0,0 +1,16 @@
[package]
name = "save_plot"
version = "0.1.0"
authors = ["hacknus <l_stoeckli@bluewin.ch>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.67"
publish = false
[dependencies]
eframe = { path = "../../crates/eframe", features = [
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
] }
image = { version = "0.24", default-features = false, features = ["png"] }
rfd = "0.11.0"
env_logger = "0.10"

View File

@@ -0,0 +1,5 @@
This example shows that you can save a plot in egui as a png.
```sh
cargo run -p save_plot
```

View File

@@ -0,0 +1,108 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::egui::plot::{Legend, Line, Plot, PlotPoints};
use eframe::egui::ColorImage;
use eframe::egui::{self, ViewportRender};
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(350.0, 400.0)),
..Default::default()
};
eframe::run_native(
"My egui App with a plot",
options,
Box::new(|_cc| Box::<MyApp>::default()),
)
}
#[derive(Default)]
struct MyApp {
screenshot: Option<ColorImage>,
}
impl eframe::App for MyApp {
fn update(
&mut self,
ctx: &egui::Context,
frame: &mut eframe::Frame,
render: Option<&ViewportRender>,
) {
if let Some(render) = render {
render(ctx);
return;
}
let mut plot_rect = None;
egui::CentralPanel::default().show(ctx, |ui| {
// these are just some dummy variables for the example,
// such that the plot is not at position (0,0)
let height = 200.0;
let border_x = 11.0;
let border_y = 18.0;
let width = 300.0;
ui.heading("My egui Application");
// add some whitespace in y direction
ui.add_space(border_y);
if ui.button("Save Plot").clicked() {
frame.request_screenshot();
}
// add some whitespace in y direction
ui.add_space(border_y);
ui.horizontal(|ui| {
// add some whitespace in x direction
ui.add_space(border_x);
let my_plot = Plot::new("My Plot")
.height(height)
.width(width)
.legend(Legend::default());
// let's create a dummy line in the plot
let graph: Vec<[f64; 2]> = vec![[0.0, 1.0], [2.0, 3.0], [3.0, 2.0]];
let inner = my_plot.show(ui, |plot_ui| {
plot_ui.line(Line::new(PlotPoints::from(graph)).name("curve"));
});
// Remember the position of the plot
plot_rect = Some(inner.response.rect);
});
// add some whitespace in y direction
ui.add_space(border_y);
});
if let (Some(screenshot), Some(plot_location)) = (self.screenshot.take(), plot_rect) {
if let Some(mut path) = rfd::FileDialog::new().save_file() {
path.set_extension("png");
// for a full size application, we should put this in a different thread,
// so that the GUI doesn't lag during saving
let pixels_per_point = frame.info().native_pixels_per_point;
let plot = screenshot.region(&plot_location, pixels_per_point);
// save the plot to png
image::save_buffer(
&path,
plot.as_raw(),
plot.width() as u32,
plot.height() as u32,
image::ColorType::Rgba8,
)
.unwrap();
}
}
}
fn post_rendering(&mut self, _screen_size_px: [u32; 2], frame: &eframe::Frame) {
// this is inspired by the Egui screenshot example
if let Some(screenshot) = frame.screenshot() {
self.screenshot = Some(screenshot);
}
}
}

View File

@@ -7,7 +7,7 @@ authors = [
]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["TicClick <ya@ticclick.ch>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.67"
publish = false
[dependencies]

View File

@@ -19,7 +19,7 @@ fn main() -> eframe::Result<()> {
}
fn repr(attention: UserAttentionType) -> String {
format!("{:?}", attention)
format!("{attention:?}")
}
struct Application {