1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 23:57:26 -04:00

add vertical labels and updated demo with example

This commit is contained in:
Evan Pezent 2020-04-28 01:06:43 -05:00
parent 50f4e94833
commit 128d52dbf6
3 changed files with 11 additions and 4 deletions

View File

@ -1860,11 +1860,14 @@ void PlotErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx),
PopClipRect(); PopClipRect();
} }
void PlotLabel(const char* text, float x, float y, const ImVec2& pixel_offset) { void PlotLabel(const char* text, float x, float y, bool vertical, const ImVec2& pixel_offset) {
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotLabel() Needs to be called between BeginPlot() and EndPlot()!"); IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotLabel() Needs to be called between BeginPlot() and EndPlot()!");
ImDrawList & DrawList = *ImGui::GetWindowDrawList(); ImDrawList & DrawList = *ImGui::GetWindowDrawList();
PushClipRect(gp.BB_Grid.Min, gp.BB_Grid.Max, true); PushClipRect(gp.BB_Grid.Min, gp.BB_Grid.Max, true);
ImVec2 pos = gp.ToPixels({x,y}) + pixel_offset; ImVec2 pos = gp.ToPixels({x,y}) + pixel_offset;
if (vertical)
AddTextVertical(&DrawList, text, pos, gp.Col_Txt);
else
DrawList.AddText(pos, gp.Col_Txt, text); DrawList.AddText(pos, gp.Col_Txt, text);
PopClipRect(); PopClipRect();
} }

View File

@ -189,7 +189,7 @@ void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const
void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float)); void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float));
void PlotErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx), void* data, int count, int offset = 0); void PlotErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx), void* data, int count, int offset = 0);
// Plots a text label at point x,y. // Plots a text label at point x,y.
void PlotLabel(const char* text, float x, float y, const ImVec2& pixel_offset = ImVec2(0,0)); void PlotLabel(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0));
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Plot Styling // Plot Styling

View File

@ -213,7 +213,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Marker Styles")) { if (ImGui::CollapsingHeader("Markers and Labels")) {
ImGui::SetNextPlotRange(0, 10, 0, 12); ImGui::SetNextPlotRange(0, 10, 0, 12);
if (ImGui::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,300), 0, 0, 0)) { if (ImGui::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,300), 0, 0, 0)) {
float xs[2] = {1,4}; float xs[2] = {1,4};
@ -281,6 +281,10 @@ void ShowImPlotDemoWindow(bool* p_open) {
ImGui::PopPlotStyleVar(4); ImGui::PopPlotStyleVar(4);
ImGui::PopPlotColor(3); ImGui::PopPlotColor(3);
ImGui::PlotLabel("Filled Markers", 1.5, 11.75);
ImGui::PlotLabel("Open Markers", 6.75, 11.75);
ImGui::PlotLabel("Fancy Markers", 4.5, 4.25, true);
ImGui::EndPlot(); ImGui::EndPlot();
} }
} }