Skip to content

Commit a7a25ee

Browse files
committed
Tools: Item Picker: Mouse button can be changed by holding Ctrl+Shift. (ocornut#2673)
1 parent 92d0924 commit a7a25ee

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Other Changes:
4343
Enter keep the input active and select all text.
4444
- Nav: Fixed moving/resizing window with gamepad or keyboard when running at very high framerate.
4545
- Misc: io.Framerate moving average now converge in 60 frames instead of 120. (#5236, #4138)
46+
- Tools: Item Picker: Mouse button can be changed by holding Ctrl+Shift, making it easier
47+
to use the Item Picker in e.g. menus. (#2673)
4648
- Backends: Metal: Use __bridge for ARC based systems. (#5403) [@stack]
4749
- Backends: Metal: Add dispatch synchronization. (#5447) [@luigifcruz]
4850
- Backends: OSX: Fixes to support full app creation in C++. (#5403) [@stack]

imgui.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -13229,16 +13229,24 @@ void ImGui::UpdateDebugToolItemPicker()
1322913229
SetMouseCursor(ImGuiMouseCursor_Hand);
1323013230
if (IsKeyPressed(ImGuiKey_Escape))
1323113231
g.DebugItemPickerActive = false;
13232-
if (IsMouseClicked(0) && hovered_id)
13232+
const bool change_mapping = g.IO.KeyMods == (ImGuiModFlags_Ctrl | ImGuiModFlags_Shift);
13233+
if (!change_mapping && IsMouseClicked(g.DebugItemPickerMouseButton) && hovered_id)
1323313234
{
1323413235
g.DebugItemPickerBreakId = hovered_id;
1323513236
g.DebugItemPickerActive = false;
1323613237
}
13237-
SetNextWindowBgAlpha(0.60f);
13238+
for (int mouse_button = 0; mouse_button < 3; mouse_button++)
13239+
if (change_mapping && IsMouseClicked(mouse_button))
13240+
g.DebugItemPickerMouseButton = (ImU8)mouse_button;
13241+
SetNextWindowBgAlpha(0.70f);
1323813242
BeginTooltip();
1323913243
Text("HoveredId: 0x%08X", hovered_id);
1324013244
Text("Press ESC to abort picking.");
13241-
TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click to break in debugger!");
13245+
const char* mouse_button_names[] = { "Left", "Right", "Middle" };
13246+
if (change_mapping)
13247+
Text("Remap w/ Ctrl+Shift: click anywhere to select new mouse button.");
13248+
else
13249+
TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click %s Button to break in debugger! (remap w/ Ctrl+Shift)", mouse_button_names[g.DebugItemPickerMouseButton]);
1324213250
EndTooltip();
1324313251
}
1324413252

imgui_demo.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -7805,7 +7805,8 @@ void ShowExampleAppDocuments(bool* p_open)
78057805
if (ImGui::MenuItem("Close All Documents", NULL, false, open_count > 0))
78067806
for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++)
78077807
app.Documents[doc_n].DoQueueClose();
7808-
if (ImGui::MenuItem("Exit", "Alt+F4")) {}
7808+
if (ImGui::MenuItem("Exit", "Ctrl+F4") && p_open)
7809+
*p_open = false;
78097810
ImGui::EndMenu();
78107811
}
78117812
ImGui::EndMenuBar();

imgui_internal.h

+2
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,7 @@ struct ImGuiContext
18221822
ImGuiDebugLogFlags DebugLogFlags;
18231823
ImGuiTextBuffer DebugLogBuf;
18241824
bool DebugItemPickerActive; // Item picker is active (started with DebugStartItemPicker())
1825+
ImU8 DebugItemPickerMouseButton;
18251826
ImGuiID DebugItemPickerBreakId; // Will call IM_DEBUG_BREAK() when encountering this ID
18261827
ImGuiMetricsConfig DebugMetricsConfig;
18271828
ImGuiStackTool DebugStackTool;
@@ -1979,6 +1980,7 @@ struct ImGuiContext
19791980

19801981
DebugLogFlags = ImGuiDebugLogFlags_OutputToTTY;
19811982
DebugItemPickerActive = false;
1983+
DebugItemPickerMouseButton = ImGuiMouseButton_Left;
19821984
DebugItemPickerBreakId = 0;
19831985

19841986
memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));

0 commit comments

Comments
 (0)