Merge pull request #41

fix: no more jitter 2
This commit is contained in:
Infi
2024-05-11 00:33:52 +02:00
committed by GitHub
+22 -17
View File
@@ -898,7 +898,7 @@ public sealed class ChatLogWindow : Window
reset = true; reset = true;
} }
var lastPos = ImGui.GetCursorPosY(); var lastPosY = ImGui.GetCursorPosY();
var lastTimestamp = string.Empty; var lastTimestamp = string.Empty;
int? lastMessageHash = null; int? lastMessageHash = null;
var sameCount = 0; var sameCount = 0;
@@ -921,6 +921,7 @@ public sealed class ChatLogWindow : Window
if (same) if (same)
{ {
sameCount += 1; sameCount += 1;
message.IsVisible[tab.Identifier] = false;
if (i != tab.Messages.Count - 1) if (i != tab.Messages.Count - 1)
continue; continue;
} }
@@ -946,6 +947,25 @@ public sealed class ChatLogWindow : Window
if (isTable) if (isTable)
ImGui.TableNextColumn(); ImGui.TableNextColumn();
// Set the height of the previous message. `lastPosY` is set to
// the top of the previous message, and the current cursor is at
// the top of the current message.
if (i > 0)
{
var prevMessage = tab.Messages[i - 1];
if (prevMessage.IsVisible.TryGetValue(tab.Identifier, out var prevVisible) && prevVisible)
{
var newHeight = ImGui.GetCursorPosY() - lastPosY;
if (isTable && !moreCompact)
// Remove the padding from the bottom of the
// previous row and the top of the current row.
newHeight -= oldCellPaddingY * 2;
if (newHeight != 0)
prevMessage.Height[tab.Identifier] = newHeight;
}
}
lastPosY = ImGui.GetCursorPosY();
// message has rendered once // message has rendered once
// message isn't visible, so render dummy // message isn't visible, so render dummy
message.Height.TryGetValue(tab.Identifier, out var height); message.Height.TryGetValue(tab.Identifier, out var height);
@@ -969,10 +989,7 @@ public sealed class ChatLogWindow : Window
ImGui.SetCursorPos(beforeDummy); ImGui.SetCursorPos(beforeDummy);
} }
else else
{
lastPos = ImGui.GetCursorPosY();
continue; continue;
}
} }
if (tab.DisplayTimestamp) if (tab.DisplayTimestamp)
@@ -1010,19 +1027,7 @@ public sealed class ChatLogWindow : Window
else else
DrawChunks(message.Content, true, handler, lineWidth); DrawChunks(message.Content, true, handler, lineWidth);
message.Height[tab.Identifier] = ImGui.GetCursorPosY() - lastPos; message.IsVisible[tab.Identifier] = ImGui.IsItemVisible();
if (isTable && !moreCompact)
message.Height[tab.Identifier] -= oldCellPaddingY * 2;
var itemVisible = ImGui.IsItemVisible();
message.IsVisible[tab.Identifier] = itemVisible;
if (itemVisible && i < tab.Messages.Count - 1)
// If this message is visible, the next message should also
// be visible. This helps alleviate jittering issues when
// scrolling down.
tab.Messages[i + 1].IsVisible[tab.Identifier] = true;
lastPos = ImGui.GetCursorPosY();
} }
} }
finally finally