diff --git a/.github/CMakeLists.txt b/.github/CMakeLists.txt index 67bf4b5b..8ec6ac66 100644 --- a/.github/CMakeLists.txt +++ b/.github/CMakeLists.txt @@ -73,7 +73,7 @@ endif() # Define supported types via command line: # - With no choice all types are supported (so that the CI provides support for all known types) -# - with -DIMPLOT_CUSTOM_NUMERIC_TYPES="default" the default set defined in implot_items.cpp is used +# - with -DIMPLOT_CUSTOM_NUMERIC_TYPES="default" the default set defined in implot_internal.h is used # - with -DIMPLOT_CUSTOM_NUMERIC_TYPES="(int)(float)(double)" only int, float and double are supported if (NOT DEFINED IMPLOT_CUSTOM_NUMERIC_TYPES) set(IMPLOT_CUSTOM_NUMERIC_TYPES "all") diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d401e435..3b829afb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,6 +45,26 @@ jobs: file cmake-build/example_implot cmake-build/example_implot + Linux-custom-types: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + + - uses: actions/checkout@v3 + with: + repository: ocornut/imgui + path: imgui + + - name: Configure + run: cmake -DCMAKE_BUILD_TYPE=release "-DIMPLOT_CUSTOM_NUMERIC_TYPES=(float)(double)" -B cmake-build -S .github + + - name: Build + run: cmake --build cmake-build --parallel $(nproc) + + - name: Run + run: cmake-build/example_implot + MacOS: runs-on: macos-latest diff --git a/README.md b/README.md index 54249b45..3769e995 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ A: Yes, within reason. You can plot tens to hundreds of thousands of points with **Q: What data types can I plot?** A: ImPlot plotting functions accept most scalar types: -`float`, `double`, `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`. Arrays of custom structs or classes (e.g. `Vector2f` or similar) are easily passed to ImPlot functions using the built-in striding features (see `implot.h` for documentation), and many plotters provide a "getter" overload which accepts data generating callbacks. You can fully customize the list of accepted types by defining `IMPLOT_CUSTOM_NUMERIC_TYPES` at compile time: see doc in `implot_items.cpp`. +`float`, `double`, `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`. Arrays of custom structs or classes (e.g. `Vector2f` or similar) are easily passed to ImPlot functions using the built-in striding features (see `implot.h` for documentation), and many plotters provide a "getter" overload which accepts data generating callbacks. You can fully customize the list of accepted types by defining `IMPLOT_CUSTOM_NUMERIC_TYPES` at compile time: see doc in `implot_internal.h` (the define must be visible to every ImPlot source file, including `implot_demo.cpp`, or be set in `imconfig.h`). **Q: Can plot styles be modified?** diff --git a/implot_demo.cpp b/implot_demo.cpp index e920ede3..9e931f63 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -30,6 +30,7 @@ #include "implot.h" #ifndef IMGUI_DISABLE +#include "implot_internal.h" #include #include #include @@ -197,6 +198,59 @@ struct HugeTimeData { static const int Size = 60*60*24*366; }; +//----------------------------------------------------------------------------- +// [SECTION] Numeric Type Gating +//----------------------------------------------------------------------------- + +// A few demos below hardcode their data as a type other than float/double (e.g. ImS8, int). ImPlot +// only instantiates PlotXxx for the types in IMPLOT_NUMERIC_TYPES (see implot_internal.h), which +// can be restricted with IMPLOT_CUSTOM_NUMERIC_TYPES. Calling PlotXxx for an excluded type still +// compiles but fails to link, so those demos are compiled out for it. +// +// A demo that plots data of a type other than float/double must be declared with +// IMPLOT_DEMO_TYPE_GATED (below). + +// Walks IMPLOT_NUMERIC_TYPES, expanding IMPLOT_DEMO_TYPE_MACRO(T) once per listed type. +#define IMPLOT_DEMO_CAT(x, y) IMPLOT_DEMO_CAT_(x, y) +#define IMPLOT_DEMO_CAT_(x, y) x ## y +#define IMPLOT_DEMO_WALK_TYPES(chain) IMPLOT_DEMO_CAT(IMPLOT_DEMO_WALK_TYPES_1 chain, _END) +#define IMPLOT_DEMO_WALK_TYPES_1(T) IMPLOT_DEMO_TYPE_MACRO(T) IMPLOT_DEMO_WALK_TYPES_2 +#define IMPLOT_DEMO_WALK_TYPES_2(T) IMPLOT_DEMO_TYPE_MACRO(T) IMPLOT_DEMO_WALK_TYPES_1 +#define IMPLOT_DEMO_WALK_TYPES_1_END +#define IMPLOT_DEMO_WALK_TYPES_2_END + +namespace Demo { + +// IsTypeEnabled::Value is true iff ImPlot explicitly instantiates PlotXxx. +template struct IsTypeEnabled { enum { Value = 0 }; }; +#define IMPLOT_DEMO_TYPE_MACRO(T) template <> struct IsTypeEnabled { enum { Value = 1 }; }; +IMPLOT_DEMO_WALK_TYPES(IMPLOT_NUMERIC_TYPES) +#undef IMPLOT_DEMO_TYPE_MACRO + +// A tiny local enable_if, so this doesn't need to pull in for its one use below. +template struct EnableIf {}; +template struct EnableIf { typedef T type; }; + +void ShowTypeDisabledNotice() { + ImGui::TextDisabled("(this demo needs a numeric type excluded via IMPLOT_CUSTOM_NUMERIC_TYPES)"); +} + +} // namespace Demo + +// Declares Name() such that exactly one of two bodies is ever compiled for a given T: the one +// written immediately after this macro if T is one of IMPLOT_NUMERIC_TYPES, or an automatic +// fallback that calls ShowTypeDisabledNotice() otherwise. Since the two are separate function +// template overloads selected via SFINAE, the one that doesn't apply to T is never instantiated, +// so it can safely reference PlotXxx without ever actually calling it (and without the linker +// ever looking for a definition of it) when T was excluded via IMPLOT_CUSTOM_NUMERIC_TYPES. +#define IMPLOT_DEMO_TYPE_GATED(Name) \ + template \ + typename Demo::EnableIf::Value>::type Name() { \ + Demo::ShowTypeDisabledNotice(); \ + } \ + template \ + typename Demo::EnableIf::Value>::type Name() + //----------------------------------------------------------------------------- // [SECTION] Demo Functions //----------------------------------------------------------------------------- @@ -541,9 +595,8 @@ void Demo_StairstepPlots() { //----------------------------------------------------------------------------- -void Demo_BarPlots() { - IMGUI_DEMO_MARKER("Plots/Bar Plots"); - static ImS8 data[10] = {1,2,3,4,5,6,7,8,9,10}; +IMPLOT_DEMO_TYPE_GATED(Demo_BarPlots_) { + static T data[10] = {1,2,3,4,5,6,7,8,9,10}; if (ImPlot::BeginPlot("Bar Plot")) { ImPlot::PlotBars("Vertical",data,10,0.7,1); ImPlot::PlotBars("Horizontal",data,10,0.4,1,{ImPlotProp_Flags, ImPlotBarsFlags_Horizontal}); @@ -551,13 +604,17 @@ void Demo_BarPlots() { } } +void Demo_BarPlots() { + IMGUI_DEMO_MARKER("Plots/Bar Plots"); + Demo_BarPlots_(); +} + //----------------------------------------------------------------------------- -void Demo_BarGroups() { - IMGUI_DEMO_MARKER("Plots/Bar Groups"); - static ImS8 data[30] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90, // midterm - 80, 62, 56, 99, 55, 78, 88, 78, 90, 100, // final - 80, 69, 52, 92, 72, 78, 75, 76, 89, 95}; // course +IMPLOT_DEMO_TYPE_GATED(Demo_BarGroups_) { + static T data[30] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90, // midterm + 80, 62, 56, 99, 55, 78, 88, 78, 90, 100, // final + 80, 69, 52, 92, 72, 78, 75, 76, 89, 95}; // course static const char* ilabels[] = {"Midterm Exam","Final Exam","Course Grade"}; static const char* glabels[] = {"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10"}; @@ -593,11 +650,14 @@ void Demo_BarGroups() { } } -//----------------------------------------------------------------------------- +void Demo_BarGroups() { + IMGUI_DEMO_MARKER("Plots/Bar Groups"); + Demo_BarGroups_(); +} -void Demo_BarStacks() { - IMGUI_DEMO_MARKER("Plots/Bar Stacks"); +//----------------------------------------------------------------------------- +IMPLOT_DEMO_TYPE_GATED(Demo_BarStacks_) { static ImPlotColormap Liars = -1; if (Liars == -1) { static const ImU32 Liars_Data[6] = { 4282515870, 4282609140, 4287357182, 4294630301, 4294945280, 4294921472 }; @@ -608,24 +668,24 @@ void Demo_BarStacks() { ImGui::Checkbox("Diverging",&diverging); static const char* politicians[] = {"Trump","Bachman","Cruz","Gingrich","Palin","Santorum","Walker","Perry","Ryan","McCain","Rubio","Romney","Rand Paul","Christie","Biden","Kasich","Sanders","J Bush","H Clinton","Obama"}; - static int data_reg[] = {18,26,7,14,10,8,6,11,4,4,3,8,6,8,6,5,0,3,1,2, // Pants on Fire - 43,36,30,21,30,27,25,17,11,22,15,16,16,17,12,12,14,6,13,12, // False - 16,13,28,22,15,21,15,18,30,17,24,18,13,10,14,15,17,22,14,12, // Mostly False - 17,10,13,25,12,22,19,26,23,17,22,27,20,26,29,17,18,22,21,27, // Half True - 5,7,16,10,10,12,23,13,17,20,22,16,23,19,20,26,36,29,27,26, // Mostly True - 1,8,6,8,23,10,12,15,15,20,14,15,22,20,19,25,15,18,24,21}; // True + static T data_reg[] = {18,26,7,14,10,8,6,11,4,4,3,8,6,8,6,5,0,3,1,2, // Pants on Fire + 43,36,30,21,30,27,25,17,11,22,15,16,16,17,12,12,14,6,13,12, // False + 16,13,28,22,15,21,15,18,30,17,24,18,13,10,14,15,17,22,14,12, // Mostly False + 17,10,13,25,12,22,19,26,23,17,22,27,20,26,29,17,18,22,21,27, // Half True + 5,7,16,10,10,12,23,13,17,20,22,16,23,19,20,26,36,29,27,26, // Mostly True + 1,8,6,8,23,10,12,15,15,20,14,15,22,20,19,25,15,18,24,21}; // True static const char* labels_reg[] = {"Pants on Fire","False","Mostly False","Half True","Mostly True","True"}; - static int data_div[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // Pants on Fire (dummy, to order legend logically) - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // False (dummy, to order legend logically) - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // Mostly False (dummy, to order legend logically) - -16,-13,-28,-22,-15,-21,-15,-18,-30,-17,-24,-18,-13,-10,-14,-15,-17,-22,-14,-12, // Mostly False - -43,-36,-30,-21,-30,-27,-25,-17,-11,-22,-15,-16,-16,-17,-12,-12,-14,-6,-13,-12, // False - -18,-26,-7,-14,-10,-8,-6,-11,-4,-4,-3,-8,-6,-8,-6,-5,0,-3,-1,-2, // Pants on Fire - 17,10,13,25,12,22,19,26,23,17,22,27,20,26,29,17,18,22,21,27, // Half True - 5,7,16,10,10,12,23,13,17,20,22,16,23,19,20,26,36,29,27,26, // Mostly True - 1,8,6,8,23,10,12,15,15,20,14,15,22,20,19,25,15,18,24,21}; // True + static T data_div[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // Pants on Fire (dummy, to order legend logically) + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // False (dummy, to order legend logically) + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // Mostly False (dummy, to order legend logically) + -16,-13,-28,-22,-15,-21,-15,-18,-30,-17,-24,-18,-13,-10,-14,-15,-17,-22,-14,-12, // Mostly False + -43,-36,-30,-21,-30,-27,-25,-17,-11,-22,-15,-16,-16,-17,-12,-12,-14,-6,-13,-12, // False + -18,-26,-7,-14,-10,-8,-6,-11,-4,-4,-3,-8,-6,-8,-6,-5,0,-3,-1,-2, // Pants on Fire + 17,10,13,25,12,22,19,26,23,17,22,27,20,26,29,17,18,22,21,27, // Half True + 5,7,16,10,10,12,23,13,17,20,22,16,23,19,20,26,36,29,27,26, // Mostly True + 1,8,6,8,23,10,12,15,15,20,14,15,22,20,19,25,15,18,24,21}; // True static const char* labels_div[] = {"Pants on Fire","False","Mostly False","Mostly False","False","Pants on Fire","Half True","Mostly True","True"}; ImPlot::PushColormap(Liars); @@ -643,6 +703,11 @@ void Demo_BarStacks() { ImPlot::PopColormap(); } +void Demo_BarStacks() { + IMGUI_DEMO_MARKER("Plots/Bar Stacks"); + Demo_BarStacks_(); +} + //----------------------------------------------------------------------------- void Demo_ErrorBars() { @@ -713,6 +778,29 @@ void Demo_InfiniteLines() { //----------------------------------------------------------------------------- +// Second pie chart's data is an int array (purely to show PlotPieChart() isn't limited to +// float/double); it needs its own type-gated helper since int (ImS32) may have been excluded via +// IMPLOT_CUSTOM_NUMERIC_TYPES. +template +typename Demo::EnableIf::Value>::type +Demo_PieCharts_Pie2(ImPlotPieChartFlags flags) { + static const char* labels2[] = {"A","B","C","D","E"}; + static T data2[] = {1,1,2,3,5}; + ImPlot::PushColormap(ImPlotColormap_Pastel); + if (ImPlot::BeginPlot("##Pie2", ImVec2(ImGui::GetTextLineHeight()*16,ImGui::GetTextLineHeight()*16), ImPlotFlags_Equal | ImPlotFlags_NoMouseText)) { + ImPlot::SetupAxes(nullptr, nullptr, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations); + ImPlot::SetupAxesLimits(0, 1, 0, 1); + ImPlot::PlotPieChart(labels2, data2, 5, 0.5, 0.5, 0.4, "%.0f", 180, {ImPlotProp_Flags, flags}); + ImPlot::EndPlot(); + } + ImPlot::PopColormap(); +} +template +typename Demo::EnableIf::Value>::type +Demo_PieCharts_Pie2(ImPlotPieChartFlags) { + Demo::ShowTypeDisabledNotice(); +} + void Demo_PieCharts() { IMGUI_DEMO_MARKER("Plots/Pie Charts"); static const char* labels1[] = {"Frogs","Hogs","Dogs","Logs"}; @@ -734,17 +822,7 @@ void Demo_PieCharts() { ImGui::SameLine(); - static const char* labels2[] = {"A","B","C","D","E"}; - static int data2[] = {1,1,2,3,5}; - - ImPlot::PushColormap(ImPlotColormap_Pastel); - if (ImPlot::BeginPlot("##Pie2", ImVec2(ImGui::GetTextLineHeight()*16,ImGui::GetTextLineHeight()*16), ImPlotFlags_Equal | ImPlotFlags_NoMouseText)) { - ImPlot::SetupAxes(nullptr, nullptr, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations); - ImPlot::SetupAxesLimits(0, 1, 0, 1); - ImPlot::PlotPieChart(labels2, data2, 5, 0.5, 0.5, 0.4, "%.0f", 180, {ImPlotProp_Flags, flags}); - ImPlot::EndPlot(); - } - ImPlot::PopColormap(); + Demo_PieCharts_Pie2(flags); } //----------------------------------------------------------------------------- @@ -1069,8 +1147,7 @@ void Demo_RealtimePlots() { //----------------------------------------------------------------------------- -void Demo_MarkersAndText() { - IMGUI_DEMO_MARKER("Plots/Markers and Text"); +IMPLOT_DEMO_TYPE_GATED(Demo_MarkersAndText_) { static ImPlotSpec spec(ImPlotProp_Marker, ImPlotMarker_Auto); ImGui::DragFloat("Marker Size",&spec.MarkerSize,0.1f,2.0f,10.0f,"%.2f px"); ImGui::DragFloat("Marker Weight", &spec.LineWeight,0.05f,0.5f,3.0f,"%.2f px"); @@ -1080,8 +1157,8 @@ void Demo_MarkersAndText() { ImPlot::SetupAxes(nullptr, nullptr, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations); ImPlot::SetupAxesLimits(0, 10, -2, 12); - ImS8 xs[2] = {1,4}; - ImS8 ys[2] = {10,11}; + T xs[2] = {1,4}; + T ys[2] = {10,11}; // filled markers for (int m = 0; m < ImPlotMarker_COUNT; ++m) { @@ -1112,6 +1189,11 @@ void Demo_MarkersAndText() { } } +void Demo_MarkersAndText() { + IMGUI_DEMO_MARKER("Plots/Markers and Text"); + Demo_MarkersAndText_(); +} + //----------------------------------------------------------------------------- void Demo_NaNValues() { @@ -1142,6 +1224,37 @@ void Demo_NaNValues() { //----------------------------------------------------------------------------- +// The "Colorful Bar Plots" bit of Demo_PerIndexColors() below plots an ImS8 array purely to show +// that PlotBars() isn't limited to float/double, so it needs its own type-gated helper in case +// ImS8 was excluded via IMPLOT_CUSTOM_NUMERIC_TYPES. +IMPLOT_DEMO_TYPE_GATED(Demo_PerIndexColors_ColorfulBars_) { + static T data_bars[10] = {1,2,3,4,5,6,7,8,9,10}; + static ImU32 colors_bars_v[10], colors_bars_h[10]; + for (int i = 0; i < 10; ++i) { + // Rainbow colors for Vertical + float hue = i / 9.0f; + colors_bars_v[i] = ImColor::HSV(hue, 0.8f, 0.9f); + + // Colormap colors for Horizontal + float t = i / 9.0f; + ImVec4 color = ImPlot::SampleColormap(t, ImPlotColormap_Viridis); + colors_bars_h[i] = ImGui::GetColorU32(color); + } + + if (ImPlot::BeginPlot("Colorful Bar Plot")) { + ImPlot::PlotBars("Vertical", data_bars, 10, 0.7, 1, { + ImPlotProp_FillColors, colors_bars_v, + ImPlotProp_LineColors, colors_bars_v + }); + ImPlot::PlotBars("Horizontal", data_bars, 10, 0.4, 1, { + ImPlotProp_Flags, ImPlotBarsFlags_Horizontal, + ImPlotProp_FillColors, colors_bars_h, + ImPlotProp_LineColors, colors_bars_h + }); + ImPlot::EndPlot(); + } +} + void Demo_PerIndexColors() { // Colorful Lines static float xs1[1001], ys1[1001]; @@ -1358,31 +1471,7 @@ void Demo_PerIndexColors() { } // Colorful Bar Plots - static ImS8 data_bars[10] = {1,2,3,4,5,6,7,8,9,10}; - static ImU32 colors_bars_v[10], colors_bars_h[10]; - for (int i = 0; i < 10; ++i) { - // Rainbow colors for Vertical - float hue = i / 9.0f; - colors_bars_v[i] = ImColor::HSV(hue, 0.8f, 0.9f); - - // Colormap colors for Horizontal - float t = i / 9.0f; - ImVec4 color = ImPlot::SampleColormap(t, ImPlotColormap_Viridis); - colors_bars_h[i] = ImGui::GetColorU32(color); - } - - if (ImPlot::BeginPlot("Colorful Bar Plot")) { - ImPlot::PlotBars("Vertical", data_bars, 10, 0.7, 1, { - ImPlotProp_FillColors, colors_bars_v, - ImPlotProp_LineColors, colors_bars_v - }); - ImPlot::PlotBars("Horizontal", data_bars, 10, 0.4, 1, { - ImPlotProp_Flags, ImPlotBarsFlags_Horizontal, - ImPlotProp_FillColors, colors_bars_h, - ImPlotProp_LineColors, colors_bars_h - }); - ImPlot::EndPlot(); - } + Demo_PerIndexColors_ColorfulBars_(); // Colorful Stem Plots static double xs_stems[51], ys1_stems[51], ys2_stems[51]; @@ -1638,11 +1727,10 @@ void Demo_MultipleAxes() { //----------------------------------------------------------------------------- -void Demo_LinkedAxes() { - IMGUI_DEMO_MARKER("Axes/Linked Axes"); +IMPLOT_DEMO_TYPE_GATED(Demo_LinkedAxes_) { static ImPlotRect lims(0,1,0,1); static bool linkx = true, linky = true; - int data[2] = {0,1}; + T data[2] = {0,1}; ImGui::Checkbox("Link X", &linkx); ImGui::SameLine(); ImGui::Checkbox("Link Y", &linky); @@ -1666,6 +1754,11 @@ void Demo_LinkedAxes() { } } +void Demo_LinkedAxes() { + IMGUI_DEMO_MARKER("Axes/Linked Axes"); + Demo_LinkedAxes_(); +} + //----------------------------------------------------------------------------- void Demo_AxisConstraints() { @@ -2578,6 +2671,19 @@ void Demo_TickLabels() { //----------------------------------------------------------------------------- +// This bit of Demo_CustomStyles() below plots an unsigned int array purely to show that PlotXxx() +// isn't limited to float/double, so it needs its own type-gated helper in case unsigned int +// (ImU32) was excluded via IMPLOT_CUSTOM_NUMERIC_TYPES. +IMPLOT_DEMO_TYPE_GATED(Demo_CustomStyles_SeabornPlots_) { + T lin[10] = {8,8,9,7,8,8,8,9,7,8}; + T bar[10] = {1,2,5,3,4,1,2,5,3,4}; + T dot[10] = {7,6,6,7,8,5,6,5,8,7}; + ImPlot::PlotBars("Bars", bar, 10, 0.5f); + ImPlot::PlotLine("Line", lin, 10); + ImPlot::NextColormapColor(); // skip green + ImPlot::PlotScatter("Scatter", dot, 10); +} + void Demo_CustomStyles() { IMGUI_DEMO_MARKER("Custom/Custom Styles"); ImPlot::PushColormap(ImPlotColormap_Deep); @@ -2587,13 +2693,7 @@ void Demo_CustomStyles() { if (ImPlot::BeginPlot("seaborn style")) { ImPlot::SetupAxes( "x-axis", "y-axis"); ImPlot::SetupAxesLimits(-0.5f, 9.5f, 0, 10); - unsigned int lin[10] = {8,8,9,7,8,8,8,9,7,8}; - unsigned int bar[10] = {1,2,5,3,4,1,2,5,3,4}; - unsigned int dot[10] = {7,6,6,7,8,5,6,5,8,7}; - ImPlot::PlotBars("Bars", bar, 10, 0.5f); - ImPlot::PlotLine("Line", lin, 10); - ImPlot::NextColormapColor(); // skip green - ImPlot::PlotScatter("Scatter", dot, 10); + Demo_CustomStyles_SeabornPlots_(); ImPlot::EndPlot(); } ImPlot::GetStyle() = backup; diff --git a/implot_internal.h b/implot_internal.h index bb1b9ab6..8f92ac01 100644 --- a/implot_internal.h +++ b/implot_internal.h @@ -71,6 +71,32 @@ constexpr int IMPLOT_NUM_Y_AXES = ImAxis_COUNT - IMPLOT_NUM_X_AXES; // [SECTION] Macros //----------------------------------------------------------------------------- +// By default, templates are instantiated for `float`, `double`, and for the following integer types, which are defined in imgui.h: +// signed char ImS8; // 8-bit signed integer +// unsigned char ImU8; // 8-bit unsigned integer +// signed short ImS16; // 16-bit signed integer +// unsigned short ImU16; // 16-bit unsigned integer +// signed int ImS32; // 32-bit signed integer == int +// unsigned int ImU32; // 32-bit unsigned integer +// signed long long ImS64; // 64-bit signed integer +// unsigned long long ImU64; // 64-bit unsigned integer +// (note: this list does *not* include `long`, `unsigned long` and `long double`) +// +// You can customize the supported types by defining IMPLOT_CUSTOM_NUMERIC_TYPES at compile time to define your own type list. +// As an example, you could use the compile time define given by the line below in order to support only float and double. +// -DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)" +// Note that the demo (implot_demo.cpp) plots float and double data, so those two must stay in the list for it to link +// (e.g. "(double)" alone fails with an undefined PlotBars). The define must also reach implot_demo.cpp, not only +// implot_items.cpp (or go in imconfig.h); otherwise the demo falls back to the default list and may fail to link. +// In order to support all known C++ types, use: +// -DIMPLOT_CUSTOM_NUMERIC_TYPES="(signed char)(unsigned char)(signed short)(unsigned short)(signed int)(unsigned int)(signed long)(unsigned long)(signed long long)(unsigned long long)(float)(double)(long double)" + +#ifdef IMPLOT_CUSTOM_NUMERIC_TYPES + #define IMPLOT_NUMERIC_TYPES IMPLOT_CUSTOM_NUMERIC_TYPES +#else + #define IMPLOT_NUMERIC_TYPES (ImS8)(ImU8)(ImS16)(ImU16)(ImS32)(ImU32)(ImS64)(ImU64)(float)(double) +#endif + // Split ImU32 color into RGB components [0 255] #define IM_COL32_SPLIT_RGB(col,r,g,b) \ ImU32 r = ((col >> IM_COL32_R_SHIFT) & 0xFF); \ diff --git a/implot_items.cpp b/implot_items.cpp index 1c1fa709..df6fbbc4 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -75,28 +75,7 @@ static IMPLOT_INLINE float ImInvSqrt(float x) { return 1.0f / sqrtf(x); } // [SECTION] Template instantiation utility //----------------------------------------------------------------------------- -// By default, templates are instantiated for `float`, `double`, and for the following integer types, which are defined in imgui.h: -// signed char ImS8; // 8-bit signed integer -// unsigned char ImU8; // 8-bit unsigned integer -// signed short ImS16; // 16-bit signed integer -// unsigned short ImU16; // 16-bit unsigned integer -// signed int ImS32; // 32-bit signed integer == int -// unsigned int ImU32; // 32-bit unsigned integer -// signed long long ImS64; // 64-bit signed integer -// unsigned long long ImU64; // 64-bit unsigned integer -// (note: this list does *not* include `long`, `unsigned long` and `long double`) -// -// You can customize the supported types by defining IMPLOT_CUSTOM_NUMERIC_TYPES at compile time to define your own type list. -// As an example, you could use the compile time define given by the line below in order to support only float and double. -// -DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)" -// In order to support all known C++ types, use: -// -DIMPLOT_CUSTOM_NUMERIC_TYPES="(signed char)(unsigned char)(signed short)(unsigned short)(signed int)(unsigned int)(signed long)(unsigned long)(signed long long)(unsigned long long)(float)(double)(long double)" - -#ifdef IMPLOT_CUSTOM_NUMERIC_TYPES - #define IMPLOT_NUMERIC_TYPES IMPLOT_CUSTOM_NUMERIC_TYPES -#else - #define IMPLOT_NUMERIC_TYPES (ImS8)(ImU8)(ImS16)(ImU16)(ImS32)(ImU32)(ImS64)(ImU64)(float)(double) -#endif +// The list of supported types, IMPLOT_NUMERIC_TYPES, is defined in implot_internal.h. // CALL_INSTANTIATE_FOR_NUMERIC_TYPES will duplicate the template instantiation code `INSTANTIATE_MACRO(T)` on supported types. #define _CAT(x, y) _CAT_(x, y)