Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egui_plot formatter, spacer etc. should not need to be 'static #4434

Closed
Fabus1184 opened this issue Apr 29, 2024 · 0 comments · Fixed by #4435
Closed

egui_plot formatter, spacer etc. should not need to be 'static #4434

Fabus1184 opened this issue Apr 29, 2024 · 0 comments · Fixed by #4435

Comments

@Fabus1184
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Currently, all methods like Plot::{x,y}_grid_spacer or Plot::{x,y}_axis_formatter take an impl Fn... + 'static which is quite impractical mainly because these methods can easily require some access to self or other borrowed data.

Describe the solution you'd like
Introduce a lifetime for the Plot struct? Since a Plot is rarely stored in another struct, this shouldn't be too much of an issue.

Describe alternatives you've considered
Not using borrowed data or some sketchy shit with RefCells

Additional context

Basic example:

struct App {
    data: (),
}

impl App {
    pub fn draw(&self, ctx: &egui::Context) {
        egui::CentralPanel::default().show(ctx, |ui| {
            egui_plot::Plot::new("plot")
                .x_axis_formatter(|_, _, _| format!("{:?}", self.data))
                .show(ui, |_| {});
        });
    }
}

This does currently not work because x_axis_formatter requires a 'static lifetime

pub fn x_axis_formatter(self, fmt: impl Fn(GridMark, usize, &RangeInclusive<f64>) -> String + 'static) -> Self
emilk pushed a commit that referenced this issue May 15, 2024
…4435)

* Closes #4434

Shouldn't break anything, because when all arguments have a 'static
lifetime (required without this PR), the Plot is also 'static and can be
used like before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant