| 351 | } |
| 352 | |
| 353 | void ShowLegendEntries(ImPlot3DItemGroup& items, const ImRect& legend_bb, const ImVec2& pad, const ImVec2& spacing, bool vertical, |
| 354 | ImDrawList& draw_list) { |
| 355 | const float txt_ht = ImGui::GetTextLineHeight(); |
| 356 | const float icon_size = txt_ht; |
| 357 | const float icon_shrink = 2; |
| 358 | ImU32 col_txt = GetStyleColorU32(ImPlot3DCol_LegendText); |
| 359 | ImU32 col_txt_dis = ImAlphaU32(col_txt, 0.25f); |
| 360 | float sum_label_width = 0; |
| 361 | |
| 362 | const int num_items = items.GetLegendCount(); |
| 363 | if (num_items == 0) |
| 364 | return; |
| 365 | |
| 366 | // Render legend items |
| 367 | for (int i = 0; i < num_items; i++) { |
| 368 | const int idx = i; |
| 369 | ImPlot3DItem* item = items.GetLegendItem(idx); |
| 370 | const char* label = items.GetLegendLabel(idx); |
| 371 | const float label_width = ImGui::CalcTextSize(label, nullptr, true).x; |
| 372 | const ImVec2 top_left = vertical ? legend_bb.Min + pad + ImVec2(0, i * (txt_ht + spacing.y)) |
| 373 | : legend_bb.Min + pad + ImVec2(i * (icon_size + spacing.x) + sum_label_width, 0); |
| 374 | sum_label_width += label_width; |
| 375 | ImRect icon_bb; |
| 376 | icon_bb.Min = top_left + ImVec2(icon_shrink, icon_shrink); |
| 377 | icon_bb.Max = top_left + ImVec2(icon_size - icon_shrink, icon_size - icon_shrink); |
| 378 | ImRect label_bb; |
| 379 | label_bb.Min = top_left; |
| 380 | label_bb.Max = top_left + ImVec2(label_width + icon_size, icon_size); |
| 381 | ImU32 col_txt_hl; |
| 382 | ImU32 col_item = ImAlphaU32(item->Color, 1); |
| 383 | |
| 384 | ImRect button_bb(icon_bb.Min, label_bb.Max); |
| 385 | |
| 386 | ImGui::KeepAliveID(item->ID); |
| 387 | |
| 388 | bool item_hov = false; |
| 389 | bool item_hld = false; |
| 390 | bool item_clk = ImPlot3D::ImHasFlag(items.Legend.Flags, ImPlot3DLegendFlags_NoButtons) |
| 391 | ? false |
| 392 | : ImGui::ButtonBehavior(button_bb, item->ID, &item_hov, &item_hld); |
| 393 | |
| 394 | if (item_clk) |
| 395 | item->Show = !item->Show; |
| 396 | |
| 397 | const bool hovering = item_hov && !ImPlot3D::ImHasFlag(items.Legend.Flags, ImPlot3DLegendFlags_NoHighlightItem); |
| 398 | |
| 399 | if (hovering) { |
| 400 | item->LegendHovered = true; |
| 401 | col_txt_hl = ImPlot3D::ImMixU32(col_txt, col_item, 64); |
| 402 | } else { |
| 403 | item->LegendHovered = false; |
| 404 | col_txt_hl = ImGui::GetColorU32(col_txt); |
| 405 | } |
| 406 | |
| 407 | ImU32 col_icon; |
| 408 | if (item_hld) |
| 409 | col_icon = item->Show ? ImAlphaU32(col_item, 0.5f) : ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.5f); |
| 410 | else if (item_hov) |
no test coverage detected