Skip to content

Commit

Permalink
Add demo of how to read plot state _before_ showing the plot
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 23, 2024
1 parent e3eb558 commit 5dc3fcb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/egui_demo_lib/src/demo/plot_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5dc3fcb

Please sign in to comment.