mirror of
https://github.com/ocornut/imgui.git
synced 2025-01-19 09:37:30 +01:00
MultiSelect: Box-Select: fixed "when dragging from void" implementation messing with calling BeginMultiSelect() without a selection size.
This commit is contained in:
parent
81548cb6bf
commit
1113f13f83
@ -7529,7 +7529,7 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected, ImGuiButtonFlags
|
|||||||
ImGuiSelectionUserData item_data = g.NextItemData.SelectionUserData;
|
ImGuiSelectionUserData item_data = g.NextItemData.SelectionUserData;
|
||||||
IM_ASSERT(g.NextItemData.FocusScopeId == g.CurrentFocusScopeId && "Forgot to call SetNextItemSelectionUserData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope");
|
IM_ASSERT(g.NextItemData.FocusScopeId == g.CurrentFocusScopeId && "Forgot to call SetNextItemSelectionUserData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope");
|
||||||
|
|
||||||
// Apply SetAll (Clear/SelectAll )requests requested by BeginMultiSelect().
|
// Apply SetAll (Clear/SelectAll) requests requested by BeginMultiSelect().
|
||||||
// This is only useful if the user hasn't processed them already, and this only works if the user isn't using the clipper.
|
// This is only useful if the user hasn't processed them already, and this only works if the user isn't using the clipper.
|
||||||
// If you are using a clipper you need to process the SetAll request after calling BeginMultiSelect()
|
// If you are using a clipper you need to process the SetAll request after calling BeginMultiSelect()
|
||||||
if (ms->LoopRequestSetAll != -1)
|
if (ms->LoopRequestSetAll != -1)
|
||||||
@ -7654,17 +7654,22 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
|
|||||||
const bool rect_overlap_curr = bs->BoxSelectRectCurr.Overlaps(g.LastItemData.Rect);
|
const bool rect_overlap_curr = bs->BoxSelectRectCurr.Overlaps(g.LastItemData.Rect);
|
||||||
const bool rect_overlap_prev = bs->BoxSelectRectPrev.Overlaps(g.LastItemData.Rect);
|
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 ((rect_overlap_curr && !rect_overlap_prev && !selected) || (rect_overlap_prev && !rect_overlap_curr))
|
||||||
|
{
|
||||||
|
if (storage->LastSelectionSize <= 0 && bs->IsStartedFromVoid)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
selected = !selected;
|
selected = !selected;
|
||||||
ImGuiSelectionRequest req = { ImGuiSelectionRequestType_SetRange, selected, item_data, item_data };
|
ImGuiSelectionRequest req = { ImGuiSelectionRequestType_SetRange, selected, item_data, item_data };
|
||||||
ImGuiSelectionRequest* prev_req = (ms->IO.Requests.Size > 0) ? &ms->IO.Requests.Data[ms->IO.Requests.Size - 1] : NULL;
|
ImGuiSelectionRequest* prev_req = (ms->IO.Requests.Size > 0) ? &ms->IO.Requests.Data[ms->IO.Requests.Size - 1] : NULL;
|
||||||
if (storage->LastSelectionSize == 0 && bs->IsStartedFromVoid)
|
if (prev_req && prev_req->Type == ImGuiSelectionRequestType_SetRange && prev_req->RangeLastItem == ms->BoxSelectLastitem && prev_req->Selected == selected)
|
||||||
pressed = true; // First item act as a pressed: code below will emit selection request and set NavId (whatever we emit here will be overriden anyway)
|
|
||||||
else if (prev_req && prev_req->Type == ImGuiSelectionRequestType_SetRange && prev_req->RangeLastItem == ms->BoxSelectLastitem && prev_req->Selected == selected)
|
|
||||||
prev_req->RangeLastItem = item_data; // Merge span into same request
|
prev_req->RangeLastItem = item_data; // Merge span into same request
|
||||||
else
|
else
|
||||||
ms->IO.Requests.push_back(req);
|
ms->IO.Requests.push_back(req);
|
||||||
storage->LastSelectionSize++;
|
}
|
||||||
|
storage->LastSelectionSize = ImMax(storage->LastSelectionSize + 1, 1);
|
||||||
}
|
}
|
||||||
ms->BoxSelectLastitem = item_data;
|
ms->BoxSelectLastitem = item_data;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user