From 35334333ac505a7f9169435537d0d0afbfa9f0aa Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 8 Jan 2022 00:46:16 +1100 Subject: [PATCH] [client] imgui: render twice for alerts When using jitRender, or on the first frame of an alert the window doesn't get resized immediately causing it to cut off the end of the text. ImGui needs two passes to calulate the bounding box for automatically sized windows, this is per it's design and not a bug, see: https://github.com/ocornut/imgui/issues/2158#issuecomment-434223618 --- client/src/app.c | 14 ++++++++++++++ client/src/main.h | 1 + 2 files changed, 15 insertions(+) diff --git a/client/src/app.c b/client/src/app.c index 1b2b9a0e..90fa637a 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -637,6 +637,8 @@ void app_alert(LG_MsgAlert type, const char * fmt, ...) g_state.alertTimeout = microtime() + ALERT_TIMEOUT; g_state.alertType = type; g_state.alertShow = true; + + g_state.renderImGuiTwice = true; app_invalidateWindow(false); } @@ -803,6 +805,8 @@ int app_renderOverlay(struct Rect * rects, int maxRects) g_state.io->DeltaTime = (now - g_state.lastImGuiFrame) * 1e-9f; g_state.lastImGuiFrame = now; +render_again: + igNewFrame(); if (g_state.overlayInput) @@ -871,6 +875,16 @@ int app_renderOverlay(struct Rect * rects, int maxRects) igRender(); + /* imgui requires two passes to calculate the bounding box of auto sized + * windows, this is by design + * ref: https://github.com/ocornut/imgui/issues/2158#issuecomment-434223618 + */ + if (g_state.renderImGuiTwice) + { + g_state.renderImGuiTwice = false; + goto render_again; + } + return totalDamage ? -1 : totalRects; } diff --git a/client/src/main.h b/client/src/main.h index 2e609771..0e126ade 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -61,6 +61,7 @@ struct AppState bool modAlt; bool modSuper; uint64_t lastImGuiFrame; + bool renderImGuiTwice; bool alertShow; char * alertMessage;