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:
parent
da5b4ab8d3
commit
8a3ccf0a44
27
implot.cpp
27
implot.cpp
|
@ -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();
|
||||
|
|
2
implot.h
2
implot.h
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user