Size the input preview correctly

This commit is contained in:
Infi
2024-05-15 21:30:55 +02:00
parent 3d9f5a2764
commit 3d249643f9
+8 -9
View File
@@ -1,3 +1,4 @@
using System.Numerics;
using System.Text; using System.Text;
using ChatTwo.Code; using ChatTwo.Code;
using ChatTwo.Util; using ChatTwo.Util;
@@ -20,7 +21,8 @@ public class InputPreview : Window
LogWindow = logWindow; LogWindow = logWindow;
Flags = ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoMove | Flags = ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoMove |
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.AlwaysAutoResize; ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoInputs;
RespectCloseHotkey = false; RespectCloseHotkey = false;
DisableWindowSounds = true; DisableWindowSounds = true;
@@ -39,7 +41,7 @@ public class InputPreview : Window
var width = LogWindow.LastWindowSize.X; var width = LogWindow.LastWindowSize.X;
var pos = LogWindow.LastWindowPos; var pos = LogWindow.LastWindowPos;
Size = LogWindow.LastWindowSize with { X = width }; Size = new Vector2(width, Height);
Position = pos with { Y = pos.Y - Height }; Position = pos with { Y = pos.Y - Height };
PositionCondition = ImGuiCond.Always; PositionCondition = ImGuiCond.Always;
@@ -52,18 +54,15 @@ public class InputPreview : Window
public override void Draw() public override void Draw()
{ {
var content = LogWindow.Chat.Trim(); var bytes = Encoding.UTF8.GetBytes(LogWindow.Chat.Trim());
var bytes = Encoding.UTF8.GetBytes(content);
AutoTranslate.ReplaceWithPayload(Plugin.DataManager, ref bytes); AutoTranslate.ReplaceWithPayload(Plugin.DataManager, ref bytes);
var seString = SeString.Parse(bytes); var chunks = ChunkUtil.ToChunks(SeString.Parse(bytes), ChunkSource.Content, ChatType.Say).ToList();
var chunks = ChunkUtil.ToChunks(seString, ChunkSource.Content, ChatType.Say).ToList();
var encodedChunks = Message.FakeMessage(chunks, new ChatCode((ushort) XivChatType.Say)); var encodedChunks = Message.FakeMessage(chunks, new ChatCode((ushort) XivChatType.Say));
var before = ImGui.GetCursorPosY();
LogWindow.DrawChunks(encodedChunks.Content); LogWindow.DrawChunks(encodedChunks.Content);
var after = ImGui.GetCursorPosY();
Height = after - before + ImGui.GetStyle().WindowPadding.Y; // WindowPadding applies to top and bottom, so we take it 2 times
Height = ImGui.GetCursorPosY() + ImGui.GetStyle().WindowPadding.Y * 2;
} }
} }