Inputs: changed specs of SetKeyOwner() to alter OwnerCurr immediately.

Note the removed comments (hence not squashing)
Amend 4448d97
(#456, #2637, #2620, #2891, #3370,, #4828, #5108, #5242, #5641)
This commit is contained in:
ocornut 2022-09-20 18:58:08 +02:00
parent 4448d975d1
commit 8c95c084cb

View File

@ -8370,17 +8370,9 @@ bool ImGui::TestKeyOwner(ImGuiKey key, ImGuiID owner_id)
if (owner_id == ImGuiKeyOwner_Any) if (owner_id == ImGuiKeyOwner_Any)
return (owner_data->LockThisFrame == false); return (owner_data->LockThisFrame == false);
// FIXME: For consistency with routing may be good to disable that, OR we could differentiate preemptive routing from setting owner on click. // Note: SetKeyOwner() sets OwnerCurr. It is not strictly required for most mouse routing overlap (because of ActiveId/HoveredId
// For now it is better to disable so we can actually get report of case where this may matter. // are acting as filter before this has a chance to filter), but sane as soon as user tries to look into things.
// -> Better to move in the SetKeyOwner() call, aka have a flag to set ->OwnerCurr in SetKeyOwner() ? // Setting OwnerCurr in SetKeyOwner() is more consistent than testing OwnerNext here: would be inconsistent with getter and other functions.
// May simply be inconsistent and unneeded to offer that feature:
// - for typical keyboard/gamepad routing with multiple claims and ServeLast, we don't want to affect owner testing during the frame.
// - for typical mouse routing overlap + hovered window generally prevents making it useful to alter owner testing during the frame.
// - but effectively Locked flag can alter same-frame behavior.
//// We want OwnerNext to be handled immediately so SetKeyOwner(key, id1), TestKeyOwner(key, id2) == false
//if (owner_data->OwnerNext != ImGuiKeyOwner_None && owner_data->OwnerNext != owner)
// return false;
if (owner_data->OwnerCurr != owner_id) if (owner_data->OwnerCurr != owner_id)
{ {
if (owner_data->LockThisFrame) if (owner_data->LockThisFrame)
@ -8392,6 +8384,7 @@ bool ImGui::TestKeyOwner(ImGuiKey key, ImGuiID owner_id)
return true; return true;
} }
// _LockXXX flags are useful to lock keys away from code which is not input-owner aware.
// When using _LockXXX flags, you can use ImGuiKeyOwner_Any to lock keys from everyone. // When using _LockXXX flags, you can use ImGuiKeyOwner_Any to lock keys from everyone.
// - SetKeyOwner(..., None) : clears owner // - SetKeyOwner(..., None) : clears owner
// - SetKeyOwner(..., Any, !Lock) : illegal (assert) // - SetKeyOwner(..., Any, !Lock) : illegal (assert)
@ -8401,14 +8394,12 @@ void ImGui::SetKeyOwner(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags)
IM_ASSERT(IsNamedKeyOrModKey(key) && (owner_id != ImGuiKeyOwner_Any || (flags & (ImGuiInputFlags_LockThisFrame | ImGuiInputFlags_LockUntilRelease)))); // Can only use _Any with _LockXXX flags (to eat a key away without an ID to retrieve it) IM_ASSERT(IsNamedKeyOrModKey(key) && (owner_id != ImGuiKeyOwner_Any || (flags & (ImGuiInputFlags_LockThisFrame | ImGuiInputFlags_LockUntilRelease)))); // Can only use _Any with _LockXXX flags (to eat a key away without an ID to retrieve it)
ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(key); ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(key);
owner_data->OwnerNext = owner_id; owner_data->OwnerCurr = owner_data->OwnerNext = owner_id;
// We cannot lock by default as it would likely break lots of legacy code. // We cannot lock by default as it would likely break lots of legacy code.
// In the case of using LockUntilRelease while key is not down we still lock during the frame (no key_data->Down test) // In the case of using LockUntilRelease while key is not down we still lock during the frame (no key_data->Down test)
owner_data->LockUntilRelease = (flags & ImGuiInputFlags_LockUntilRelease) != 0; owner_data->LockUntilRelease = (flags & ImGuiInputFlags_LockUntilRelease) != 0;
owner_data->LockThisFrame = (flags & ImGuiInputFlags_LockThisFrame) != 0 || (owner_data->LockUntilRelease); owner_data->LockThisFrame = (flags & ImGuiInputFlags_LockThisFrame) != 0 || (owner_data->LockUntilRelease);
if (owner_data->LockThisFrame)
owner_data->OwnerCurr = owner_id;
} }
// This is more or less equivalent to: // This is more or less equivalent to: