mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 23:13:13 -04:00
Merge branch 'master' of https://github.com/emilk/egui into multiples_viewports
This commit is contained in:
@@ -12,4 +12,8 @@ publish = false
|
||||
eframe = { path = "../../crates/eframe", features = [
|
||||
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO
|
||||
] }
|
||||
|
||||
# For image support:
|
||||
egui_extras = { path = "../../crates/egui_extras", features = ["image"] }
|
||||
|
||||
env_logger = "0.10"
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 12 KiB |
@@ -11,7 +11,12 @@ fn main() -> Result<(), eframe::Error> {
|
||||
eframe::run_native(
|
||||
"My egui App",
|
||||
options,
|
||||
Box::new(|_cc| Box::<MyApp>::default()),
|
||||
Box::new(|cc| {
|
||||
// This gives us image support:
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
|
||||
Box::<MyApp>::default()
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -43,6 +48,10 @@ impl eframe::App for MyApp {
|
||||
self.age += 1;
|
||||
}
|
||||
ui.label(format!("Hello '{}', age {}", self.name, self.age));
|
||||
|
||||
ui.image(egui::include_image!(
|
||||
"../../../crates/egui/assets/ferris.png"
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 12 KiB |
@@ -12,7 +12,7 @@ fn main() -> Result<(), eframe::Error> {
|
||||
"Image Viewer",
|
||||
options,
|
||||
Box::new(|cc| {
|
||||
// The following call is needed to load images when using `ui.image` and `egui::Image`:
|
||||
// This gives us image support:
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
Box::<MyApp>::default()
|
||||
}),
|
||||
@@ -29,8 +29,7 @@ impl eframe::App for MyApp {
|
||||
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)),
|
||||
egui::Image::new("https://picsum.photos/seed/1.759706314/1024").rounding(10.0),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,3 +3,5 @@ This example shows that you can save a plot in egui as a png.
|
||||
```sh
|
||||
cargo run -p save_plot
|
||||
```
|
||||
|
||||

|
||||
|
||||
BIN
examples/save_plot/screenshot.png
Normal file
BIN
examples/save_plot/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
@@ -8,7 +8,7 @@ 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)),
|
||||
initial_window_size: Some(egui::vec2(350.0, 200.0)),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
@@ -27,45 +27,19 @@ impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
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);
|
||||
let my_plot = Plot::new("My Plot").legend(Legend::default());
|
||||
|
||||
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);
|
||||
// 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"));
|
||||
});
|
||||
|
||||
// add some whitespace in y direction
|
||||
ui.add_space(border_y);
|
||||
// Remember the position of the plot
|
||||
plot_rect = Some(inner.response.rect);
|
||||
});
|
||||
|
||||
if let (Some(screenshot), Some(plot_location)) = (self.screenshot.take(), plot_rect) {
|
||||
|
||||
Reference in New Issue
Block a user