From 91a0be2d78af80cd9cb72db1ee95b4fbf921f7e6 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 24 Jun 2024 23:01:46 +0200 Subject: [PATCH] impr: Better UI/UX for interactive help --- lib/libimhex/source/api/tutorial_manager.cpp | 26 +++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/libimhex/source/api/tutorial_manager.cpp b/lib/libimhex/source/api/tutorial_manager.cpp index fcb2cb474..825d57388 100644 --- a/lib/libimhex/source/api/tutorial_manager.cpp +++ b/lib/libimhex/source/api/tutorial_manager.cpp @@ -142,20 +142,28 @@ namespace hex { } void TutorialManager::drawHighlights() { - if (s_helpHoverActive && s_hoveredId != 0) { - ImGui::GetForegroundDrawList()->AddRectFilled(s_hoveredRect.Min, s_hoveredRect.Max, 0x30FFFFFF); + if (s_helpHoverActive) { + const auto &drawList = ImGui::GetForegroundDrawList(); + drawList->AddText(ImGui::GetMousePos() + scaled({ 10, -5, }), ImGui::GetColorU32(ImGuiCol_Text), "?"); - if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - s_helpHoverActive = false; + const bool mouseClicked = ImGui::IsMouseClicked(ImGuiMouseButton_Left); + if (s_hoveredId != 0) { + drawList->AddRectFilled(s_hoveredRect.Min, s_hoveredRect.Max, 0x30FFFFFF); - auto it = s_interactiveHelpItems->find(s_hoveredId); - if (it != s_interactiveHelpItems->end()) { - it->second(); + if (mouseClicked) { + auto it = s_interactiveHelpItems->find(s_hoveredId); + if (it != s_interactiveHelpItems->end()) { + it->second(); + } } + + s_hoveredId = 0; + s_hoveredRect = {}; } - s_hoveredId = 0; - s_hoveredRect = {}; + if (mouseClicked || ImGui::IsKeyPressed(ImGuiKey_Escape)) { + s_helpHoverActive = false; + } } for (const auto &[rect, unlocalizedText] : *s_highlightDisplays) {