Fixed certain scenario that could break the event viewer
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user