1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-09-24 03:28:33 +02:00

MultiSelect: added courtesy ImGuiMultiSelectFlags_NavWrapX flag so we can demo this until a nav api is designed.

This commit is contained in:
ocornut 2024-06-28 19:01:18 +02:00
parent d411c9054a
commit 7d4de84ee3
3 changed files with 22 additions and 7 deletions

View File

@ -2781,6 +2781,7 @@ enum ImGuiMultiSelectFlags_
ImGuiMultiSelectFlags_SelectOnClick = 1 << 13, // Apply selection on mouse down when clicking on unselected item. (Default)
ImGuiMultiSelectFlags_SelectOnClickRelease = 1 << 14, // Apply selection on mouse release when clicking an unselected item. Allow dragging an unselected item without altering selection.
//ImGuiMultiSelectFlags_RangeSelect2d = 1 << 15, // Shift+Selection uses 2d geometry instead of linear sequence, so possible to use Shift+up/down to select vertically in grid. Analogous to what BoxSelect does.
ImGuiMultiSelectFlags_NavWrapX = 1 << 16, // [Temporary] Enable navigation wrapping on X axis. Provided as a convenience because we don't have a design for the general Nav API for this yet. When the more general feature be public we may obsolete this flag in favor of new one.
};
// Main IO structure returned by BeginMultiSelect()/EndMultiSelect().

View File

@ -9836,10 +9836,21 @@ struct ExampleAssetsBrowser
// Multi-select
ImGuiMultiSelectFlags ms_flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_ClearOnClickVoid;
if (AllowDragUnselected)
ms_flags |= ImGuiMultiSelectFlags_SelectOnClickRelease; // To allow dragging an unselected item without altering selection.
// - Enable box-select (in 2D mode, so that changing box-select rectangle X1/X2 boundaries will affect clipped items)
if (AllowBoxSelect)
ms_flags |= ImGuiMultiSelectFlags_BoxSelect2d; // Enable box-select in 2D mode.
ms_flags |= ImGuiMultiSelectFlags_BoxSelect2d;
// - This feature allows dragging an unselected item without selecting it (rarely used)
if (AllowDragUnselected)
ms_flags |= ImGuiMultiSelectFlags_SelectOnClickRelease;
// - Enable keyboard wrapping on X axis
// (FIXME-MULTISELECT: We haven't designed/exposed a general nav wrapping api yet, so this flag is provided as a courtesy to avoid doing:
// ImGui::NavMoveRequestTryWrapping(ImGui::GetCurrentWindow(), ImGuiNavMoveFlags_WrapX);
// When we finish implementing a more general API for this, we will obsolete this flag in favor of the new system)
ms_flags |= ImGuiMultiSelectFlags_NavWrapX;
ImGuiMultiSelectIO* ms_io = ImGui::BeginMultiSelect(ms_flags, Selection.Size, Items.Size);
// Use custom selection adapter: store ID in selection (recommended)
@ -9970,10 +9981,6 @@ struct ExampleAssetsBrowser
if (want_delete)
Selection.ApplyDeletionPostLoop(ms_io, Items, item_curr_idx_to_focus);
// Keyboard/Gamepad Wrapping
// FIXME-MULTISELECT: Currently an imgui_internal.h API. Find a design/way to expose this in public API.
//ImGui::NavMoveRequestTryWrapping(ImGui::GetCurrentWindow(), ImGuiNavMoveFlags_WrapX);
// Zooming with CTRL+Wheel
if (ImGui::IsWindowAppearing())
ZoomWheelAccum = 0.0f;

View File

@ -7479,6 +7479,13 @@ ImGuiMultiSelectIO* ImGui::EndMultiSelect()
}
}
// Courtesy nav wrapping helper flag
if (ms->Flags & ImGuiMultiSelectFlags_NavWrapX)
{
IM_ASSERT(ms->Flags & ImGuiMultiSelectFlags_ScopeWindow); // Only supported at window scope
ImGui::NavMoveRequestTryWrapping(ImGui::GetCurrentWindow(), ImGuiNavMoveFlags_WrapX);
}
// Unwind
window->DC.CursorMaxPos = ImMax(ms->BackupCursorMaxPos, window->DC.CursorMaxPos);
PopFocusScope();