RangeSelect/MultiSelect: move shared logic to MultiSelectItemHeader().

No logic change AFAIK but added an indent level in MultiSelectItemHeader(). Logic changes will come in next commit.
features/range_select
ocornut ago%!(EXTRA string=2 years)
parent 4b15ee88a0
commit 6f9d36c6f2
  1. 3
      imgui_demo.cpp
  2. 2
      imgui_internal.h
  3. 51
      imgui_widgets.cpp

@ -3399,7 +3399,8 @@ static void ShowDemoWindowMultiSelect()
ImGui::SetNextItemSelectionUserData(n);
if (widget_type == WidgetType_Selectable)
{
ImGui::Selectable(label, item_is_selected);
ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_None;
ImGui::Selectable(label, item_is_selected, selectable_flags);
if (item_curr_idx_to_focus == n)
ImGui::SetKeyboardFocusHere(-1);

@ -3356,7 +3356,7 @@ namespace ImGui
IMGUI_API int TypingSelectFindBestLeadingMatch(ImGuiTypingSelectRequest* req, int items_count, const char* (*get_item_name_func)(void*, int), void* user_data);
// Multi-Select API
IMGUI_API void MultiSelectItemHeader(ImGuiID id, bool* p_selected);
IMGUI_API void MultiSelectItemHeader(ImGuiID id, bool* p_selected, ImGuiButtonFlags* p_button_flags);
IMGUI_API void MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed);
// Internal Columns API (this is not exposed because we will encourage transitioning to the Tables API)

@ -6356,19 +6356,11 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
// Multi-selection support (header)
if (is_multi_select)
{
MultiSelectItemHeader(id, &selected);
button_flags |= ImGuiButtonFlags_NoHoveredOnFocus;
// Handle multi-select + alter button flags for it
MultiSelectItemHeader(id, &selected, &button_flags);
// We absolutely need to distinguish open vs select so this is the default when multi-select is enabled.
// We absolutely need to distinguish open vs select so comes by default
flags |= ImGuiTreeNodeFlags_OpenOnArrow;
// To handle drag and drop of multiple items we need to avoid clearing selection on click.
// Enabling this test makes actions using CTRL+SHIFT delay their effect on MouseUp which is annoying, but it allows drag and drop of multiple items.
// FIXME-MULTISELECT: Consider opt-in for drag and drop behavior in ImGuiMultiSelectFlags?
if (!selected || (g.ActiveId == id && g.ActiveIdHasBeenPressedBefore))
button_flags = (button_flags | ImGuiButtonFlags_PressedOnClick) & ~ImGuiButtonFlags_PressedOnClickRelease;
else
button_flags |= ImGuiButtonFlags_PressedOnClickRelease;
}
else
{
@ -6705,15 +6697,8 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
const bool was_selected = selected;
if (is_multi_select)
{
MultiSelectItemHeader(id, &selected);
button_flags |= ImGuiButtonFlags_NoHoveredOnFocus;
// To handle drag and drop of multiple items we need to avoid clearing selection on click.
// Enabling this test makes actions using CTRL+SHIFT delay their effect on the mouse release which is annoying, but it allows drag and drop of multiple items.
if (!selected || (g.ActiveId == id && g.ActiveIdHasBeenPressedBefore))
button_flags |= ImGuiButtonFlags_PressedOnClick;
else
button_flags |= ImGuiButtonFlags_PressedOnClickRelease;
// Handle multi-select + alter button flags for it
MultiSelectItemHeader(id, &selected, &button_flags);
}
bool hovered, held;
@ -7154,21 +7139,21 @@ void ImGui::SetNextItemSelectionUserData(ImGuiSelectionUserData selection_user_d
}
}
void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected)
void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected, ImGuiButtonFlags* p_button_flags)
{
ImGuiContext& g = *GImGui;
ImGuiMultiSelectTempData* ms = g.CurrentMultiSelect;
if (!ms->IsFocused)
return;
ImGuiMultiSelectState* storage = ms->Storage;
IM_ASSERT(g.NextItemData.FocusScopeId == g.CurrentFocusScopeId && "Forgot to call SetNextItemSelectionUserData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope");
bool selected = *p_selected;
if (ms->IsFocused)
{
ImGuiMultiSelectState* storage = ms->Storage;
ImGuiSelectionUserData item_data = g.NextItemData.SelectionUserData;
IM_ASSERT(g.NextItemData.FocusScopeId == g.CurrentFocusScopeId && "Forgot to call SetNextItemSelectionUserData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope");
// 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.
// If you are using a clipper (aka not submitting every element of the list) you need to process the Clear/SelectAll request after calling BeginMultiSelect()
bool selected = *p_selected;
if (ms->BeginIO.RequestClear)
selected = false;
else if (ms->BeginIO.RequestSelectAll)
@ -7198,10 +7183,22 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected)
else if ((ms->KeyMods & ImGuiMod_Ctrl) == 0)
selected = false;
}
*p_selected = selected;
}
// Alter button behavior flags
// To handle drag and drop of multiple items we need to avoid clearing selection on click.
// Enabling this test makes actions using CTRL+SHIFT delay their effect on MouseUp which is annoying, but it allows drag and drop of multiple items.
// FIXME-MULTISELECT: Consider opt-in for drag and drop behavior in ImGuiMultiSelectFlags?
ImGuiButtonFlags button_flags = *p_button_flags;
button_flags |= ImGuiButtonFlags_NoHoveredOnFocus;
if (!selected || (g.ActiveId == id && g.ActiveIdHasBeenPressedBefore))
button_flags = (button_flags | ImGuiButtonFlags_PressedOnClick) & ~ImGuiButtonFlags_PressedOnClickRelease;
else
button_flags |= ImGuiButtonFlags_PressedOnClickRelease;
*p_button_flags = button_flags;
}
void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed)
{
ImGuiContext& g = *GImGui;

Loading…
Cancel
Save