fix: handle more weird wrapping stuff

This commit is contained in:
Anna
2022-02-16 15:15:10 -05:00
parent 3e7ba56c17
commit 259000d92a
2 changed files with 25 additions and 11 deletions
+8 -6
View File
@@ -671,13 +671,15 @@ internal sealed class ChatLog : IUiComponent {
ImGui.TableNextColumn();
}
var lineWidth = ImGui.GetContentRegionAvail().X;
var beforeDraw = ImGui.GetCursorScreenPos();
if (message.Sender.Count > 0) {
this.DrawChunks(message.Sender, true, this.PayloadHandler);
this.DrawChunks(message.Sender, true, this.PayloadHandler, lineWidth);
ImGui.SameLine();
}
this.DrawChunks(message.Content, true, this.PayloadHandler);
this.DrawChunks(message.Content, true, this.PayloadHandler, lineWidth);
var afterDraw = ImGui.GetCursorScreenPos();
message.Height = ImGui.GetCursorPosY() - lastPos;
@@ -918,7 +920,7 @@ internal sealed class ChatLog : IUiComponent {
return 0;
}
internal void DrawChunks(IReadOnlyList<Chunk> chunks, bool wrap = true, PayloadHandler? handler = null) {
internal void DrawChunks(IReadOnlyList<Chunk> chunks, bool wrap = true, PayloadHandler? handler = null, float lineWidth = 0f) {
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
try {
for (var i = 0; i < chunks.Count; i++) {
@@ -926,7 +928,7 @@ internal sealed class ChatLog : IUiComponent {
continue;
}
this.DrawChunk(chunks[i], wrap, handler);
this.DrawChunk(chunks[i], wrap, handler, lineWidth);
if (i < chunks.Count - 1) {
ImGui.SameLine();
@@ -937,7 +939,7 @@ internal sealed class ChatLog : IUiComponent {
}
}
private void DrawChunk(Chunk chunk, bool wrap = true, PayloadHandler? handler = null) {
private void DrawChunk(Chunk chunk, bool wrap = true, PayloadHandler? handler = null, float lineWidth = 0f) {
if (chunk is IconChunk icon && this._fontIcon != null) {
var bounds = IconUtil.GetBounds((byte) icon.Icon);
if (bounds != null) {
@@ -988,7 +990,7 @@ internal sealed class ChatLog : IUiComponent {
}
if (wrap) {
ImGuiUtil.WrapText(content, chunk, handler, this.Ui.DefaultText);
ImGuiUtil.WrapText(content, chunk, handler, this.Ui.DefaultText, lineWidth);
} else {
ImGui.TextUnformatted(content);
ImGuiUtil.PostPayload(chunk, handler);