Skip to content

Commit

Permalink
Provide StyleColors... method aliases that take colors list directly
Browse files Browse the repository at this point in the history
  • Loading branch information
khiner committed Dec 12, 2023
1 parent a8c4a6c commit 844593b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
61 changes: 33 additions & 28 deletions implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4878,12 +4878,13 @@ bool ShowStyleSelector(const char* label)
static int style_idx = -1;
if (ImGui::Combo(label, &style_idx, "Auto\0Classic\0Dark\0Light\0"))
{
ImPlotStyle *dst = &GetStyle();
switch (style_idx)
{
case 0: StyleColorsAuto(); break;
case 1: StyleColorsClassic(); break;
case 2: StyleColorsDark(); break;
case 3: StyleColorsLight(); break;
case 0: StyleColorsAuto(dst); break;
case 1: StyleColorsClassic(dst); break;
case 2: StyleColorsDark(dst); break;
case 3: StyleColorsLight(dst); break;
}
return true;
}
Expand Down Expand Up @@ -5741,12 +5742,7 @@ bool ShowTimePicker(const char* id, ImPlotTime* t) {
return changed;
}

void StyleColorsAuto(ImPlotStyle* dst) {
ImPlotStyle* style = dst ? dst : &ImPlot::GetStyle();
ImVec4* colors = style->Colors;

style->MinorAlpha = 0.25f;

void StyleColorsAuto(ImVec4* colors) {
colors[ImPlotCol_Line] = IMPLOT_AUTO_COL;
colors[ImPlotCol_Fill] = IMPLOT_AUTO_COL;
colors[ImPlotCol_MarkerOutline] = IMPLOT_AUTO_COL;
Expand All @@ -5771,12 +5767,7 @@ void StyleColorsAuto(ImPlotStyle* dst) {
colors[ImPlotCol_Crosshairs] = IMPLOT_AUTO_COL;
}

void StyleColorsClassic(ImPlotStyle* dst) {
ImPlotStyle* style = dst ? dst : &ImPlot::GetStyle();
ImVec4* colors = style->Colors;

style->MinorAlpha = 0.5f;

void StyleColorsClassic(ImVec4* colors) {
colors[ImPlotCol_Line] = IMPLOT_AUTO_COL;
colors[ImPlotCol_Fill] = IMPLOT_AUTO_COL;
colors[ImPlotCol_MarkerOutline] = IMPLOT_AUTO_COL;
Expand All @@ -5800,12 +5791,7 @@ void StyleColorsClassic(ImPlotStyle* dst) {
colors[ImPlotCol_Crosshairs] = ImVec4(0.50f, 0.50f, 0.50f, 0.75f);
}

void StyleColorsDark(ImPlotStyle* dst) {
ImPlotStyle* style = dst ? dst : &ImPlot::GetStyle();
ImVec4* colors = style->Colors;

style->MinorAlpha = 0.25f;

void StyleColorsDark(ImVec4* colors) {
colors[ImPlotCol_Line] = IMPLOT_AUTO_COL;
colors[ImPlotCol_Fill] = IMPLOT_AUTO_COL;
colors[ImPlotCol_MarkerOutline] = IMPLOT_AUTO_COL;
Expand All @@ -5829,12 +5815,7 @@ void StyleColorsDark(ImPlotStyle* dst) {
colors[ImPlotCol_Crosshairs] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f);
}

void StyleColorsLight(ImPlotStyle* dst) {
ImPlotStyle* style = dst ? dst : &ImPlot::GetStyle();
ImVec4* colors = style->Colors;

style->MinorAlpha = 1.0f;

void StyleColorsLight(ImVec4* colors) {
colors[ImPlotCol_Line] = IMPLOT_AUTO_COL;
colors[ImPlotCol_Fill] = IMPLOT_AUTO_COL;
colors[ImPlotCol_MarkerOutline] = IMPLOT_AUTO_COL;
Expand All @@ -5858,6 +5839,30 @@ void StyleColorsLight(ImPlotStyle* dst) {
colors[ImPlotCol_Crosshairs] = ImVec4(0.00f, 0.00f, 0.00f, 0.50f);
}

void StyleColorsAuto(ImPlotStyle* dst) {
ImPlotStyle* style = dst ? dst : &ImPlot::GetStyle();
style->MinorAlpha = 0.25f;
StyleColorsAuto(style->Colors);
}

void StyleColorsClassic(ImPlotStyle* dst) {
ImPlotStyle* style = dst ? dst : &ImPlot::GetStyle();
style->MinorAlpha = 0.5f;
StyleColorsClassic(style->Colors);
}

void StyleColorsDark(ImPlotStyle* dst) {
ImPlotStyle* style = dst ? dst : &ImPlot::GetStyle();
style->MinorAlpha = 0.25f;
StyleColorsDark(style->Colors);
}

void StyleColorsLight(ImPlotStyle* dst) {
ImPlotStyle* style = dst ? dst : &ImPlot::GetStyle();
style->MinorAlpha = 1.0f;
StyleColorsLight(style->Colors);
}

//-----------------------------------------------------------------------------
// [SECTION] Obsolete Functions/Types
//-----------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,11 @@ IMPLOT_API void StyleColorsDark(ImPlotStyle* dst = nullptr);
// Style plot colors for ImGui "Light".
IMPLOT_API void StyleColorsLight(ImPlotStyle* dst = nullptr);

IMPLOT_API void StyleColorsAuto(ImVec4* dst = NULL);
IMPLOT_API void StyleColorsClassic(ImVec4* dst = NULL);
IMPLOT_API void StyleColorsDark(ImVec4* dst = NULL);
IMPLOT_API void StyleColorsLight(ImVec4* dst = NULL);

// Use PushStyleX to temporarily modify your ImPlotStyle. The modification
// will last until the matching call to PopStyleX. You MUST call a pop for
// every push, otherwise you will leak memory! This behaves just like ImGui.
Expand Down

0 comments on commit 844593b

Please sign in to comment.