feat: implement janky clipping
This commit is contained in:
parent
7204e66a13
commit
6f14bad62c
|
@ -4,6 +4,8 @@ namespace ChatTwo;
|
||||||
|
|
||||||
internal class Message {
|
internal class Message {
|
||||||
internal ulong ContentId;
|
internal ulong ContentId;
|
||||||
|
internal float? Height;
|
||||||
|
internal bool IsVisible;
|
||||||
|
|
||||||
internal DateTime Date { get; }
|
internal DateTime Date { get; }
|
||||||
internal ChatCode Code { get; }
|
internal ChatCode Code { get; }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Numerics;
|
using System.Diagnostics;
|
||||||
|
using System.Numerics;
|
||||||
using ChatTwo.Code;
|
using ChatTwo.Code;
|
||||||
using ChatTwo.GameFunctions.Types;
|
using ChatTwo.GameFunctions.Types;
|
||||||
using ChatTwo.Util;
|
using ChatTwo.Util;
|
||||||
|
@ -27,6 +28,8 @@ internal sealed class ChatLog : IUiComponent {
|
||||||
private int _lastTab;
|
private int _lastTab;
|
||||||
private InputChannel? _tempChannel;
|
private InputChannel? _tempChannel;
|
||||||
private TellTarget? _tellTarget;
|
private TellTarget? _tellTarget;
|
||||||
|
private Vector2 _lastWindowSize = Vector2.Zero;
|
||||||
|
private readonly Stopwatch _lastResize = new();
|
||||||
|
|
||||||
private PayloadHandler PayloadHandler { get; }
|
private PayloadHandler PayloadHandler { get; }
|
||||||
private Dictionary<string, ChatType> TextCommandChannels { get; } = new();
|
private Dictionary<string, ChatType> TextCommandChannels { get; } = new();
|
||||||
|
@ -258,6 +261,13 @@ internal sealed class ChatLog : IUiComponent {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resized = this._lastWindowSize != ImGui.GetWindowSize();
|
||||||
|
this._lastWindowSize = ImGui.GetWindowSize();
|
||||||
|
|
||||||
|
if (resized) {
|
||||||
|
this._lastResize.Restart();
|
||||||
|
}
|
||||||
|
|
||||||
this._lastViewport = ImGui.GetWindowViewport().NativePtr;
|
this._lastViewport = ImGui.GetWindowViewport().NativePtr;
|
||||||
|
|
||||||
var currentTab = this.Ui.Plugin.Config.SidebarTabView
|
var currentTab = this.Ui.Plugin.Config.SidebarTabView
|
||||||
|
@ -446,14 +456,42 @@ internal sealed class ChatLog : IUiComponent {
|
||||||
ImGui.TableSetupColumn("messages", ImGuiTableColumnFlags.WidthStretch);
|
ImGui.TableSetupColumn("messages", ImGuiTableColumnFlags.WidthStretch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper());
|
|
||||||
// int numMessages;
|
|
||||||
try {
|
try {
|
||||||
tab.MessagesMutex.WaitOne();
|
tab.MessagesMutex.WaitOne();
|
||||||
|
|
||||||
for (var i = 0; i < tab.Messages.Count; i++) {
|
var reset = false;
|
||||||
// numDrawn += 1;
|
if (this._lastResize.IsRunning && this._lastResize.Elapsed.TotalSeconds > 0.25) {
|
||||||
var message = tab.Messages[i];
|
this._lastResize.Stop();
|
||||||
|
this._lastResize.Reset();
|
||||||
|
reset = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastPos = ImGui.GetCursorPosY();
|
||||||
|
foreach (var message in tab.Messages) {
|
||||||
|
if (reset) {
|
||||||
|
message.Height = null;
|
||||||
|
message.IsVisible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// message has rendered once
|
||||||
|
if (message.Height.HasValue) {
|
||||||
|
// message isn't visible, so render dummy
|
||||||
|
if (!message.IsVisible) {
|
||||||
|
// skip columns
|
||||||
|
if (table) {
|
||||||
|
if (tab.DisplayTimestamp) {
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.Dummy(new Vector2(1f, message.Height.Value));
|
||||||
|
message.IsVisible = ImGui.IsItemVisible();
|
||||||
|
|
||||||
|
goto UpdateMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tab.DisplayTimestamp) {
|
if (tab.DisplayTimestamp) {
|
||||||
var timestamp = message.Date.ToLocalTime().ToString("t");
|
var timestamp = message.Date.ToLocalTime().ToString("t");
|
||||||
|
@ -472,34 +510,27 @@ internal sealed class ChatLog : IUiComponent {
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var beforeDraw = ImGui.GetCursorScreenPos();
|
||||||
if (message.Sender.Count > 0) {
|
if (message.Sender.Count > 0) {
|
||||||
this.DrawChunks(message.Sender, true, this.PayloadHandler);
|
this.DrawChunks(message.Sender, true, this.PayloadHandler);
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.DrawChunks(message.Content, true, this.PayloadHandler);
|
this.DrawChunks(message.Content, true, this.PayloadHandler);
|
||||||
|
var afterDraw = ImGui.GetCursorScreenPos();
|
||||||
|
|
||||||
// drawnHeight += ImGui.GetCursorPosY() - lastPos;
|
message.Height = ImGui.GetCursorPosY() - lastPos;
|
||||||
// lastPos = ImGui.GetCursorPosY();
|
message.IsVisible = ImGui.IsRectVisible(beforeDraw, afterDraw);
|
||||||
|
|
||||||
|
UpdateMessage:
|
||||||
|
lastPos = ImGui.GetCursorPosY();
|
||||||
}
|
}
|
||||||
|
|
||||||
// numMessages = tab.Messages.Count;
|
|
||||||
// may render too many items, but this is easier
|
|
||||||
// clipper.Begin(numMessages, lineHeight + ImGui.GetStyle().ItemSpacing.Y);
|
|
||||||
// while (clipper.Step()) {
|
|
||||||
// }
|
|
||||||
} finally {
|
} finally {
|
||||||
tab.MessagesMutex.ReleaseMutex();
|
tab.MessagesMutex.ReleaseMutex();
|
||||||
ImGui.PopStyleVar(this.Ui.Plugin.Config.MoreCompactPretty ? 2 : 1);
|
ImGui.PopStyleVar(this.Ui.Plugin.Config.MoreCompactPretty ? 2 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginLog.Log($"numDrawn: {numDrawn}");
|
|
||||||
|
|
||||||
if (switchedTab || ImGui.GetScrollY() >= ImGui.GetScrollMaxY()) {
|
if (switchedTab || ImGui.GetScrollY() >= ImGui.GetScrollMaxY()) {
|
||||||
// PluginLog.Log($"drawnHeight: {drawnHeight}");
|
|
||||||
// var itemPosY = clipper.StartPosY + drawnHeight;
|
|
||||||
// PluginLog.Log($"itemPosY: {itemPosY}");
|
|
||||||
// ImGui.SetScrollFromPosY(itemPosY - ImGui.GetWindowPos().Y);
|
|
||||||
ImGui.SetScrollHereY(1f);
|
ImGui.SetScrollHereY(1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user