Configurable position for the preview

This commit is contained in:
Infi
2024-05-15 23:41:22 +02:00
parent d49e2736b6
commit b08c858364
6 changed files with 133 additions and 15 deletions
+2 -2
View File
@@ -521,7 +521,7 @@ public sealed class ChatLogWindow : Window
// TODO: I hate this predraw thing
PreviewHeight = 0;
Message? predrawnMessage = null;
if (!string.IsNullOrEmpty(Chat))
if (Plugin.Config.PreviewPosition is PreviewPosition.Inside && !string.IsNullOrEmpty(Chat))
{
var bytes = Encoding.UTF8.GetBytes(Chat.Trim());
AutoTranslate.ReplaceWithPayload(Plugin.DataManager, ref bytes);
@@ -534,7 +534,7 @@ public sealed class ChatLogWindow : Window
var before = ImGui.GetCursorPosY();
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
{
ImGui.TextUnformatted("Text Preview:");
ImGui.TextUnformatted(Language.Options_Preview_Header);
DrawChunks(predrawnMessage.Content);
}
var after = ImGui.GetCursorPosY();
+11 -13
View File
@@ -1,4 +1,3 @@
using System.Numerics;
using System.Text;
using ChatTwo.Code;
using ChatTwo.Util;
@@ -14,7 +13,6 @@ public class InputPreview : Window
private ChatLogWindow LogWindow { get; }
private float Height;
private float AppliedHeight;
internal InputPreview(ChatLogWindow logWindow) : base("##chat2-inputpreview")
{
@@ -31,25 +29,25 @@ public class InputPreview : Window
public override void PreDraw()
{
// ReSharper disable once CompareOfFloatsByEqualityOperator
// Sizes don't use much precision
if (AppliedHeight == Height)
return;
AppliedHeight = Height;
var width = LogWindow.LastWindowSize.X;
var pos = LogWindow.LastWindowPos;
var size = LogWindow.LastWindowSize;
Size = new Vector2(width, Height);
Size = size with { Y = Height };
Position = pos with { Y = pos.Y - Height };
var y = Plugin.Config.PreviewPosition switch
{
PreviewPosition.Top => pos.Y - Height,
PreviewPosition.Bottom => pos.Y + size.Y,
_ => throw new ArgumentOutOfRangeException(nameof(Plugin.Config.PreviewPosition), Plugin.Config.PreviewPosition, null)
};
Position = pos with { Y = y };
PositionCondition = ImGuiCond.Always;
}
public override bool DrawConditions()
{
return !string.IsNullOrEmpty(LogWindow.Chat);
return Plugin.Config.PreviewPosition is PreviewPosition.Top or PreviewPosition.Bottom && !string.IsNullOrEmpty(LogWindow.Chat);
}
public override void Draw()
+13
View File
@@ -24,6 +24,19 @@ internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab
ImGuiUtil.HelpText(string.Format(Language.Options_Language_Description, Plugin.PluginName));
ImGui.Spacing();
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Preview_Name, Mutable.PreviewPosition.Name()))
{
if (combo)
{
foreach (var position in Enum.GetValues<PreviewPosition>())
if (ImGui.Selectable(position.Name(), Mutable.PreviewPosition == position))
Mutable.PreviewPosition = position;
}
}
ImGuiUtil.HelpText(Language.Options_Preview_Description);
ImGui.Spacing();
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name()))
{
if (combo)