1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-23 02:38:53 -05: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,12 +1860,15 @@ void PlotErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx),
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()!");
ImDrawList & DrawList = *ImGui::GetWindowDrawList();
PushClipRect(gp.BB_Grid.Min, gp.BB_Grid.Max, true);
ImVec2 pos = gp.ToPixels({x,y}) + pixel_offset;
DrawList.AddText(pos, gp.Col_Txt, text);
if (vertical)
AddTextVertical(&DrawList, text, pos, gp.Col_Txt);
else
DrawList.AddText(pos, gp.Col_Txt, text);
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, ImVec4 (*getter)(void* data, int idx), void* data, int count, int offset = 0);
// 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

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);
if (ImGui::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,300), 0, 0, 0)) {
float xs[2] = {1,4};
@ -281,6 +281,10 @@ void ShowImPlotDemoWindow(bool* p_open) {
ImGui::PopPlotStyleVar(4);
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();
}
}