Repository navigation
fix: demo no longer links an excluded type when IMPLOT_CUSTOM_NUMERIC_TYPES is restricted - #726
Merged
Merged
Conversation
…_TYPES is restricted A handful of demos (Bar Plots, Bar Groups, Bar Stacks, the second Pie Chart, Markers and Text, the "Colorful Bar Plots" bit of Per-Index Colors, Linked Axes, and the Seaborn style bit of Custom Styles) hardcode their plot data as ImS8, int or unsigned int just to show that PlotXxx() isn't limited to float/double. Since ImPlot only explicitly instantiates PlotXxx<T> for the types listed in IMPLOT_NUMERIC_TYPES, building with -DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)" (as suggested in implot.h's own docs for shrinking the binary) made these calls fail to link with undefined references, even though they compiled fine. Rather than silently swapping each demo's data to a fallback type, which would be confusing in its own way, this mirrors the numeric type list inside implot_demo.cpp and uses it to gate those specific snippets at compile time: a small SFINAE helper picks between the real snippet and a one-line "type excluded" notice depending on whether the hardcoded type is actually instantiated, so the excluded overload never references the unavailable PlotXxx<T> and the linker never looks for it. The default type list is untouched, so normal builds keep calling the exact same code they always did.
The IMPLOT_NUMERIC_TYPES definition (IMPLOT_CUSTOM_NUMERIC_TYPES if set, otherwise the ten default types), with its explanatory comment, moves from implot_items.cpp into implot_internal.h so the library and the demo read the same list. The demo's gating helpers now walk IMPLOT_NUMERIC_TYPES directly instead of keeping their own copy of the list that had to stay in sync by hand, and implot_demo.cpp includes implot_internal.h at the top for it.
Every existing CI job builds with the "all types" list, so nothing noticed when a demo needed a type that a restricted list leaves out. Add a Linux job that builds and runs example_implot with -DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)". A demo that plots non-float/double data and is not declared with IMPLOT_DEMO_TYPE_GATED now fails to link in this job.
brenocq
force-pushed
the
fix/custom-numeric-types-demo-link
branch
from
October 25, 2026 07:52
98d696b to
f694fdd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #715
Building the example with a restricted
IMPLOT_CUSTOM_NUMERIC_TYPES, e.g.-DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)"(the wayimplot.hsuggests for shrinking the binary), compilesimplot_demo.cppbut then fails to link. A few demos hardcode their data asImS8,intorunsigned intto show thatPlotXxx()is not limited to float/double, and ImPlot only instantiatesPlotXxx<T>for the types inIMPLOT_NUMERIC_TYPES:This PR makes the demo gate those snippets at compile time. The type list (
IMPLOT_CUSTOM_NUMERIC_TYPESif defined, otherwise all ten types) is defined once asIMPLOT_NUMERIC_TYPESinimplot_internal.h, moved there fromimplot_items.cpp.implot_demo.cppgets a small "Numeric Type Gating" section that reads it, and anIMPLOT_DEMO_TYPE_GATED(Name)macro. It declaresName<T>()as two SFINAE overloads: the real body whenTis enabled, and a one-line notice when it is not. The disabled overload never referencesPlotXxx<T>, so the linker never looks for it. The affected demos are Bar Plots, Bar Groups, Bar Stacks, the second Pie Chart, Markers and Text, Colorful Bars (Per-Index Colors), Linked Axes and the Seaborn style (Custom Styles). The list is also documented next to its definition, noting that the define must reachimplot_demo.cpptoo and that the demo needsfloatanddoublein it. A new Linux CI job builds and runsexample_implotwith(float)(double), so a demo that needs another type without being gated now fails to link there. With the default type list nothing changes: each demo calls the same code with the same type as before.Before:
After:
When the type is excluded, the demo shows:
Tested by building
example/against ImGui v1.93.0 with(float)(double)(fails to link before this change, links after) and with the default types (unchanged).Bar Plots, the second Pie Chart and Linked Axes, in the default build and with
(float)(double):(float)(double)