MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / CalcLegendSize

Function CalcLegendSize

Source/3rdParty/implot/implot.cpp:614–633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

612}
613
614ImVec2 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
635bool ClampLegendRect(ImRect& legend_rect, const ImRect& outer_rect, const ImVec2& pad) {
636 bool clamped = false;

Callers 5

SetupFinishFunction · 0.85
EndPlotFunction · 0.85
BeginSubplotsFunction · 0.85
EndSubplotsFunction · 0.85
ShowAltLegendFunction · 0.85

Calls 3

ImVec2Function · 0.85
GetLegendCountMethod · 0.80
GetLegendLabelMethod · 0.80

Tested by

no test coverage detected