Merge pull request #42

* fix: ensure newlines when rendering emotes
This commit is contained in:
Dean Sheather
2024-05-10 21:47:37 -07:00
committed by GitHub
parent 050485fece
commit 0f5ece288d
2 changed files with 15 additions and 8 deletions
+5 -2
View File
@@ -135,8 +135,11 @@ internal class Message
private List<Chunk> CheckMessageContent(List<Chunk> oldChunks)
{
var newChunks = new List<Chunk>();
void AddChunkWithMessage(Chunk chunk)
void AddChunkWithMessage(TextChunk chunk)
{
if (string.IsNullOrEmpty(chunk.Content))
return;
chunk.Message = this;
newChunks.Add(chunk);
}
@@ -198,7 +201,7 @@ internal class Message
AddContentAfterURLCheck(builder.ToString(), text, chunk);
builder.Clear();
newChunks.Add(new TextChunk(chunk.Source, EmotePayload.ResolveEmote(word), word));
AddChunkWithMessage(new TextChunk(chunk.Source, EmotePayload.ResolveEmote(word), word));
builder.Append(' ');
continue;
}
+9 -5
View File
@@ -1482,13 +1482,17 @@ public sealed class ChatLogWindow : Window
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
for (var i = 0; i < chunks.Count; i++)
{
if (chunks[i] is TextChunk text && string.IsNullOrEmpty(text.Content))
continue;
DrawChunk(chunks[i], wrap, handler, lineWidth);
if (i < chunks.Count - 1)
ImGui.SameLine();
else if (chunks[i].Link is EmotePayload) {
// Emote payloads seem to not automatically put newlines, which
// is an issue when modern mode is disabled.
ImGui.SameLine();
// Use default ImGui behavior for newlines.
ImGui.TextUnformatted("");
}
}
}
@@ -1517,17 +1521,17 @@ public sealed class ChatLogWindow : Window
if (chunk is not TextChunk text)
return;
if (chunk.Link?.Type == (PayloadType)0x53)
if (chunk.Link is EmotePayload emotePayload)
{
var emoteSize = ImGui.CalcTextSize("W");
emoteSize = emoteSize with { Y = emoteSize.X } * 1.5f;
var emotePayload = (EmotePayload) chunk.Link;
var image = EmoteCache.GetEmote(emotePayload.Code);
if (image is { IsLoaded: true })
image.Draw(emoteSize);
else
ImGui.Dummy(emoteSize);
ImGui.SetTooltip(emotePayload.Code);
return;
}