Skip to content

Commit

Permalink
MultiSelect: BoxSelect: fixed box-select from void setting nav id mul…
Browse files Browse the repository at this point in the history
…tiple times.
  • Loading branch information
ocornut committed Jul 25, 2024
1 parent 237165a commit ed356dc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,7 @@ struct ImGuiBoxSelectState
bool IsActive;
bool IsStarting;
bool IsStartedFromVoid; // Starting click was not from an item.
bool IsStartedSetNavIdOnce;
bool RequestClear;
ImGuiKeyChord KeyMods : 16; // Latched key-mods for box-select logic.
ImVec2 StartPosRel; // Start position in window-contents relative space (to support scrolling)
Expand Down
4 changes: 3 additions & 1 deletion imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7161,6 +7161,7 @@ static void BoxSelectPreStartDrag(ImGuiID id, ImGuiSelectionUserData clicked_ite
bs->ID = id;
bs->IsStarting = true; // Consider starting box-select.
bs->IsStartedFromVoid = (clicked_item == ImGuiSelectionUserData_Invalid);
bs->IsStartedSetNavIdOnce = bs->IsStartedFromVoid;
bs->KeyMods = g.IO.KeyMods;
bs->StartPosRel = bs->EndPosRel = ImGui::WindowPosAbsToRel(g.CurrentWindow, g.IO.MousePos);
bs->ScrollAccum = ImVec2(0.0f, 0.0f);
Expand Down Expand Up @@ -7682,9 +7683,10 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
const bool rect_overlap_prev = bs->BoxSelectRectPrev.Overlaps(g.LastItemData.Rect);
if ((rect_overlap_curr && !rect_overlap_prev && !selected) || (rect_overlap_prev && !rect_overlap_curr))
{
if (storage->LastSelectionSize <= 0 && bs->IsStartedFromVoid)
if (storage->LastSelectionSize <= 0 && bs->IsStartedSetNavIdOnce)
{
pressed = true; // First item act as a pressed: code below will emit selection request and set NavId (whatever we emit here will be overridden anyway)
bs->IsStartedSetNavIdOnce = false;
}
else
{
Expand Down

0 comments on commit ed356dc

Please sign in to comment.