emilk / egui_plot

2D plotting library in Rust for egui
Apache License 2.0
95 stars 31 forks source link

Non-static Plot::label_formatter closure #10

Open zdimension opened 1 year ago

zdimension commented 1 year ago

Is your feature request related to a problem? Please describe.

I'm using the Plot component for physical measurements, for which I want to calculate the instantaneous derivative and definite integral, both of which should be displayed in the mouse-hover label.

Problem: the closure expected by Plot::label_formatter needs to be static. I want to compute derivatives and integrals in the label (values that require accessing other plot points than the one being hovered), but this requires borrowing things in the closure, but since it needs to be static, I can't borrow non-static data. I have to resort to weird hacks such as unsafe &* lifetime extension. There may be other ways around, with Arc maybe, but they're not ergonomic.

Describe the solution you'd like

Allow Plot::label_formatter to take a non-static closure.