feat: Implement chat line wrapping and viewport resizing for message display

This commit is contained in:
HueByte
2026-02-19 09:11:01 +01:00
parent 96b31ec568
commit bed6040f7c
3 changed files with 82 additions and 4 deletions
+28 -3
View File
@@ -45,6 +45,7 @@ public sealed class MainWindow : Runnable
private readonly Dictionary<string, string?> _channelTopics = [];
private string _currentChannel = string.Empty;
private string _currentUser = string.Empty;
private int _lastChatWidth;
/// <summary>
/// Fired when the user selects a channel. Parameter is the channel name.
@@ -192,6 +193,9 @@ public sealed class MainWindow : Runnable
// Apply our custom color schemes to all views
ApplyColorSchemes();
// Re-wrap messages when the chat area is resized
_messageList.ViewportChanged += (_, _) => OnChatViewportChanged();
// Window-level key handling for Ctrl+C (quit)
KeyDown += OnWindowKeyDown;
}
@@ -368,6 +372,16 @@ public sealed class MainWindow : Runnable
}
}
private void OnChatViewportChanged()
{
var newWidth = _messageList.Viewport.Width;
if (newWidth > 0 && newWidth != _lastChatWidth)
{
_lastChatWidth = newWidth;
RefreshMessages();
}
}
private void OnWindowKeyDown(object? sender, Key e)
{
// Ctrl+C quits from anywhere
@@ -588,11 +602,22 @@ public sealed class MainWindow : Runnable
{
if (_channelMessages.TryGetValue(_currentChannel, out var messages))
{
var width = _messageList.Viewport.Width;
var source = new ChatListSource();
source.AddRange(messages);
if (width > 0)
{
foreach (var line in messages)
source.AddRange(line.Wrap(width));
}
else
{
source.AddRange(messages);
}
_messageList.Source = source;
if (messages.Count > 0)
_messageList.SelectedItem = messages.Count - 1;
if (source.Count > 0)
_messageList.SelectedItem = source.Count - 1;
}
else
{