RangeSelect/MultiSelect: Renamed SetNextItemMultiSelectData() to SetNextItemSelectionData()

This commit is contained in:
omar 2020-01-14 16:18:55 +01:00 committed by ocornut
parent 72da877c4c
commit abfa8487eb
4 changed files with 20 additions and 12 deletions

View File

@ -620,7 +620,7 @@ namespace ImGui
// When enabled, Selectable() and TreeNode() functions will return true when selection needs toggling. // When enabled, Selectable() and TreeNode() functions will return true when selection needs toggling.
IMGUI_API ImGuiMultiSelectData* BeginMultiSelect(ImGuiMultiSelectFlags flags, void* range_ref, bool range_ref_is_selected); IMGUI_API ImGuiMultiSelectData* BeginMultiSelect(ImGuiMultiSelectFlags flags, void* range_ref, bool range_ref_is_selected);
IMGUI_API ImGuiMultiSelectData* EndMultiSelect(); IMGUI_API ImGuiMultiSelectData* EndMultiSelect();
IMGUI_API void SetNextItemMultiSelectData(void* item_data); IMGUI_API void SetNextItemSelectionData(void* item_data);
// Widgets: List Boxes // Widgets: List Boxes
// - This is essentially a thin wrapper to using BeginChild/EndChild with some stylistic changes. // - This is essentially a thin wrapper to using BeginChild/EndChild with some stylistic changes.
@ -2353,7 +2353,7 @@ struct ImGuiListClipper
// performance penalty, but requires a little more work on the code. If you only have a few hundreds elements in your possible selection set, // performance penalty, but requires a little more work on the code. If you only have a few hundreds elements in your possible selection set,
// you may as well not bother with clipping, as the cost should be negligible (as least on imgui side). // you may as well not bother with clipping, as the cost should be negligible (as least on imgui side).
// If you are not sure, always start without clipping and you can work your way to the more optimized version afterwards. // If you are not sure, always start without clipping and you can work your way to the more optimized version afterwards.
// - The void* Src/Dst value represent a selectable object. They are the values you pass to SetNextItemMultiSelectData(). // - The void* Src/Dst value represent a selectable object. They are the values you pass to SetNextItemSelectionData().
// Storing an integer index is the easiest thing to do, as SetRange requests will give you two end points. But the code never assume that sortable integers are used. // Storing an integer index is the easiest thing to do, as SetRange requests will give you two end points. But the code never assume that sortable integers are used.
// - In the spirit of imgui design, your code own the selection data. So this is designed to handle all kind of selection data: instructive (store a bool inside each object), // - In the spirit of imgui design, your code own the selection data. So this is designed to handle all kind of selection data: instructive (store a bool inside each object),
// external array (store an array aside from your objects), set (store only selected items in a hash/map/set), using intervals (store indices in an interval tree), etc. // external array (store an array aside from your objects), set (store only selected items in a hash/map/set), using intervals (store indices in an interval tree), etc.
@ -2364,7 +2364,7 @@ struct ImGuiListClipper
// 3) Set RangeSrcPassedBy=true if the RangeSrc item is part of the items clipped before the first submitted/visible item. [Only required if you are using a clipper in step 4] // 3) Set RangeSrcPassedBy=true if the RangeSrc item is part of the items clipped before the first submitted/visible item. [Only required if you are using a clipper in step 4]
// This is because for range-selection we need to know if we are currently "inside" or "outside" the range. // This is because for range-selection we need to know if we are currently "inside" or "outside" the range.
// If you are using integer indices everywhere, this is easy to compute: if (clipper.DisplayStart > (int)data->RangeSrc) { data->RangeSrcPassedBy = true; } // If you are using integer indices everywhere, this is easy to compute: if (clipper.DisplayStart > (int)data->RangeSrc) { data->RangeSrcPassedBy = true; }
// 4) Submit your items with SetNextItemMultiSelectData() + Selectable()/TreeNode() calls. // 4) Submit your items with SetNextItemSelectionData() + Selectable()/TreeNode() calls.
// Call IsItemSelectionToggled() to query with the selection state has been toggled, in which you need the info immediately (before EndMultiSelect()) for your display. // Call IsItemSelectionToggled() to query with the selection state has been toggled, in which you need the info immediately (before EndMultiSelect()) for your display.
// When cannot reliably return a "IsItemSelected()" value because we need to consider clipped (unprocessed) item, this is why we return a toggle event instead. // When cannot reliably return a "IsItemSelected()" value because we need to consider clipped (unprocessed) item, this is why we return a toggle event instead.
// 5) Call EndMultiSelect(). Save the value of ->RangeSrc for the next frame (you may convert the value in a format that is safe for persistance) // 5) Call EndMultiSelect(). Save the value of ->RangeSrc for the next frame (you may convert the value in a format that is safe for persistance)

View File

@ -1260,7 +1260,7 @@ static void ShowDemoWindowWidgets()
}; };
int COUNT = 1000; int COUNT = 1000;
HelpMarker("Hold CTRL and click to select multiple items. Hold SHIFT to select a range."); HelpMarker("Hold CTRL and click to select multiple items. Hold SHIFT to select a range. Keyboard is also supported.");
ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", (unsigned int *)&ImGui::GetIO().ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard); ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", (unsigned int *)&ImGui::GetIO().ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard);
if (ImGui::BeginListBox("##Basket", ImVec2(-FLT_MIN, ImGui::GetFontSize() * 20))) if (ImGui::BeginListBox("##Basket", ImVec2(-FLT_MIN, ImGui::GetFontSize() * 20)))
@ -1268,6 +1268,7 @@ static void ShowDemoWindowWidgets()
ImGuiMultiSelectData* multi_select_data = ImGui::BeginMultiSelect(ImGuiMultiSelectFlags_None, (void*)(intptr_t)selection_ref, selection.GetSelected((int)selection_ref)); ImGuiMultiSelectData* multi_select_data = ImGui::BeginMultiSelect(ImGuiMultiSelectFlags_None, (void*)(intptr_t)selection_ref, selection.GetSelected((int)selection_ref));
if (multi_select_data->RequestClear) { selection.Clear(); } if (multi_select_data->RequestClear) { selection.Clear(); }
if (multi_select_data->RequestSelectAll) { selection.SelectAll(COUNT); } if (multi_select_data->RequestSelectAll) { selection.SelectAll(COUNT); }
ImVec2 color_button_sz(ImGui::GetFontSize(), ImGui::GetFontSize());
ImGuiListClipper clipper; ImGuiListClipper clipper;
clipper.Begin(COUNT); clipper.Begin(COUNT);
while (clipper.Step()) while (clipper.Step())
@ -1280,7 +1281,14 @@ static void ShowDemoWindowWidgets()
char label[64]; char label[64];
sprintf(label, "Object %05d (category: %s)", n, random_names[n % IM_ARRAYSIZE(random_names)]); sprintf(label, "Object %05d (category: %s)", n, random_names[n % IM_ARRAYSIZE(random_names)]);
bool item_is_selected = selection.GetSelected(n); bool item_is_selected = selection.GetSelected(n);
ImGui::SetNextItemMultiSelectData((void*)(intptr_t)n);
// Emit a color button, to test that Shift+LeftArrow landing on an item that is not part
// of the selection scope doesn't erroneously alter our selection.
ImVec4 dummy_col = ImColor((ImU32)ImGui::GetID(label));
ImGui::ColorButton("##", dummy_col, ImGuiColorEditFlags_NoTooltip, color_button_sz);
ImGui::SameLine();
ImGui::SetNextItemSelectionData((void*)(intptr_t)n);
if (ImGui::Selectable(label, item_is_selected)) if (ImGui::Selectable(label, item_is_selected))
selection.SetSelected(n, !item_is_selected); selection.SetSelected(n, !item_is_selected);
ImGui::PopID(); ImGui::PopID();

View File

@ -1095,7 +1095,7 @@ struct ImGuiNextItemData
ImGuiCond OpenCond; ImGuiCond OpenCond;
bool OpenVal; // Set by SetNextItemOpen() bool OpenVal; // Set by SetNextItemOpen()
ImGuiID MultiSelectScopeId; // Set by SetNextItemMultiSelectData() ImGuiID MultiSelectScopeId; // Set by SetNextItemMultiSelectData()
void* MultiSelectData; void* SelectionData; // Set by SetNextItemSelectionData() (note that NULL/0 is a valid value)
ImGuiNextItemData() { memset(this, 0, sizeof(*this)); } ImGuiNextItemData() { memset(this, 0, sizeof(*this)); }
inline void ClearFlags() { Flags = ImGuiNextItemDataFlags_None; } // Also cleared manually by ItemAdd()! inline void ClearFlags() { Flags = ImGuiNextItemDataFlags_None; } // Also cleared manually by ItemAdd()!

View File

@ -6359,7 +6359,7 @@ bool ImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// - BeginMultiSelect() // - BeginMultiSelect()
// - EndMultiSelect() // - EndMultiSelect()
// - SetNextItemMultiSelectData() // - SetNextItemSelectionData()
// - MultiSelectItemHeader() [Internal] // - MultiSelectItemHeader() [Internal]
// - MultiSelectItemFooter() [Internal] // - MultiSelectItemFooter() [Internal]
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -6429,11 +6429,11 @@ ImGuiMultiSelectData* ImGui::EndMultiSelect()
return &state->Out; return &state->Out;
} }
void ImGui::SetNextItemMultiSelectData(void* item_data) void ImGui::SetNextItemSelectionData(void* item_data)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
IM_ASSERT(g.MultiSelectScopeId != 0); IM_ASSERT(g.MultiSelectScopeId != 0);
g.NextItemData.MultiSelectData = item_data; g.NextItemData.SelectionData = item_data;
g.NextItemData.MultiSelectScopeId = g.MultiSelectScopeId; g.NextItemData.MultiSelectScopeId = g.MultiSelectScopeId;
} }
@ -6442,8 +6442,8 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiMultiSelectState* state = &g.MultiSelectState; ImGuiMultiSelectState* state = &g.MultiSelectState;
IM_ASSERT(g.NextItemData.MultiSelectScopeId == g.MultiSelectScopeId && "Forgot to call SetNextItemMultiSelectData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope"); IM_ASSERT(g.NextItemData.MultiSelectScopeId == g.MultiSelectScopeId && "Forgot to call SetNextItemSelectionData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope");
void* item_data = g.NextItemData.MultiSelectData; void* item_data = g.NextItemData.SelectionData;
// Apply Clear/SelectAll requests requested by BeginMultiSelect(). // Apply Clear/SelectAll requests requested by BeginMultiSelect().
// This is only useful if the user hasn't processed them already, and this only works if the user isn't using the clipper. // This is only useful if the user hasn't processed them already, and this only works if the user isn't using the clipper.
@ -6482,7 +6482,7 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
ImGuiMultiSelectState* state = &g.MultiSelectState; ImGuiMultiSelectState* state = &g.MultiSelectState;
void* item_data = g.NextItemData.MultiSelectData; void* item_data = g.NextItemData.SelectionData;
g.NextItemData.MultiSelectScopeId = 0; g.NextItemData.MultiSelectScopeId = 0;
bool selected = *p_selected; bool selected = *p_selected;