implot icon indicating copy to clipboard operation
implot copied to clipboard

feat: add `IsPlotChanging()`

Open SamuMazzi opened this issue 1 year ago • 2 comments

As pointed out in the TODO.md, this PR implements a function to detect if the limits of the plots are changing.

SamuMazzi avatar Sep 23 '24 08:09 SamuMazzi

@SamuMazzi Thanks for taking a swing at this. A couple things:

I think the following code in SetupAxis will only be called every frame if the user explicitly calls SetupAxis/SetupAxes in their plot code block. Since this is not required, this feature will not work in some scenarios (e.g. the Plot Shaded demo and others)

// cache previous range
axis.PreviousRange = ImPlotRange(axis.Range.Min, axis.Range.Max);

I think the solution here is to cache the previous range(s) in SetupFinish, just before UpdateInput. Lemme know what you think.

Second, I suggest we name this function something more descriptive and also consider if it should be callable per-axis, for instance:

bool IsAxisRangeChanging(ImAxis axis)

epezent avatar Dec 24 '24 15:12 epezent

Since this is not required, this feature will not work in some scenarios (e.g. the Plot Shaded demo and others)

Nice catch, thank you, I didn't think about that!

Second, I suggest we name this function something more descriptive and also consider if it should be callable per-axis

Yes, perfect! I used the previous name just because of the notes in the TODO.md, but it makes more sense this name (and also the selection of the axis) ;)

And also sorry, I made a little mess with commits, hope it's not a problem!

SamuMazzi avatar Dec 26 '24 17:12 SamuMazzi