MultiSelect: (Breaking) Fix + Rename ImGuiMultiSelectFlags_NoMultiSelect to ImGuiMultiSelectFlags_SingleSelect as it seems easier to grasp.
Feature was broken by "Tidying up..." June 30 commit.
This commit is contained in:
parent
0cf376348b
commit
847b1dde8c
6
imgui.h
6
imgui.h
@ -2724,12 +2724,12 @@ struct ImColor
|
||||
#define IMGUI_HAS_MULTI_SELECT // Multi-Select/Range-Select WIP branch // <-- This is currently _not_ in the top of imgui.h to prevent merge conflicts.
|
||||
|
||||
// Flags for BeginMultiSelect().
|
||||
// (we provide 'ImGuiMultiSelectFlags_NoMultiSelect' for consistency and flexiblity, but it essentially disable the main purpose of BeginMultiSelect().
|
||||
// If you use 'ImGuiMultiSelectFlags_NoMultiSelect' you can handle single-selection in a simpler way by just calling Selectable()/TreeNode() and reacting on clicks).
|
||||
// (we provide 'ImGuiMultiSelectFlags_SingleSelect' for consistency and flexiblity to allow a single-selection to use same code/logic, but it essentially disable the biggest purpose of BeginMultiSelect().
|
||||
// If you use 'ImGuiMultiSelectFlags_SingleSelect' you can handle single-selection in a simpler way by just calling Selectable()/TreeNode() and reacting on clicks).
|
||||
enum ImGuiMultiSelectFlags_
|
||||
{
|
||||
ImGuiMultiSelectFlags_None = 0,
|
||||
ImGuiMultiSelectFlags_NoMultiSelect = 1 << 0, // Disable selecting more than one item. This is not very useful at this kind of selection can be implemented without BeginMultiSelect(), but this is available for consistency.
|
||||
ImGuiMultiSelectFlags_SingleSelect = 1 << 0, // Disable selecting more than one item. This is available to allow single-selection code to use same code/logic is desired, but may not be very useful.
|
||||
ImGuiMultiSelectFlags_NoSelectAll = 1 << 1, // Disable CTRL+A shortcut to set RequestSelectAll
|
||||
ImGuiMultiSelectFlags_ClearOnEscape = 1 << 2, // Clear selection when pressing Escape while scope is focused.
|
||||
ImGuiMultiSelectFlags_ClearOnClickWindowVoid= 1 << 3, // Clear selection when clicking on empty location within host window (use if BeginMultiSelect() covers a whole window)
|
||||
|
@ -3106,7 +3106,7 @@ static void ShowDemoWindowMultiSelect()
|
||||
ImGui::Checkbox("Enable drag & drop", &use_drag_drop);
|
||||
ImGui::Checkbox("Show in a table", &show_in_table);
|
||||
ImGui::Checkbox("Show color button", &show_color_button);
|
||||
ImGui::CheckboxFlags("ImGuiMultiSelectFlags_NoMultiSelect", &flags, ImGuiMultiSelectFlags_NoMultiSelect);
|
||||
ImGui::CheckboxFlags("ImGuiMultiSelectFlags_SingleSelect", &flags, ImGuiMultiSelectFlags_SingleSelect);
|
||||
ImGui::CheckboxFlags("ImGuiMultiSelectFlags_NoSelectAll", &flags, ImGuiMultiSelectFlags_NoSelectAll);
|
||||
ImGui::CheckboxFlags("ImGuiMultiSelectFlags_ClearOnEscape", &flags, ImGuiMultiSelectFlags_ClearOnEscape);
|
||||
ImGui::CheckboxFlags("ImGuiMultiSelectFlags_ClearOnClickWindowVoid", &flags, ImGuiMultiSelectFlags_ClearOnClickWindowVoid);
|
||||
|
@ -7180,7 +7180,7 @@ ImGuiMultiSelectIO* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags)
|
||||
}
|
||||
|
||||
// Shortcut: Select all (CTRL+A)
|
||||
if (!(flags & ImGuiMultiSelectFlags_NoMultiSelect) && !(flags & ImGuiMultiSelectFlags_NoSelectAll))
|
||||
if (!(flags & ImGuiMultiSelectFlags_SingleSelect) && !(flags & ImGuiMultiSelectFlags_NoSelectAll))
|
||||
if (Shortcut(ImGuiMod_Ctrl | ImGuiKey_A))
|
||||
ms->BeginIO.RequestSelectAll = true;
|
||||
|
||||
@ -7332,7 +7332,7 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
|
||||
|
||||
void* item_data = (void*)g.NextItemData.SelectionUserData;
|
||||
|
||||
const bool is_multiselect = (ms->Flags & ImGuiMultiSelectFlags_NoMultiSelect) == 0;
|
||||
const bool is_multiselect = (ms->Flags & ImGuiMultiSelectFlags_SingleSelect) == 0;
|
||||
bool is_ctrl = (ms->KeyMods & ImGuiMod_Ctrl) != 0;
|
||||
bool is_shift = (ms->KeyMods & ImGuiMod_Shift) != 0;
|
||||
|
||||
@ -7411,18 +7411,20 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
|
||||
ms->EndIO.RangeDirection = +1;
|
||||
}
|
||||
|
||||
if (input_source == ImGuiInputSource_Mouse || g.NavActivateId == id)
|
||||
if (!is_multiselect)
|
||||
{
|
||||
if (is_multiselect && !is_ctrl)
|
||||
ms->EndIO.RequestClear = true;
|
||||
}
|
||||
else if (input_source == ImGuiInputSource_Mouse || g.NavActivateId == id)
|
||||
{
|
||||
if (!is_ctrl)
|
||||
ms->EndIO.RequestClear = true;
|
||||
}
|
||||
else if (input_source == ImGuiInputSource_Keyboard || input_source == ImGuiInputSource_Gamepad)
|
||||
{
|
||||
if (is_multiselect && is_shift && !is_ctrl) // Without Shift the RequestClear was done in BeginIO, not necessary to do again.
|
||||
if (is_shift && !is_ctrl) // Without Shift the RequestClear was done in BeginIO, not necessary to do again.
|
||||
ms->EndIO.RequestClear = true;
|
||||
}
|
||||
else if (!is_multiselect)
|
||||
ms->EndIO.RequestClear = true;
|
||||
}
|
||||
|
||||
// Update/store the selection state of the Source item (used by CTRL+SHIFT, when Source is unselected we perform a range unselect)
|
||||
|
Loading…
Reference in New Issue
Block a user