From 9b3e3f79e32a6379efdde5d548815e6d17d2b1d5 Mon Sep 17 00:00:00 2001 From: Infi Date: Fri, 19 Sep 2025 22:49:51 +0200 Subject: [PATCH] - Fix imgui asserts on table --- ChatTwo/Ui/ChatLogWindow.cs | 4 +-- ChatTwo/Ui/SeStringDebugger.cs | 57 +++++++++++++++----------------- ChatTwo/Ui/SettingsTabs/Emote.cs | 2 +- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index b8571ac..563b4e3 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -1259,8 +1259,8 @@ public sealed class ChatLogWindow : Window if (!tabTable.Success) return; - ImGui.TableSetupColumn("tabs", ImGuiTableColumnFlags.None, 1); - ImGui.TableSetupColumn("chat", ImGuiTableColumnFlags.None, 4); + ImGui.TableSetupColumn("tabs", ImGuiTableColumnFlags.WidthStretch, 1); + ImGui.TableSetupColumn("chat", ImGuiTableColumnFlags.WidthStretch, 4); ImGui.TableNextColumn(); diff --git a/ChatTwo/Ui/SeStringDebugger.cs b/ChatTwo/Ui/SeStringDebugger.cs index 8be4732..1d02e53 100644 --- a/ChatTwo/Ui/SeStringDebugger.cs +++ b/ChatTwo/Ui/SeStringDebugger.cs @@ -257,33 +257,33 @@ public class SeStringDebugger : Window var style = ImGui.GetStyle(); ImGui.Text($"{name}:"); - ImGui.Indent(style.IndentSpacing); - if (!ImGui.BeginTable($"##chat3-{name}", 2, 0)) + using var indent = ImRaii.PushIndent(style.IndentSpacing); + using (var table = ImRaii.Table($"##chat2-{name}", 2)) { - ImGui.EndTable(); - ImGui.Unindent(style.IndentSpacing); - return; + if (!table.Success) + return; + + ImGui.TableSetupColumn($"##chat2-{name}-key", ImGuiTableColumnFlags.WidthStretch, 0.4f); + ImGui.TableSetupColumn($"##chat2-{name}-value"); + for (var i = 0; i < metadata.Count; i++) + { + using var id = ImRaii.PushId(i); + + var (key, value) = metadata.ElementAt(i); + ImGui.TableNextColumn(); + ImGui.Text(key); + + ImGui.TableNextColumn(); + ImGuiTextVisibleWhitespace(value); + } } - ImGui.TableSetupColumn($"##chat3-{name}-key", 0, 0.4f); - ImGui.TableSetupColumn($"##chat3-{name}-value"); - for (var i = 0; i < metadata.Count; i++) - { - var (key, value) = metadata.ElementAt(i); - ImGui.PushID(i); - ImGui.TableNextColumn(); - ImGui.Text(key); - ImGui.TableNextColumn(); - ImGuiTextVisibleWhitespace(value); - ImGui.PopID(); - } - ImGui.EndTable(); - ImGui.Unindent(style.IndentSpacing); + ImGui.NewLine(); } // ImGuiTextVisibleWhitespace replaces leading and trailing whitespace with // visible characters. The extra characters are rendered with a muted font. - private static void ImGuiTextVisibleWhitespace(string? original, bool wrap = true) + private static void ImGuiTextVisibleWhitespace(string? original) { if (string.IsNullOrEmpty(original)) { @@ -298,33 +298,28 @@ public class SeStringDebugger : Window using var pushedStyle = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0)); - void WriteText(string wText) - { - if (wrap) - ImGui.TextWrapped(wText); - else - ImGui.TextUnformatted(wText); - } - while (start < end && char.IsWhiteSpace(text[start])) start++; if (start > 0) { using var pushedColor = ImRaii.PushColor(ImGuiCol.Text, new Vector4(1, 1, 1, 0.5f)); - WriteText(new string('_', start)); + ImGui.TextWrapped(new string('_', start)); + ImGui.SameLine(); } while (end > start && char.IsWhiteSpace(text[end - 1])) end--; - WriteText(text[start..end]); + ImGui.TextWrapped(text[start..end]); + if (end < text.Length) { ImGui.SameLine(); + using var pushedColor = ImRaii.PushColor(ImGuiCol.Text, new Vector4(1, 1, 1, 0.5f)); - WriteText(new string('_', text.Length - end)); + ImGui.TextWrapped(new string('_', text.Length - end)); } } } diff --git a/ChatTwo/Ui/SettingsTabs/Emote.cs b/ChatTwo/Ui/SettingsTabs/Emote.cs index fb03d4d..4f43e63 100644 --- a/ChatTwo/Ui/SettingsTabs/Emote.cs +++ b/ChatTwo/Ui/SettingsTabs/Emote.cs @@ -62,7 +62,7 @@ internal sealed class Emote : ISettingsTab if (table) { ImGui.TableSetupColumn(Language.Options_Emote_EmoteTable); - ImGui.TableSetupColumn("##Del", 0, 0.07f); + ImGui.TableSetupColumn("##Del", ImGuiTableColumnFlags.WidthStretch, 0.07f); ImGui.TableHeadersRow();