Add clickable links to community macros

This commit is contained in:
Asriel Camora
2024-02-27 04:07:39 -08:00
parent 7e1ba4feb8
commit 0d2c811c91
3 changed files with 33 additions and 4 deletions
+7 -3
View File
@@ -569,16 +569,20 @@ internal static class ImGuiUtils
}
// https://gist.github.com/dougbinks/ef0962ef6ebe2cadae76c4e9f0586c69#file-imguiutils-h-L228
public static unsafe void Hyperlink(string text, string url)
public static unsafe void Hyperlink(string text, string url, bool underline = true)
{
ImGui.TextUnformatted(text);
UnderlineLastItem(*ImGui.GetStyleColorVec4(ImGuiCol.Text));
if (underline)
UnderlineLastItem(*ImGui.GetStyleColorVec4(ImGuiCol.Text));
if (ImGui.IsItemHovered())
{
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true });
Tooltip("Open in Browser");
var urlWithoutScheme = url;
if (Uri.TryCreate(url, UriKind.Absolute, out var uri))
urlWithoutScheme = uri.Host + (string.Equals(uri.PathAndQuery, "/", StringComparison.Ordinal) ? string.Empty : uri.PathAndQuery);
Tooltip(urlWithoutScheme);
}
}