Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rapid Plot Legend Item Selection #551

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down