implot icon indicating copy to clipboard operation
implot copied to clipboard

PlotText does not honour ImPlotItemFlags_NoFit flag (v0.14)

Open villains opened this issue 3 years ago • 0 comments

As the title says. I was trying to plot some text annotations on a plot, without having the x- and y-axis extents increasing to fit the text. However, PlotText does not honour the new ImPlotItemFlags_NoFit flag, and updates the x and y extents anyway.

However, I was able to get it working with these 2 minor changes:

diff --git a/implot_items.cpp b/implot_items.cpp
index 1fbdf5b..f000f21 100644
--- a/implot_items.cpp
+++ b/implot_items.cpp
@@ -2656,7 +2656,7 @@ void PlotText(const char* text, double x, double y, const ImVec2& pixel_offset,
         ImVec2 siz = CalcTextSizeVertical(text) * 0.5f;
         ImVec2 ctr = siz * 0.5f;
         ImVec2 pos = PlotToPixels(ImPlotPoint(x,y),IMPLOT_AUTO,IMPLOT_AUTO) + ImVec2(-ctr.x, ctr.y) + pixel_offset;
-        if (FitThisFrame()) {
+        if (FitThisFrame() && (flags & ImPlotItemFlags_NoFit) == 0) {
             FitPoint(PixelsToPlot(pos));
             FitPoint(PixelsToPlot(pos.x + siz.x, pos.y - siz.y));
         }
@@ -2665,7 +2665,7 @@ void PlotText(const char* text, double x, double y, const ImVec2& pixel_offset,
     else {
         ImVec2 siz = ImGui::CalcTextSize(text);
         ImVec2 pos = PlotToPixels(ImPlotPoint(x,y),IMPLOT_AUTO,IMPLOT_AUTO) - siz * 0.5f + pixel_offset;
-        if (FitThisFrame()) {
+        if (FitThisFrame() && (flags & ImPlotItemFlags_NoFit) == 0) {
             FitPoint(PixelsToPlot(pos));
             FitPoint(PixelsToPlot(pos+siz));
         }

villains avatar Sep 22 '22 17:09 villains