-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add SetNextColorsData to give per point colors #332
base: master
Are you sure you want to change the base?
Conversation
First, this is amazing work! Thank you for opening this PR
We should discuss this in the context of the proposal in #330. It's likely in the near future that we lump styling parameters in the
I plan to eleminate the ImGui fallback implementation in #319 -- it only exists to provide an AA option for line plot (at some point we will add back AA via |
Scanning the code, the first idea that jumps out to me is possibly putting color indexing/getting into the existing I'm curious how this should behave for Also, I think this would also need to honor |
Thanks for the feedback. I will wait with attention the new API. |
Implementation and demo for lines, scatter, infinite lines, shaded plots and stairstep
Hello,
I needed to have color per point for lines and markers so I developed the feature .
This request has already been discuted here :
#298
#321 (comment)
The patch add only one function allowing to override the color used for the data:
// Set color buffer for the next item only. The colors array must be keep alive until the next item plot.
IMPLOT_API void SetNextColorsData(ImPlotCol_ target, ImU32* const& colors, int stride = sizeof(ImU32));
I know you are not convinced by the need of implicit lifetime management of the color pointer but with 2 calls there is not lot of option without data copy.
As the SetNextColorsData call is often done just before the plot call this liftime management is not so dangerous for most developers. If you find it too dangerous, it could be moved in implot_internal.h
The internal implementation mainly replace some "ImU32 col" by some "const ImU32* col_ptr, int col_stride" parameter. This allow to use a stride of 0 to support easily the legacy behavior with the Style color in the same code path.
I tested and added demo for lines, scatter, VLines and HLines but it should work for other plots.
For the line plot, the color of the first point is used for the the whole line instead of a gradient between the both point color. This is because the AddLine of the ImGui API take only 1 color even if deep inside the draw API, in ImDrawList::AddPolyline, 2 different color could have been provided leading to a gradient in most renderers:
for (int i = 0; i < points_count; i++)
{
_VtxWritePtr[0].pos = temp_points[i * 2 + 0]; _VtxWritePtr[0].uv = tex_uv0; _VtxWritePtr[0].col = col; // Left-side outer edge
_VtxWritePtr[1].pos = temp_points[i * 2 + 1]; _VtxWritePtr[1].uv = tex_uv1; _VtxWritePtr[1].col = col; // Right-side outer edge
_VtxWritePtr += 2;
}
If you have better idea of API or implementation, i can rework the patch, or improve the demo if needed. As the patch modify the internal API of implot, it will be a lot easier to keep sync with the feature directly in the upstream.
Thanks !
Frédéric