From acb69ab41060dd77acd9a5820f76de47a60fcdbd Mon Sep 17 00:00:00 2001 From: epezent Date: Mon, 24 Aug 2020 11:48:00 -0500 Subject: [PATCH] add Configuration section to demo --- implot.cpp | 12 +++++++----- implot.h | 11 ++++++----- implot_demo.cpp | 20 +++++++++++++++++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/implot.cpp b/implot.cpp index b4cfee1..7941d12 100644 --- a/implot.cpp +++ b/implot.cpp @@ -2034,6 +2034,9 @@ void SetColormap(ImPlotColormap colormap, int samples) { ResampleColormap(gp.Colormap, gp.ColormapSize, &resampled[0], samples); SetColormap(&resampled[0], samples); } + else { + BustItemCache(); + } } void SetColormap(const ImVec4* colors, int size) { @@ -2047,6 +2050,7 @@ void SetColormap(const ImVec4* colors, int size) { user_colormap.push_back(colors[i]); gp.Colormap = &user_colormap[0]; gp.ColormapSize = size; + BustItemCache(); } const ImVec4* GetColormap(ImPlotColormap colormap, int* size_out) { @@ -2475,12 +2479,14 @@ void ShowStyleEditor(ImPlotStyle* ref) { int size; const ImVec4* cmap = GetColormap(i, &size); bool selected = cmap == gp.Colormap; + if (selected) { + custom_set = false; + } if (!selected) ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.25f); if (ImGui::Button(GetColormapName(i), ImVec2(75,0))) { SetColormap(i); - BustItemCache(); custom_set = false; } if (!selected) @@ -2506,7 +2512,6 @@ void ShowStyleEditor(ImPlotStyle* ref) { ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.25f); if (ImGui::Button("Custom", ImVec2(75, 0))) { SetColormap(&custom[0], custom.Size); - BustItemCache(); custom_set = true; } if (!custom_set_now) @@ -2515,7 +2520,6 @@ void ShowStyleEditor(ImPlotStyle* ref) { custom.push_back(ImVec4(0,0,0,1)); if (custom_set) { SetColormap(&custom[0], custom.Size); - BustItemCache(); } } ImGui::SameLine(); @@ -2523,7 +2527,6 @@ void ShowStyleEditor(ImPlotStyle* ref) { custom.pop_back(); if (custom_set) { SetColormap(&custom[0], custom.Size); - BustItemCache(); } } ImGui::EndGroup(); @@ -2533,7 +2536,6 @@ void ShowStyleEditor(ImPlotStyle* ref) { ImGui::PushID(c); if (ImGui::ColorEdit4("##Col1", &custom[c].x, ImGuiColorEditFlags_NoInputs) && custom_set) { SetColormap(&custom[0], custom.Size); - BustItemCache(); } if ((c + 1) % 12 != 0) ImGui::SameLine(); diff --git a/implot.h b/implot.h index 34e369c..3216df5 100644 --- a/implot.h +++ b/implot.h @@ -171,7 +171,8 @@ struct ImPlotPoint { double operator[] (size_t idx) const { return (&x)[idx]; } double& operator[] (size_t idx) { return (&x)[idx]; } #ifdef IMPLOT_POINT_CLASS_EXTRA - IMPLOT_POINT_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImPlotPoint. + IMPLOT_POINT_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h + // to convert back and forth between your math types and ImPlotPoint. #endif }; @@ -418,7 +419,7 @@ bool IsLegendEntryHovered(const char* label_id); // Provides access to plot style structure for permanant modifications to colors, sizes, etc. ImPlotStyle& GetStyle(); -// Style colors from current ImGui style (default) +// Style colors for current ImGui style (default). void StyleColorsAuto(ImPlotStyle* dst = NULL); // Style colors for ImGui "Classic". void StyleColorsClassic(ImPlotStyle* dst = NULL); @@ -463,7 +464,7 @@ int GetColormapSize(); ImVec4 GetColormapColor(int index); // Linearly interpolates a color from the current colormap given t between 0 and 1. ImVec4 LerpColormap(float t); -// Returns the next unused colormap color and advances the colormap. Can be used to skip colors if desired. Call between BeginPlot/EndPlot. +// Returns the next unused colormap color and advances the colormap. Can be used to skip colors if desired. ImVec4 NextColormapColor(); const char* GetStyleColorName(ImPlotCol color); @@ -482,9 +483,9 @@ ImPlotInputMap& GetInputMap(); // Shows ImPlot style selector dropdown menu. bool ShowStyleSelector(const char* label); -// Shows ImPlot style editor block (not a window) +// Shows ImPlot style editor block (not a window). void ShowStyleEditor(ImPlotStyle* ref = NULL); -// Add basic help/info block (not a window): how to manipulate ImPlot as a end-user +// Add basic help/info block (not a window): how to manipulate ImPlot as an end-user. void ShowUserGuide(); // Push clip rect for rendering to current plot area. diff --git a/implot_demo.cpp b/implot_demo.cpp index 5284ecc..097a47c 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -139,6 +139,7 @@ struct BenchmarkItem { }; void ShowDemoWindow(bool* p_open) { + t_float DEMO_TIME = (t_float)ImGui::GetTime(); static bool show_imgui_metrics = false; static bool show_imgui_style_editor = false; static bool show_implot_style_editor = false; @@ -195,7 +196,24 @@ void ShowDemoWindow(bool* p_open) { ImGui::Text("USER GUIDE:"); ShowUserGuide(); } - t_float DEMO_TIME = (t_float)ImGui::GetTime(); + //------------------------------------------------------------------------- + if (ImGui::CollapsingHeader("Configuration")) { + ImGui::ShowFontSelector("Font"); + ImGui::ShowStyleSelector("ImGui Style"); + ImPlot::ShowStyleSelector("ImPlot Style"); + + static const char* map = ImPlot::GetColormapName(ImPlotColormap_Default); + if (ImGui::BeginCombo("ImPlot Colormap", map)) { + for (int i = 0; i < ImPlotColormap_COUNT; ++i) { + const char* name = GetColormapName(i); + if (ImGui::Selectable(name, map == name)) { + map = name; + ImPlot::SetColormap(i); + } + } + ImGui::EndCombo(); + } + } //------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Line Plots")) { static t_float xs1[1001], ys1[1001];