1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-23 10:48:52 -05:00

add Configuration section to demo

This commit is contained in:
epezent 2020-08-24 11:48:00 -05:00
parent 2f139f8a99
commit acb69ab410
3 changed files with 32 additions and 11 deletions

View File

@ -2034,6 +2034,9 @@ void SetColormap(ImPlotColormap colormap, int samples) {
ResampleColormap(gp.Colormap, gp.ColormapSize, &resampled[0], samples); ResampleColormap(gp.Colormap, gp.ColormapSize, &resampled[0], samples);
SetColormap(&resampled[0], samples); SetColormap(&resampled[0], samples);
} }
else {
BustItemCache();
}
} }
void SetColormap(const ImVec4* colors, int size) { void SetColormap(const ImVec4* colors, int size) {
@ -2047,6 +2050,7 @@ void SetColormap(const ImVec4* colors, int size) {
user_colormap.push_back(colors[i]); user_colormap.push_back(colors[i]);
gp.Colormap = &user_colormap[0]; gp.Colormap = &user_colormap[0];
gp.ColormapSize = size; gp.ColormapSize = size;
BustItemCache();
} }
const ImVec4* GetColormap(ImPlotColormap colormap, int* size_out) { const ImVec4* GetColormap(ImPlotColormap colormap, int* size_out) {
@ -2475,12 +2479,14 @@ void ShowStyleEditor(ImPlotStyle* ref) {
int size; int size;
const ImVec4* cmap = GetColormap(i, &size); const ImVec4* cmap = GetColormap(i, &size);
bool selected = cmap == gp.Colormap; bool selected = cmap == gp.Colormap;
if (selected) {
custom_set = false;
}
if (!selected) if (!selected)
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.25f); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.25f);
if (ImGui::Button(GetColormapName(i), ImVec2(75,0))) { if (ImGui::Button(GetColormapName(i), ImVec2(75,0))) {
SetColormap(i); SetColormap(i);
BustItemCache();
custom_set = false; custom_set = false;
} }
if (!selected) if (!selected)
@ -2506,7 +2512,6 @@ void ShowStyleEditor(ImPlotStyle* ref) {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.25f); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.25f);
if (ImGui::Button("Custom", ImVec2(75, 0))) { if (ImGui::Button("Custom", ImVec2(75, 0))) {
SetColormap(&custom[0], custom.Size); SetColormap(&custom[0], custom.Size);
BustItemCache();
custom_set = true; custom_set = true;
} }
if (!custom_set_now) if (!custom_set_now)
@ -2515,7 +2520,6 @@ void ShowStyleEditor(ImPlotStyle* ref) {
custom.push_back(ImVec4(0,0,0,1)); custom.push_back(ImVec4(0,0,0,1));
if (custom_set) { if (custom_set) {
SetColormap(&custom[0], custom.Size); SetColormap(&custom[0], custom.Size);
BustItemCache();
} }
} }
ImGui::SameLine(); ImGui::SameLine();
@ -2523,7 +2527,6 @@ void ShowStyleEditor(ImPlotStyle* ref) {
custom.pop_back(); custom.pop_back();
if (custom_set) { if (custom_set) {
SetColormap(&custom[0], custom.Size); SetColormap(&custom[0], custom.Size);
BustItemCache();
} }
} }
ImGui::EndGroup(); ImGui::EndGroup();
@ -2533,7 +2536,6 @@ void ShowStyleEditor(ImPlotStyle* ref) {
ImGui::PushID(c); ImGui::PushID(c);
if (ImGui::ColorEdit4("##Col1", &custom[c].x, ImGuiColorEditFlags_NoInputs) && custom_set) { if (ImGui::ColorEdit4("##Col1", &custom[c].x, ImGuiColorEditFlags_NoInputs) && custom_set) {
SetColormap(&custom[0], custom.Size); SetColormap(&custom[0], custom.Size);
BustItemCache();
} }
if ((c + 1) % 12 != 0) if ((c + 1) % 12 != 0)
ImGui::SameLine(); ImGui::SameLine();

View File

@ -171,7 +171,8 @@ struct ImPlotPoint {
double operator[] (size_t idx) const { return (&x)[idx]; } double operator[] (size_t idx) const { return (&x)[idx]; }
double& operator[] (size_t idx) { return (&x)[idx]; } double& operator[] (size_t idx) { return (&x)[idx]; }
#ifdef IMPLOT_POINT_CLASS_EXTRA #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 #endif
}; };
@ -418,7 +419,7 @@ bool IsLegendEntryHovered(const char* label_id);
// Provides access to plot style structure for permanant modifications to colors, sizes, etc. // Provides access to plot style structure for permanant modifications to colors, sizes, etc.
ImPlotStyle& GetStyle(); ImPlotStyle& GetStyle();
// Style colors from current ImGui style (default) // Style colors for current ImGui style (default).
void StyleColorsAuto(ImPlotStyle* dst = NULL); void StyleColorsAuto(ImPlotStyle* dst = NULL);
// Style colors for ImGui "Classic". // Style colors for ImGui "Classic".
void StyleColorsClassic(ImPlotStyle* dst = NULL); void StyleColorsClassic(ImPlotStyle* dst = NULL);
@ -463,7 +464,7 @@ int GetColormapSize();
ImVec4 GetColormapColor(int index); ImVec4 GetColormapColor(int index);
// Linearly interpolates a color from the current colormap given t between 0 and 1. // Linearly interpolates a color from the current colormap given t between 0 and 1.
ImVec4 LerpColormap(float t); 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(); ImVec4 NextColormapColor();
const char* GetStyleColorName(ImPlotCol color); const char* GetStyleColorName(ImPlotCol color);
@ -482,9 +483,9 @@ ImPlotInputMap& GetInputMap();
// Shows ImPlot style selector dropdown menu. // Shows ImPlot style selector dropdown menu.
bool ShowStyleSelector(const char* label); 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); 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(); void ShowUserGuide();
// Push clip rect for rendering to current plot area. // Push clip rect for rendering to current plot area.

View File

@ -139,6 +139,7 @@ struct BenchmarkItem {
}; };
void ShowDemoWindow(bool* p_open) { void ShowDemoWindow(bool* p_open) {
t_float DEMO_TIME = (t_float)ImGui::GetTime();
static bool show_imgui_metrics = false; static bool show_imgui_metrics = false;
static bool show_imgui_style_editor = false; static bool show_imgui_style_editor = false;
static bool show_implot_style_editor = false; static bool show_implot_style_editor = false;
@ -195,7 +196,24 @@ void ShowDemoWindow(bool* p_open) {
ImGui::Text("USER GUIDE:"); ImGui::Text("USER GUIDE:");
ShowUserGuide(); 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")) { if (ImGui::CollapsingHeader("Line Plots")) {
static t_float xs1[1001], ys1[1001]; static t_float xs1[1001], ys1[1001];