Fixed certain scenario that could break the event viewer

This commit is contained in:
cake
2025-12-15 19:37:22 +01:00
parent 44e91bef8f
commit ee1fcb5661
2 changed files with 42 additions and 16 deletions

View File

@@ -205,17 +205,37 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
var posX = ImGui.GetCursorPosX();
var maxTextLength = ImGui.GetWindowContentRegionMax().X - posX;
var textSize = ImGui.CalcTextSize(ev.Message).X;
var msg = ev.Message;
while (textSize > maxTextLength)
var msg = ev.Message ?? string.Empty;
var maxEventTextLength = ImGui.GetContentRegionAvail().X;
if (maxEventTextLength <= 0f)
{
msg = msg[..^5] + "...";
textSize = ImGui.CalcTextSize(msg).X;
ImGui.TextUnformatted(string.Empty);
return;
}
var eventTextSize = ImGui.CalcTextSize(msg).X;
if (eventTextSize > maxEventTextLength)
{
const string ellipsis = "...";
while (eventTextSize > maxTextLength && msg.Length > ellipsis.Length)
{
var cut = Math.Min(5, msg.Length - ellipsis.Length);
msg = msg[..^cut] + ellipsis;
eventTextSize = ImGui.CalcTextSize(msg).X;
}
if (textSize > maxEventTextLength)
msg = ellipsis;
}
ImGui.TextUnformatted(msg);
if (!string.Equals(msg, ev.Message, StringComparison.Ordinal))
{
UiSharedService.AttachToolTip(ev.Message);
}
}
}
}