1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-24 07:40:22 +01:00

MultiSelect: Fixed needing to set RangeSrcPassedBy when not using clipper.

This commit is contained in:
ocornut 2023-04-12 22:14:32 +02:00
parent 78cb1661cb
commit 815c61b82e
2 changed files with 5 additions and 8 deletions

View File

@ -2881,10 +2881,6 @@ static void ShowDemoWindowMultiSelect()
for (int n = 0; n < ITEMS_COUNT; n++) for (int n = 0; n < ITEMS_COUNT; n++)
{ {
// FIXME-MULTISELECT: This should not be needed but currently is because coarse clipping break the auto-setup.
if (n > selection.RangeRef)
multi_select_data->RangeSrcPassedBy = true;
char label[64]; char label[64];
sprintf(label, "Object %05d: %s", n, random_names[n % IM_ARRAYSIZE(random_names)]); sprintf(label, "Object %05d: %s", n, random_names[n % IM_ARRAYSIZE(random_names)]);

View File

@ -7218,6 +7218,10 @@ void ImGui::SetNextItemSelectionUserData(ImGuiSelectionUserData selection_user_d
g.NextItemData.ItemFlags |= ImGuiItemFlags_HasSelectionUserData; g.NextItemData.ItemFlags |= ImGuiItemFlags_HasSelectionUserData;
g.NextItemData.SelectionUserData = selection_user_data; g.NextItemData.SelectionUserData = selection_user_data;
g.NextItemData.FocusScopeId = g.CurrentFocusScopeId; g.NextItemData.FocusScopeId = g.CurrentFocusScopeId;
// Auto updating RangeSrcPassedBy for cases were clipped is not used.
if (g.MultiSelectState.In.RangeSrc == (void*)selection_user_data)
g.MultiSelectState.In.RangeSrcPassedBy = true;
} }
void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected) void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected)
@ -7240,16 +7244,13 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected)
else if (ms->In.RequestSelectAll) else if (ms->In.RequestSelectAll)
selected = true; selected = true;
const bool is_range_src = (ms->In.RangeSrc == item_data);
if (is_range_src)
ms->In.RangeSrcPassedBy = true; // FIXME-MULTISELECT: The promise that this would be automatically done is not because of ItemAdd() clipping.
// When using SHIFT+Nav: because it can incur scrolling we cannot afford a frame of lag with the selection highlight (otherwise scrolling would happen before selection) // When using SHIFT+Nav: because it can incur scrolling we cannot afford a frame of lag with the selection highlight (otherwise scrolling would happen before selection)
// For this to work, IF the user is clipping items, they need to set RangeSrcPassedBy = true to notify the system. // For this to work, IF the user is clipping items, they need to set RangeSrcPassedBy = true to notify the system.
if (ms->InRequestSetRangeNav) if (ms->InRequestSetRangeNav)
{ {
IM_ASSERT(id != 0); IM_ASSERT(id != 0);
IM_ASSERT((ms->KeyMods & ImGuiMod_Shift) != 0); IM_ASSERT((ms->KeyMods & ImGuiMod_Shift) != 0);
const bool is_range_src = (ms->In.RangeSrc == item_data);
const bool is_range_dst = !ms->InRangeDstPassedBy && g.NavJustMovedToId == id; // Assume that g.NavJustMovedToId is not clipped. const bool is_range_dst = !ms->InRangeDstPassedBy && g.NavJustMovedToId == id; // Assume that g.NavJustMovedToId is not clipped.
if (is_range_dst) if (is_range_dst)
ms->InRangeDstPassedBy = true; ms->InRangeDstPassedBy = true;