RangeSelect/MultiSelect: Fix testing key mods from after the nav request (remove need to hold the mod longer)

features/range_select
omar ago%!(EXTRA string=5 years) committed by ocornut
parent b295efc68f
commit 25f49eaf42
  1. 2
      imgui_internal.h
  2. 15
      imgui_widgets.cpp

@ -2116,6 +2116,7 @@ struct ImGuiContext
bool MultiSelectEnabled;
ImGuiMultiSelectFlags MultiSelectFlags;
ImGuiMultiSelectState MultiSelectState; // We currently don't support recursing/stacking multi-select
ImGuiKeyChord MultiSelectKeyMods;
// Render
float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list)
@ -2376,6 +2377,7 @@ struct ImGuiContext
MultiSelectEnabled = false;
MultiSelectFlags = ImGuiMultiSelectFlags_None;
MultiSelectKeyMods = ImGuiMod_None;
DimBgRatio = 0.0f;

@ -7021,6 +7021,9 @@ ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void*
g.MultiSelectEnabled = true;
g.MultiSelectFlags = flags;
// Use copy of keyboard mods at the time of the request, otherwise we would requires mods to be held for an extra frame.
g.MultiSelectKeyMods = g.NavJustMovedToId ? g.NavJustMovedToKeyMods : g.IO.KeyMods;
if ((flags & ImGuiMultiSelectFlags_NoMultiSelect) == 0)
{
ms->In.RangeSrc = ms->Out.RangeSrc = range_ref;
@ -7031,9 +7034,9 @@ ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void*
// FIXME: Polling key mods after the fact (frame following the move request) is incorrect, but latching it would requires non-trivial change in MultiSelectItemFooter()
if (g.NavJustMovedToId != 0 && g.NavJustMovedToFocusScopeId == ms->FocusScopeId && g.NavJustMovedToHasSelectionData)
{
if (g.IO.KeyShift)
if (g.MultiSelectKeyMods & ImGuiMod_Shift)
ms->InRequestSetRangeNav = true;
if (!g.IO.KeyCtrl && !g.IO.KeyShift)
if ((g.MultiSelectKeyMods & (ImGuiMod_Ctrl | ImGuiMod_Shift)) == 0)
ms->In.RequestClear = true;
}
@ -7116,13 +7119,13 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected)
if (ms->InRequestSetRangeNav)
{
IM_ASSERT(id != 0);
IM_ASSERT(g.IO.KeyShift);
IM_ASSERT((g.MultiSelectKeyMods & ImGuiMod_Shift) != 0);
const bool is_range_dst = !ms->InRangeDstPassedBy && g.NavJustMovedToId == id; // Assume that g.NavJustMovedToId is not clipped.
if (is_range_dst)
ms->InRangeDstPassedBy = true;
if (is_range_src || is_range_dst || ms->In.RangeSrcPassedBy != ms->InRangeDstPassedBy)
selected = ms->In.RangeValue;
else if (!g.IO.KeyCtrl)
else if ((g.MultiSelectKeyMods & ImGuiMod_Ctrl) == 0)
selected = false;
}
@ -7139,9 +7142,9 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
bool selected = *p_selected;
bool pressed = *p_pressed;
bool is_ctrl = g.IO.KeyCtrl;
bool is_shift = g.IO.KeyShift;
const bool is_multiselect = (g.MultiSelectFlags & ImGuiMultiSelectFlags_NoMultiSelect) == 0;
bool is_ctrl = (g.MultiSelectKeyMods & ImGuiMod_Ctrl) != 0;
bool is_shift = (g.MultiSelectKeyMods & ImGuiMod_Shift) != 0;
// Auto-select as you navigate a list
if (g.NavJustMovedToId == id)

Loading…
Cancel
Save