fix: handle more weird wrapping stuff
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -39,7 +39,7 @@ internal static class ImGuiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void WrapText(string csText, Chunk chunk, PayloadHandler? handler, Vector4 defaultText) {
|
||||
internal static unsafe void WrapText(string csText, Chunk chunk, PayloadHandler? handler, Vector4 defaultText, float lineWidth) {
|
||||
void Text(byte* text, byte* textEnd) {
|
||||
var oldPos = ImGui.GetCursorScreenPos();
|
||||
|
||||
@@ -96,7 +96,16 @@ internal static class ImGuiUtil {
|
||||
if (properBreak) {
|
||||
Text(text, endPrevLine);
|
||||
} else {
|
||||
if (lineWidth == 0f) {
|
||||
ImGui.TextUnformatted("");
|
||||
} else {
|
||||
// check if the next bit is longer than the entire line width
|
||||
var wrapPos = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, firstSpace, lineWidth);
|
||||
if (wrapPos >= firstSpace) {
|
||||
// only go to next line is it's going to wrap at the space
|
||||
ImGui.TextUnformatted("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
widthLeft = ImGui.GetContentRegionAvail().X;
|
||||
@@ -105,14 +114,12 @@ internal static class ImGuiUtil {
|
||||
text = endPrevLine;
|
||||
}
|
||||
|
||||
properBreak = true;
|
||||
|
||||
if (*text == ' ') {
|
||||
++text;
|
||||
} // skip a space at start of line
|
||||
|
||||
var newEnd = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, textEnd, widthLeft);
|
||||
if (newEnd == endPrevLine) {
|
||||
if (properBreak && newEnd == endPrevLine) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -124,6 +131,11 @@ internal static class ImGuiUtil {
|
||||
}
|
||||
|
||||
Text(text, endPrevLine);
|
||||
|
||||
if (!properBreak) {
|
||||
properBreak = true;
|
||||
widthLeft = ImGui.GetContentRegionAvail().X;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user