mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-05 07:36:03 +02:00
Add hex color parsing helper and implement custom list sources for channels and users
- Introduced HexColorHelper for parsing hex color strings to Terminal.Gui Attributes and Colors. - Created ChannelListSource for managing and rendering a list of channels with unread counts and active indicators. - Developed UserListSource for displaying online users with per-user nickname colors. - Refactored MainWindow to utilize ChatMessageManager for handling messages and channel state. - Updated project references and removed unused content from the server project. - Adjusted tests to reflect changes in namespaces and structure.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using EchoHub.Client.UI.Helpers;
|
||||
using Terminal.Gui.App;
|
||||
using Terminal.Gui.Views;
|
||||
using Terminal.Gui.ViewBase;
|
||||
using Terminal.Gui.Drawing;
|
||||
using Terminal.Gui.ViewBase;
|
||||
using Terminal.Gui.Views;
|
||||
using Attribute = Terminal.Gui.Drawing.Attribute;
|
||||
|
||||
namespace EchoHub.Client.UI;
|
||||
namespace EchoHub.Client.UI.Dialogs;
|
||||
|
||||
/// <summary>
|
||||
/// Result returned from the profile edit dialog.
|
||||
@@ -243,32 +244,13 @@ public sealed class ProfileEditDialog
|
||||
return;
|
||||
}
|
||||
|
||||
var color = ParseHexToTrueColor(hexColor.Trim());
|
||||
var color = HexColorHelper.ParseHexToColor(hexColor.Trim(), Color.White);
|
||||
preview.SetScheme(new Scheme
|
||||
{
|
||||
Normal = new Attribute(color, Color.Blue)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a hex color string to a Terminal.Gui TrueColor Color.
|
||||
/// V2 supports TrueColor via new Color(r, g, b).
|
||||
/// </summary>
|
||||
private static Color ParseHexToTrueColor(string hex)
|
||||
{
|
||||
if (hex.StartsWith('#'))
|
||||
hex = hex[1..];
|
||||
|
||||
if (hex.Length != 6 || !int.TryParse(hex, System.Globalization.NumberStyles.HexNumber, null, out var rgb))
|
||||
return Color.White;
|
||||
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
private static string? NullIfEmpty(string? value) =>
|
||||
string.IsNullOrWhiteSpace(value) ? null : value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user