diff --git a/implot.cpp b/implot.cpp index d9260281..c53b8876 100644 --- a/implot.cpp +++ b/implot.cpp @@ -670,9 +670,54 @@ bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool hov ? false : ImGui::ButtonBehavior(button_bb, item->ID, &item_hov, &item_hld); - if (item_clk) - item->Show = !item->Show; + if (item_clk) { + ImGuiIO& IO = ImGui::GetIO(); + if (IO.KeyCtrl && IO.KeyShift) { + // select all items + for (int j = 0; j < num_items; ++j) { + ImPlotItem* item_j = items.GetLegendItem(indices[j]); + item_j->Show = true; + } + } + else if (IO.KeyCtrl) { + // select the item and deselect all others + for (int j = 0; j < num_items; ++j) { + ImPlotItem* item_j = items.GetLegendItem(indices[j]); + if (item_j->Show) { + item_j->Show = false; + } + } + item->Show = true; + } + else { + // select/deselect the item + item->Show = !item->Show; + } + } + else { + // multiple selection + static bool selecting_multiple_items = false; + if (item_hov) { + selecting_multiple_items = true; + } + + if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { + selecting_multiple_items = false; + } + + if (selecting_multiple_items && + ImGui::IsMouseDown(ImGuiMouseButton_Left) && + ImGui::IsMouseHoveringRect(button_bb.Min, button_bb.Max)) { + ImGuiIO& IO = ImGui::GetIO(); + if (IO.KeyCtrl) { + item->Show = true; + } + else if (IO.KeyAlt) { + item->Show = false; + } + } + } const bool can_hover = (item_hov) && (!ImHasFlag(items.Legend.Flags, ImPlotLegendFlags_NoHighlightItem)