Skip to content

Commit b6e313b

Browse files
committed
MultiSelect: using ImGuiMultiSelectFlags_NoRangeSelect ensure never having to interpolate between two ImGuiSelectionUserData.
1 parent 168ef39 commit b6e313b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

imgui.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -2760,6 +2760,8 @@ struct ImColor
27602760
// SetRange requests will give you two end-points and you will need to iterate/interpolate between them to update your selection.
27612761
// - However it is perfectly possible to store a POINTER or another IDENTIFIER inside ImGuiSelectionUserData.
27622762
// Our system never assume that you identify items by indices, it never attempts to interpolate between two values.
2763+
// - If you enable ImGuiMultiSelectFlags_NoRangeSelect then it is guaranteed that you will never have to interpolate
2764+
// between two ImGuiSelectionUserData, which may be a convenient way to use part of the feature with less code work.
27632765
// - As most users will want to store an index, for convenience and to reduce confusion we use ImS64 instead of void*,
27642766
// being syntactically easier to downcast. Feel free to reinterpret_cast and store a pointer inside.
27652767

@@ -2769,7 +2771,7 @@ enum ImGuiMultiSelectFlags_
27692771
ImGuiMultiSelectFlags_None = 0,
27702772
ImGuiMultiSelectFlags_SingleSelect = 1 << 0, // Disable selecting more than one item. This is available to allow single-selection code to share same code/logic if desired. It essentially disables the main purpose of BeginMultiSelect() tho!
27712773
ImGuiMultiSelectFlags_NoSelectAll = 1 << 1, // Disable CTRL+A shortcut to select all.
2772-
ImGuiMultiSelectFlags_NoRangeSelect = 1 << 2, // Disable Shift+selection mouse/keyboard support (useful for unordered 2D selection).
2774+
ImGuiMultiSelectFlags_NoRangeSelect = 1 << 2, // Disable Shift+selection mouse/keyboard support (useful for unordered 2D selection). With BoxSelect is also ensure contiguous SetRange requests are not combined into one. This allows not handling interpolation in SetRange requests.
27732775
ImGuiMultiSelectFlags_NoAutoSelect = 1 << 3, // Disable selecting items when navigating (useful for e.g. supporting range-select in a list of checkboxes)
27742776
ImGuiMultiSelectFlags_NoAutoClear = 1 << 4, // Disable clearing selection when navigating or selecting another one (generally used with ImGuiMultiSelectFlags_NoAutoSelect. useful for e.g. supporting range-select in a list of checkboxes)
27752777
ImGuiMultiSelectFlags_NoAutoClearOnReselect = 1 << 5, // Disable clearing selection when clicking/selecting an already selected item

imgui_widgets.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -7680,9 +7680,10 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
76807680
{
76817681
selected = !selected;
76827682
ImGuiSelectionRequest req = { ImGuiSelectionRequestType_SetRange, selected, +1, item_data, item_data };
7683-
ImGuiSelectionRequest* prev_req = (ms->IO.Requests.Size > 0) ? &ms->IO.Requests.Data[ms->IO.Requests.Size - 1] : NULL;
7684-
if (prev_req && prev_req->Type == ImGuiSelectionRequestType_SetRange && prev_req->RangeLastItem == ms->BoxSelectLastitem && prev_req->Selected == selected)
7685-
prev_req->RangeLastItem = item_data; // Merge span into same request
7683+
// Merge continuous ranges (unless NoRangeSelect is set)
7684+
ImGuiSelectionRequest* prev = ms->IO.Requests.Size > 0 ? &ms->IO.Requests.Data[ms->IO.Requests.Size - 1] : NULL;
7685+
if (prev && prev->Type == ImGuiSelectionRequestType_SetRange && prev->RangeLastItem == ms->BoxSelectLastitem && prev->Selected == selected && (ms->Flags & ImGuiMultiSelectFlags_NoRangeSelect) == 0)
7686+
prev->RangeLastItem = item_data; // Merge span into same request
76867687
else
76877688
ms->IO.Requests.push_back(req);
76887689
}

0 commit comments

Comments
 (0)