Skip to content

Commit

Permalink
remove BustItemCache from SetColormap and add ShowColormapSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
epezent committed Oct 11, 2020
1 parent da5b4ab commit 8a3ccf0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
27 changes: 23 additions & 4 deletions implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2953,9 +2953,6 @@ 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) {
Expand All @@ -2969,7 +2966,6 @@ 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) {
Expand Down Expand Up @@ -3240,6 +3236,24 @@ bool ShowStyleSelector(const char* label)
return false;
}

bool ShowColormapSelector(const char* label) {
bool set = false;
static const char* map = ImPlot::GetColormapName(ImPlotColormap_Default);
if (ImGui::BeginCombo(label, 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);
ImPlot::BustItemCache();
set = true;
}
}
ImGui::EndCombo();
}
return set;
}

void ShowStyleEditor(ImPlotStyle* ref) {
ImPlotContext& gp = *GImPlot;
ImPlotStyle& style = GetStyle();
Expand Down Expand Up @@ -3409,6 +3423,7 @@ void ShowStyleEditor(ImPlotStyle* ref) {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.25f);
if (ImGui::Button(GetColormapName(i), ImVec2(75,0))) {
SetColormap(i);
BustItemCache();
custom_set = false;
}
if (!selected)
Expand All @@ -3434,6 +3449,7 @@ 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)
Expand All @@ -3442,13 +3458,15 @@ void ShowStyleEditor(ImPlotStyle* ref) {
custom.push_back(ImVec4(0,0,0,1));
if (custom_set) {
SetColormap(&custom[0], custom.Size);
BustItemCache();
}
}
ImGui::SameLine();
if (ImGui::Button("-", ImVec2((75 - ImGui::GetStyle().ItemSpacing.x)/2,0)) && custom.Size > 1) {
custom.pop_back();
if (custom_set) {
SetColormap(&custom[0], custom.Size);
BustItemCache();
}
}
ImGui::EndGroup();
Expand All @@ -3458,6 +3476,7 @@ 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();
Expand Down
4 changes: 3 additions & 1 deletion implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ IMPLOT_API ImPlotLimits GetPlotQuery(int y_axis = IMPLOT_AUTO);
// Plot Tools
//-----------------------------------------------------------------------------

// Shows an annotation callout at a chosen point.
// Shows an annotation callout at a chosen point.
IMPLOT_API void Annotate(double x, double y, const ImVec2& pix_offset, const char* fmt, ...) IM_FMTARGS(4);
IMPLOT_API void Annotate(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(5);
// Same as above, but the annotation will always be clamped to stay inside the plot area.
Expand Down Expand Up @@ -606,6 +606,8 @@ IMPLOT_API void PopPlotClipRect();

// Shows ImPlot style selector dropdown menu.
IMPLOT_API bool ShowStyleSelector(const char* label);
// Shows ImPlot colormap selector dropdown menu.
IMPLOT_API bool ShowColormapSelector(const char* label);
// Shows ImPlot style editor block (not a window).
IMPLOT_API void ShowStyleEditor(ImPlotStyle* ref = NULL);
// Add basic help/info block (not a window): how to manipulate ImPlot as an end-user.
Expand Down
13 changes: 1 addition & 12 deletions implot_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,7 @@ void ShowDemoWindow(bool* p_open) {
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();
}
ImPlot::ShowColormapSelector("ImPlot Colormap");
float indent = ImGui::CalcItemWidth() - ImGui::GetFrameHeight();
ImGui::Indent(ImGui::CalcItemWidth() - ImGui::GetFrameHeight());
ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines);
Expand Down

0 comments on commit 8a3ccf0

Please sign in to comment.