[client] imgui: implement new widget for displaying URLs

Note that actually opening the browser is not implemented yet.
This commit is contained in:
Quantum 2021-08-05 07:47:08 -04:00 committed by Geoffrey McRae
parent 2f8ebc29e8
commit 08f3ad504c
2 changed files with 40 additions and 0 deletions

View File

@ -21,11 +21,15 @@
#ifndef _H_LG_OVERLAY_UTILS_
#define _H_LG_OVERLAY_UTILS_
#include <stdbool.h>
#include "common/types.h"
typedef struct ImVec2 ImVec2;
void overlayGetImGuiRect(struct Rect * rect);
ImVec2 * overlayGetScreenSize(void);
void overlayTextURL(const char * url, const char * text);
void overlayTextMaybeURL(const char * text, bool wrapped);
#endif

View File

@ -20,6 +20,9 @@
#include "overlay_utils.h"
#include <string.h>
#include "common/open.h"
#include "cimgui.h"
#include "main.h"
@ -41,3 +44,36 @@ ImVec2 * overlayGetScreenSize(void)
{
return &g_state.io->DisplaySize;
}
static void overlayAddUnderline(ImU32 color)
{
ImVec2 min, max;
igGetItemRectMin(&min);
igGetItemRectMax(&max);
min.y = max.y;
ImDrawList_AddLine(igGetWindowDrawList(), min, max, color, 1.0f);
}
void overlayTextURL(const char * url, const char * text)
{
igText(text ? text : url);
if (igIsItemHovered(ImGuiHoveredFlags_None))
{
if (igIsItemClicked(ImGuiMouseButton_Left))
lgOpenURL(url);
overlayAddUnderline(igGetColorU32Vec4(*igGetStyleColorVec4(ImGuiCol_ButtonHovered)));
igSetMouseCursor(ImGuiMouseCursor_Hand);
igSetTooltip("Open in browser: %s", url);
}
}
void overlayTextMaybeURL(const char * text, bool wrapped)
{
if (strncmp(text, "https://", 8) == 0)
overlayTextURL(text, NULL);
else if (wrapped)
igTextWrapped(text);
else
igText(text);
}