Skip to content

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

@Fabus1184

Description

@Fabus1184

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions