| 612 | } |
| 613 | |
| 614 | ImVec2 CalcLegendSize(ImPlotItemGroup& items, const ImVec2& pad, const ImVec2& spacing, bool vertical) { |
| 615 | // vars |
| 616 | const int nItems = items.GetLegendCount(); |
| 617 | const float txt_ht = ImGui::GetTextLineHeight(); |
| 618 | const float icon_size = txt_ht; |
| 619 | // get label max width |
| 620 | float max_label_width = 0; |
| 621 | float sum_label_width = 0; |
| 622 | for (int i = 0; i < nItems; ++i) { |
| 623 | const char* label = items.GetLegendLabel(i); |
| 624 | const float label_width = ImGui::CalcTextSize(label, nullptr, true).x; |
| 625 | max_label_width = label_width > max_label_width ? label_width : max_label_width; |
| 626 | sum_label_width += label_width; |
| 627 | } |
| 628 | // calc legend size |
| 629 | const ImVec2 legend_size = vertical ? |
| 630 | ImVec2(pad.x * 2 + icon_size + max_label_width, pad.y * 2 + nItems * txt_ht + (nItems - 1) * spacing.y) : |
| 631 | ImVec2(pad.x * 2 + icon_size * nItems + sum_label_width + (nItems - 1) * spacing.x, pad.y * 2 + txt_ht); |
| 632 | return legend_size; |
| 633 | } |
| 634 | |
| 635 | bool ClampLegendRect(ImRect& legend_rect, const ImRect& outer_rect, const ImVec2& pad) { |
| 636 | bool clamped = false; |
no test coverage detected