Skip to content

Commit

Permalink
Tools: Item Picker: Mouse button can be changed by holding Ctrl+Shift. (
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Jul 7, 2022
1 parent 92d0924 commit 19444d0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Other Changes:
Enter keep the input active and select all text.
- Nav: Fixed moving/resizing window with gamepad or keyboard when running at very high framerate.
- Misc: io.Framerate moving average now converge in 60 frames instead of 120. (#5236, #4138)
- Tools: Item Picker: Mouse button can be changed by holding Ctrl+Shift, making it easier
to use the Item Picker in e.g. menus. (#2673)
- Backends: Metal: Use __bridge for ARC based systems. (#5403) [@stack]
- Backends: Metal: Add dispatch synchronization. (#5447) [@luigifcruz]
- Backends: OSX: Fixes to support full app creation in C++. (#5403) [@stack]
Expand Down
14 changes: 11 additions & 3 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13229,16 +13229,24 @@ void ImGui::UpdateDebugToolItemPicker()
SetMouseCursor(ImGuiMouseCursor_Hand);
if (IsKeyPressed(ImGuiKey_Escape))
g.DebugItemPickerActive = false;
if (IsMouseClicked(0) && hovered_id)
const bool change_mapping = g.IO.KeyMods == (ImGuiKeyModFlags_Ctrl | ImGuiKeyModFlags_Shift);
if (!change_mapping && IsMouseClicked(g.DebugItemPickerMouseButton) && hovered_id)
{
g.DebugItemPickerBreakId = hovered_id;
g.DebugItemPickerActive = false;
}
SetNextWindowBgAlpha(0.60f);
for (int mouse_button = 0; mouse_button < 3; mouse_button++)
if (change_mapping && IsMouseClicked(mouse_button))
g.DebugItemPickerMouseButton = (ImU8)mouse_button;
SetNextWindowBgAlpha(0.70f);
BeginTooltip();
Text("HoveredId: 0x%08X", hovered_id);
Text("Press ESC to abort picking.");
TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click to break in debugger!");
const char* mouse_button_names[] = { "Left", "Right", "Middle" };
if (change_mapping)
Text("Remap w/ Ctrl+Shift: click anywhere to select new mouse button.");
else
TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click %s Button to break in debugger! (remap w/ Ctrl+Shift)", mouse_button_names[g.DebugItemPickerMouseButton]);
EndTooltip();
}

Expand Down
3 changes: 2 additions & 1 deletion imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7805,7 +7805,8 @@ void ShowExampleAppDocuments(bool* p_open)
if (ImGui::MenuItem("Close All Documents", NULL, false, open_count > 0))
for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++)
app.Documents[doc_n].DoQueueClose();
if (ImGui::MenuItem("Exit", "Alt+F4")) {}
if (ImGui::MenuItem("Exit", "Ctrl+F4") && p_open)
*p_open = false;
ImGui::EndMenu();
}
ImGui::EndMenuBar();
Expand Down
2 changes: 2 additions & 0 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ struct ImGuiContext
ImGuiDebugLogFlags DebugLogFlags;
ImGuiTextBuffer DebugLogBuf;
bool DebugItemPickerActive; // Item picker is active (started with DebugStartItemPicker())
ImU8 DebugItemPickerMouseButton;
ImGuiID DebugItemPickerBreakId; // Will call IM_DEBUG_BREAK() when encountering this ID
ImGuiMetricsConfig DebugMetricsConfig;
ImGuiStackTool DebugStackTool;
Expand Down Expand Up @@ -1979,6 +1980,7 @@ struct ImGuiContext

DebugLogFlags = ImGuiDebugLogFlags_OutputToTTY;
DebugItemPickerActive = false;
DebugItemPickerMouseButton = ImGuiMouseButton_Left;
DebugItemPickerBreakId = 0;

memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
Expand Down

0 comments on commit 19444d0

Please sign in to comment.