1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-22 18:28:53 -05:00

remove BustItemCache from SetColormap and add ShowColormapSelector

This commit is contained in:
epezent 2020-10-11 00:38:18 -05:00
parent da5b4ab8d3
commit 8a3ccf0a44
3 changed files with 27 additions and 17 deletions

View File

@ -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) {
@ -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) {
@ -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();
@ -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)
@ -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)
@ -3442,6 +3458,7 @@ void ShowStyleEditor(ImPlotStyle* ref) {
custom.push_back(ImVec4(0,0,0,1));
if (custom_set) {
SetColormap(&custom[0], custom.Size);
BustItemCache();
}
}
ImGui::SameLine();
@ -3449,6 +3466,7 @@ void ShowStyleEditor(ImPlotStyle* ref) {
custom.pop_back();
if (custom_set) {
SetColormap(&custom[0], custom.Size);
BustItemCache();
}
}
ImGui::EndGroup();
@ -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();

View File

@ -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.
@ -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.

View File

@ -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);