mirror of
https://github.com/ocornut/imgui.git
synced 2026-03-28 07:47:02 -05:00
MultiSelect: added ImGuiMultiSelectFlags_SelectOnClickAlways mode. Prevents Drag and Drop of multiple items but allows BoxSelect to always reselect even when clicking inside a selecttion. (#9307, #1861)
This commit is contained in:
@@ -53,7 +53,7 @@ Breaking Changes:
|
|||||||
BeginChild("ScrollingRegion", { 0, -footer_height });
|
BeginChild("ScrollingRegion", { 0, -footer_height });
|
||||||
When such idiom was used and assuming zero-height Separator, it is likely that
|
When such idiom was used and assuming zero-height Separator, it is likely that
|
||||||
in 1.92.7 the resulting window will have unexpected 1 pixel scrolling range.
|
in 1.92.7 the resulting window will have unexpected 1 pixel scrolling range.
|
||||||
- MultiSelect: renamed ImGuiMultiSelectFlags_SelectOnClick to ImGuiMultiSelectFlags_SelectOnAuto.
|
- Multi-Select: renamed ImGuiMultiSelectFlags_SelectOnClick to ImGuiMultiSelectFlags_SelectOnAuto.
|
||||||
Kept inline redirection enum (will obsolete).
|
Kept inline redirection enum (will obsolete).
|
||||||
- Combo(), ListBox(): commented out legacy signatures which were obsoleted in 1.90
|
- Combo(), ListBox(): commented out legacy signatures which were obsoleted in 1.90
|
||||||
(Nov 2023), when the getter callback type was changed from:
|
(Nov 2023), when the getter callback type was changed from:
|
||||||
@@ -105,6 +105,10 @@ Other Changes:
|
|||||||
BeginPopupContextItem(), BeginPopupContextWindow() or OpenPopupOnItemClick().
|
BeginPopupContextItem(), BeginPopupContextWindow() or OpenPopupOnItemClick().
|
||||||
(#8803, #9270) [@exelix11, @ocornut]
|
(#8803, #9270) [@exelix11, @ocornut]
|
||||||
- Popups: pressing North button (PS4/PS5 triangle, SwitchX, Xbox Y) also open popups menus.
|
- Popups: pressing North button (PS4/PS5 triangle, SwitchX, Xbox Y) also open popups menus.
|
||||||
|
- Multi-Select:
|
||||||
|
- Added ImGuiMultiSelectFlags_SelectOnClickAlways mode (rarely used).
|
||||||
|
This prevents Drag and Drop of multiple items, but it allows to start a new Box-Selection
|
||||||
|
from inside an existing selection (Excel style). (#9307, #1861)
|
||||||
- Clipper:
|
- Clipper:
|
||||||
- Clear `DisplayStart`/`DisplayEnd` fields when `Step()` returns false.
|
- Clear `DisplayStart`/`DisplayEnd` fields when `Step()` returns false.
|
||||||
- Added `UserIndex` helper storage. This is solely a convenience for cases where
|
- Added `UserIndex` helper storage. This is solely a convenience for cases where
|
||||||
|
|||||||
5
imgui.h
5
imgui.h
@@ -3031,11 +3031,12 @@ enum ImGuiMultiSelectFlags_
|
|||||||
ImGuiMultiSelectFlags_ScopeWindow = 1 << 11, // Scope for _BoxSelect and _ClearOnClickVoid is whole window (Default). Use if BeginMultiSelect() covers a whole window or used a single time in same window.
|
ImGuiMultiSelectFlags_ScopeWindow = 1 << 11, // Scope for _BoxSelect and _ClearOnClickVoid is whole window (Default). Use if BeginMultiSelect() covers a whole window or used a single time in same window.
|
||||||
ImGuiMultiSelectFlags_ScopeRect = 1 << 12, // Scope for _BoxSelect and _ClearOnClickVoid is rectangle encompassing BeginMultiSelect()/EndMultiSelect(). Use if BeginMultiSelect() is called multiple times in same window.
|
ImGuiMultiSelectFlags_ScopeRect = 1 << 12, // Scope for _BoxSelect and _ClearOnClickVoid is rectangle encompassing BeginMultiSelect()/EndMultiSelect(). Use if BeginMultiSelect() is called multiple times in same window.
|
||||||
ImGuiMultiSelectFlags_SelectOnAuto = 1 << 13, // Apply selection on mouse down when clicking on unselected item, on mouse up when clicking on selected item. (Default)
|
ImGuiMultiSelectFlags_SelectOnAuto = 1 << 13, // Apply selection on mouse down when clicking on unselected item, on mouse up when clicking on selected 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_SelectOnClickAlways = 1 << 14, // Apply selection on mouse down when clicking on any items. Prevents Drag and Drop from being used on multiple-selection, but allows e.g. BoxSelect to always reselect even when clicking inside an existing selection. (Excel style behavior)
|
||||||
|
ImGuiMultiSelectFlags_SelectOnClickRelease = 1 << 15, // 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_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.
|
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.
|
||||||
ImGuiMultiSelectFlags_NoSelectOnRightClick = 1 << 17, // Disable default right-click processing, which selects item on mouse down, and is designed for context-menus.
|
ImGuiMultiSelectFlags_NoSelectOnRightClick = 1 << 17, // Disable default right-click processing, which selects item on mouse down, and is designed for context-menus.
|
||||||
ImGuiMultiSelectFlags_SelectOnMask_ = ImGuiMultiSelectFlags_SelectOnAuto | ImGuiMultiSelectFlags_SelectOnClickRelease,
|
ImGuiMultiSelectFlags_SelectOnMask_ = ImGuiMultiSelectFlags_SelectOnAuto | ImGuiMultiSelectFlags_SelectOnClickAlways | ImGuiMultiSelectFlags_SelectOnClickRelease,
|
||||||
|
|
||||||
// Obsolete names
|
// Obsolete names
|
||||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
|||||||
@@ -2632,7 +2632,7 @@ struct ExampleDualListBox
|
|||||||
}
|
}
|
||||||
if (child_visible)
|
if (child_visible)
|
||||||
{
|
{
|
||||||
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_None;
|
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_BoxSelect1d;
|
||||||
ImGuiMultiSelectIO* ms_io = ImGui::BeginMultiSelect(flags, selection.Size, items.Size);
|
ImGuiMultiSelectIO* ms_io = ImGui::BeginMultiSelect(flags, selection.Size, items.Size);
|
||||||
ApplySelectionRequests(ms_io, side);
|
ApplySelectionRequests(ms_io, side);
|
||||||
|
|
||||||
@@ -3243,6 +3243,10 @@ static void DemoWindowWidgetsSelectionAndMultiSelect(ImGuiDemoWindowData* demo_d
|
|||||||
flags &= ~ImGuiMultiSelectFlags_ScopeWindow;
|
flags &= ~ImGuiMultiSelectFlags_ScopeWindow;
|
||||||
if (ImGui::CheckboxFlags("ImGuiMultiSelectFlags_SelectOnAuto", &flags, ImGuiMultiSelectFlags_SelectOnAuto))
|
if (ImGui::CheckboxFlags("ImGuiMultiSelectFlags_SelectOnAuto", &flags, ImGuiMultiSelectFlags_SelectOnAuto))
|
||||||
flags &= ~(ImGuiMultiSelectFlags_SelectOnMask_ ^ ImGuiMultiSelectFlags_SelectOnAuto);
|
flags &= ~(ImGuiMultiSelectFlags_SelectOnMask_ ^ ImGuiMultiSelectFlags_SelectOnAuto);
|
||||||
|
ImGui::SameLine(); HelpMarker("Apply selection on mouse down when clicking on unselected item, on mouse up when clicking on selected item. (Default)");
|
||||||
|
if (ImGui::CheckboxFlags("ImGuiMultiSelectFlags_SelectOnClickAlways", &flags, ImGuiMultiSelectFlags_SelectOnClickAlways))
|
||||||
|
flags &= ~(ImGuiMultiSelectFlags_SelectOnMask_ ^ ImGuiMultiSelectFlags_SelectOnClickAlways);
|
||||||
|
ImGui::SameLine(); HelpMarker("Prevents Drag and Drop from being used on multi-selection, but allows e.g. BoxSelect to always reselect even when clicking inside an existing selection. (Excel style behavior)");
|
||||||
if (ImGui::CheckboxFlags("ImGuiMultiSelectFlags_SelectOnClickRelease", &flags, ImGuiMultiSelectFlags_SelectOnClickRelease))
|
if (ImGui::CheckboxFlags("ImGuiMultiSelectFlags_SelectOnClickRelease", &flags, ImGuiMultiSelectFlags_SelectOnClickRelease))
|
||||||
flags &= ~(ImGuiMultiSelectFlags_SelectOnMask_ ^ ImGuiMultiSelectFlags_SelectOnClickRelease);
|
flags &= ~(ImGuiMultiSelectFlags_SelectOnMask_ ^ ImGuiMultiSelectFlags_SelectOnClickRelease);
|
||||||
ImGui::SameLine(); HelpMarker("Allow dragging an unselected item without altering selection.");
|
ImGui::SameLine(); HelpMarker("Allow dragging an unselected item without altering selection.");
|
||||||
@@ -10716,8 +10720,9 @@ struct ExampleAssetsBrowser
|
|||||||
// Options
|
// Options
|
||||||
bool ShowTypeOverlay = true;
|
bool ShowTypeOverlay = true;
|
||||||
bool AllowSorting = true;
|
bool AllowSorting = true;
|
||||||
bool AllowDragUnselected = false;
|
bool AllowBoxSelect = true; // Will set ImGuiMultiSelectFlags_BoxSelect2d
|
||||||
bool AllowBoxSelect = true;
|
bool AllowBoxSelectInsideSelection = false; // Will set ImGuiMultiSelectFlags_SelectOnClickAlways
|
||||||
|
bool AllowDragUnselected = false; // Will set ImGuiMultiSelectFlags_SelectOnClickRelease
|
||||||
float IconSize = 32.0f;
|
float IconSize = 32.0f;
|
||||||
int IconSpacing = 10;
|
int IconSpacing = 10;
|
||||||
int IconHitSpacing = 4; // Increase hit-spacing if you want to make it possible to clear or box-select from gaps. Some spacing is required to able to amend with Shift+box-select. Value is small in Explorer.
|
int IconHitSpacing = 4; // Increase hit-spacing if you want to make it possible to clear or box-select from gaps. Some spacing is required to able to amend with Shift+box-select. Value is small in Explorer.
|
||||||
@@ -10822,8 +10827,11 @@ struct ExampleAssetsBrowser
|
|||||||
ImGui::Checkbox("Allow Sorting", &AllowSorting);
|
ImGui::Checkbox("Allow Sorting", &AllowSorting);
|
||||||
|
|
||||||
ImGui::SeparatorText("Selection Behavior");
|
ImGui::SeparatorText("Selection Behavior");
|
||||||
ImGui::Checkbox("Allow dragging unselected item", &AllowDragUnselected);
|
|
||||||
ImGui::Checkbox("Allow box-selection", &AllowBoxSelect);
|
ImGui::Checkbox("Allow box-selection", &AllowBoxSelect);
|
||||||
|
if (ImGui::Checkbox("Allow box-selection from selected items", &AllowBoxSelectInsideSelection) && AllowBoxSelectInsideSelection)
|
||||||
|
AllowDragUnselected = false;
|
||||||
|
if (ImGui::Checkbox("Allow dragging unselected item", &AllowDragUnselected) && AllowDragUnselected)
|
||||||
|
AllowBoxSelectInsideSelection = false;
|
||||||
|
|
||||||
ImGui::SeparatorText("Layout");
|
ImGui::SeparatorText("Layout");
|
||||||
ImGui::SliderFloat("Icon Size", &IconSize, 16.0f, 128.0f, "%.0f");
|
ImGui::SliderFloat("Icon Size", &IconSize, 16.0f, 128.0f, "%.0f");
|
||||||
@@ -10879,9 +10887,11 @@ struct ExampleAssetsBrowser
|
|||||||
if (AllowBoxSelect)
|
if (AllowBoxSelect)
|
||||||
ms_flags |= ImGuiMultiSelectFlags_BoxSelect2d;
|
ms_flags |= ImGuiMultiSelectFlags_BoxSelect2d;
|
||||||
|
|
||||||
// - This feature allows dragging an unselected item without selecting it (rarely used)
|
// - Selection mode
|
||||||
if (AllowDragUnselected)
|
if (AllowDragUnselected)
|
||||||
ms_flags |= ImGuiMultiSelectFlags_SelectOnClickRelease;
|
ms_flags |= ImGuiMultiSelectFlags_SelectOnClickRelease; // Rarely used: Allows dragging an unselected item without selecting it(rarely used)
|
||||||
|
else if (AllowBoxSelectInsideSelection)
|
||||||
|
ms_flags |= ImGuiMultiSelectFlags_SelectOnClickAlways; // Rarely used: Prevents Drag and Drop from being used on multiple-selection, but allows e.g. BoxSelect to always reselect even when clicking inside an existing selection.
|
||||||
|
|
||||||
// - Enable keyboard wrapping on X axis
|
// - 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:
|
// (FIXME-MULTISELECT: We haven't designed/exposed a general nav wrapping api yet, so this flag is provided as a courtesy to avoid doing:
|
||||||
|
|||||||
@@ -8170,10 +8170,13 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected, ImGuiButtonFlags
|
|||||||
{
|
{
|
||||||
ImGuiButtonFlags button_flags = *p_button_flags;
|
ImGuiButtonFlags button_flags = *p_button_flags;
|
||||||
button_flags |= ImGuiButtonFlags_NoHoveredOnFocus;
|
button_flags |= ImGuiButtonFlags_NoHoveredOnFocus;
|
||||||
if ((!selected || (g.ActiveId == id && g.ActiveIdHasBeenPressedBefore)) && !(ms->Flags & ImGuiMultiSelectFlags_SelectOnClickRelease))
|
button_flags &= ~(ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickRelease);
|
||||||
button_flags = (button_flags | ImGuiButtonFlags_PressedOnClick) & ~ImGuiButtonFlags_PressedOnClickRelease;
|
if (ms->Flags & ImGuiMultiSelectFlags_SelectOnClickAlways)
|
||||||
else
|
button_flags |= ImGuiButtonFlags_PressedOnClick;
|
||||||
|
else if (ms->Flags & ImGuiMultiSelectFlags_SelectOnClickRelease)
|
||||||
button_flags |= ImGuiButtonFlags_PressedOnClickRelease;
|
button_flags |= ImGuiButtonFlags_PressedOnClickRelease;
|
||||||
|
else // ImGuiMultiSelectFlags_SelectOnAuto
|
||||||
|
button_flags |= (!selected || (g.ActiveId == id && g.ActiveIdHasBeenPressedBefore)) ? ImGuiButtonFlags_PressedOnClick : ImGuiButtonFlags_PressedOnClickRelease;
|
||||||
*p_button_flags = button_flags;
|
*p_button_flags = button_flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user