Jelajahi Sumber

TextLinkOpenURL(): added bool return value on click. (#8645, #8451, #7660)

ocornut 2 bulan lalu
induk
melakukan
1ffa7a40ac
3 mengubah file dengan 7 tambahan dan 5 penghapusan
  1. 1 0
      docs/CHANGELOG.txt
  2. 1 1
      imgui.h
  3. 5 4
      imgui_widgets.cpp

+ 1 - 0
docs/CHANGELOG.txt

@@ -97,6 +97,7 @@ Other changes:
   which mitigates edge case issues in multi-viewport scenarios where abnormally large
   which mitigates edge case issues in multi-viewport scenarios where abnormally large
   windows (e.g. determined programmatically) can lead to renderer backend trying to
   windows (e.g. determined programmatically) can lead to renderer backend trying to
   create abnormally large framebuffers.
   create abnormally large framebuffers.
+- TextLinkOpenURL(): added bool return value on click. (#8645, #8451, #7660)
 - Nav: fixed assertion when holding gamepad FaceLeft/West button to open
 - Nav: fixed assertion when holding gamepad FaceLeft/West button to open
   CTRL+Tab windowing + pressing a keyboard key. (#8525)
   CTRL+Tab windowing + pressing a keyboard key. (#8525)
 - Error Handling: added better error report and recovery for extraneous
 - Error Handling: added better error report and recovery for extraneous

+ 1 - 1
imgui.h

@@ -559,7 +559,7 @@ namespace ImGui
     IMGUI_API void          ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-FLT_MIN, 0), const char* overlay = NULL);
     IMGUI_API void          ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-FLT_MIN, 0), const char* overlay = NULL);
     IMGUI_API void          Bullet();                                                       // draw a small circle + keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses
     IMGUI_API void          Bullet();                                                       // draw a small circle + keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses
     IMGUI_API bool          TextLink(const char* label);                                    // hyperlink text button, return true when clicked
     IMGUI_API bool          TextLink(const char* label);                                    // hyperlink text button, return true when clicked
-    IMGUI_API void          TextLinkOpenURL(const char* label, const char* url = NULL);     // hyperlink text button, automatically open file/url when clicked
+    IMGUI_API bool          TextLinkOpenURL(const char* label, const char* url = NULL);     // hyperlink text button, automatically open file/url when clicked
 
 
     // Widgets: Images
     // Widgets: Images
     // - Read about ImTextureID here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
     // - Read about ImTextureID here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples

+ 5 - 4
imgui_widgets.cpp

@@ -1529,14 +1529,14 @@ bool ImGui::TextLink(const char* label)
     return pressed;
     return pressed;
 }
 }
 
 
-void ImGui::TextLinkOpenURL(const char* label, const char* url)
+bool ImGui::TextLinkOpenURL(const char* label, const char* url)
 {
 {
     ImGuiContext& g = *GImGui;
     ImGuiContext& g = *GImGui;
     if (url == NULL)
     if (url == NULL)
         url = label;
         url = label;
-    if (TextLink(label))
-        if (g.PlatformIO.Platform_OpenInShellFn != NULL)
-            g.PlatformIO.Platform_OpenInShellFn(&g, url);
+    bool pressed = TextLink(label);
+    if (pressed && g.PlatformIO.Platform_OpenInShellFn != NULL)
+        g.PlatformIO.Platform_OpenInShellFn(&g, url);
     SetItemTooltip(LocalizeGetMsg(ImGuiLocKey_OpenLink_s), url); // It is more reassuring for user to _always_ display URL when we same as label
     SetItemTooltip(LocalizeGetMsg(ImGuiLocKey_OpenLink_s), url); // It is more reassuring for user to _always_ display URL when we same as label
     if (BeginPopupContextItem())
     if (BeginPopupContextItem())
     {
     {
@@ -1544,6 +1544,7 @@ void ImGui::TextLinkOpenURL(const char* label, const char* url)
             SetClipboardText(url);
             SetClipboardText(url);
         EndPopup();
         EndPopup();
     }
     }
+    return pressed;
 }
 }
 
 
 //-------------------------------------------------------------------------
 //-------------------------------------------------------------------------