Skip to content

Commit

Permalink
fix imgui backward compat, YAxis[3], and add new demo benchmark optio…
Browse files Browse the repository at this point in the history
…n for LineG
  • Loading branch information
epezent committed Jul 10, 2021
1 parent 5ab78cb commit 51930a5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
7 changes: 1 addition & 6 deletions implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ You can read releases logs https://github.com/epezent/implot/releases for more d
#define ImDrawFlags_RoundCornersAll ImDrawCornerFlags_All
#endif

// Support for pre-1.84 versions. ImPool's GetSize() -> GetBufSize()
#if (IMGUI_VERSION_NUM < 18303)
#define GetBufSize GetSize // A little bit ugly since 'GetBufSize' could technically be used elsewhere (but currently isn't). Could use a proxy define if needed.
#endif

// Global plot context
ImPlotContext* GImPlot = NULL;

Expand Down Expand Up @@ -4483,7 +4478,7 @@ void ShowMetricsWindow(bool* p_popen) {
if (ImHasFlag(plot->Flags, ImPlotFlags_YAxis2))
fg.AddRect(plot->YAxis[1].HoverRect.Min, plot->YAxis[1].HoverRect.Max, IM_COL32(0,255,0,255));
if (ImHasFlag(plot->Flags, ImPlotFlags_YAxis3))
fg.AddRect(plot->YAxis[3].HoverRect.Min, plot->YAxis[2].HoverRect.Max, IM_COL32(0,255,0,255));
fg.AddRect(plot->YAxis[2].HoverRect.Min, plot->YAxis[2].HoverRect.Max, IM_COL32(0,255,0,255));
}
}
for (int p = 0; p < n_subplots; ++p) {
Expand Down
22 changes: 18 additions & 4 deletions implot_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2063,9 +2063,10 @@ struct BenchData {

enum BenchMode {
Line = 0,
Shaded = 1,
Scatter = 2,
Bars = 3
LineG = 1,
Shaded = 2,
Scatter = 3,
Bars = 4
};

struct BenchRecord {
Expand All @@ -2074,6 +2075,11 @@ struct BenchRecord {
ImVector<ImPlotPoint> Data;
};

ImPlotPoint BenchmarkGetter(void* data, int idx) {
float* values = (float*)data;
return ImPlotPoint(idx, values[idx]);
}

void ShowBenchmarkTool() {
static const int max_items = 500;
static BenchData items[max_items];
Expand All @@ -2083,7 +2089,7 @@ void ShowBenchmarkTool() {
static int F = 0;
static double t1, t2;
static int mode = BenchMode::Line;
const char* names[] = {"Line","Shaded","Scatter","Bars"};
const char* names[] = {"Line","LineG","Shaded","Scatter","Bars"};

static ImVector<BenchRecord> records;

Expand Down Expand Up @@ -2143,6 +2149,14 @@ void ShowBenchmarkTool() {
ImGui::PopID();
}
}
else if (mode == BenchMode::LineG) {
for (int i = 0; i < L; ++i) {
ImGui::PushID(i);
ImPlot::SetNextLineStyle(items[i].Col);
ImPlot::PlotLineG("##item",BenchmarkGetter,items[i].Data,1000);
ImGui::PopID();
}
}
else if (mode == BenchMode::Shaded) {
for (int i = 0; i < L; ++i) {
ImGui::PushID(i);
Expand Down
9 changes: 7 additions & 2 deletions implot_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
#error Must include implot.h before implot_internal.h
#endif

// Support for pre-1.84 versions. ImPool's GetSize() -> GetBufSize()
#if (IMGUI_VERSION_NUM < 18303)
#define GetBufSize GetSize
#endif

//-----------------------------------------------------------------------------
// [SECTION] Constants
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1264,8 +1269,8 @@ void FillRange(ImVector<T>& buffer, int n, T vmin, T vmax) {

// Offsets and strides a data buffer
template <typename T>
static inline T OffsetAndStride(const T* data, int idx, int count, int offset, int stride) {
idx = ImPosMod(offset + idx, count);
static inline T OffsetAndStride(const T* data, int idx, int , int , int stride) {
// idx = ImPosMod(offset + idx, count);
return *(const T*)(const void*)((const unsigned char*)data + (size_t)idx * stride);
}

Expand Down
6 changes: 0 additions & 6 deletions implot_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@
#define ImDrawFlags_RoundCornersAll ImDrawCornerFlags_All
#endif

// Support for pre-1.84 versions. ImPool's GetSize() -> GetBufSize()
#if (IMGUI_VERSION_NUM < 18303)
#define GetBufSize GetSize // A little bit ugly since 'GetBufSize' could technically be used elsewhere (but currently isn't). Could use a proxy define if needed.
#endif


namespace ImPlot {

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 51930a5

Please sign in to comment.