1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Make egui_plot::PlotMemory public (#3871)

This allows users to e.g. read/write the plot bounds/transform before
and after showing a `Plot`.
This commit is contained in:
Emil Ernerfeldt
2024-01-23 09:47:47 +01:00
committed by GitHub
parent aa67d3180b
commit 2f9a4ca6e8
5 changed files with 163 additions and 98 deletions

View File

@@ -769,7 +769,20 @@ struct InteractionDemo {}
impl InteractionDemo {
#[allow(clippy::unused_self)]
fn ui(&mut self, ui: &mut Ui) -> Response {
let plot = Plot::new("interaction_demo").height(300.0);
let id = ui.make_persistent_id("interaction_demo");
// This demonstrates how to read info about the plot _before_ showing it:
let plot_memory = egui_plot::PlotMemory::load(ui.ctx(), id);
if let Some(plot_memory) = plot_memory {
let bounds = plot_memory.bounds();
ui.label(format!(
"plot bounds: min: {:.02?}, max: {:.02?}",
bounds.min(),
bounds.max()
));
}
let plot = Plot::new("interaction_demo").id(id).height(300.0);
let PlotResponse {
response,