using System;
namespace Spectre.Console
{
///
/// Contains extension methods for .
///
public static class PanelExtensions
{
///
/// Sets the panel header.
///
/// The panel.
/// The header text.
/// The header style.
/// The header alignment.
/// The same instance so that multiple calls can be chained.
public static Panel Header(this Panel panel, string text, Style? style = null, Justify? alignment = null)
{
if (panel is null)
{
throw new ArgumentNullException(nameof(panel));
}
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}
style ??= panel.Header?.Style;
alignment ??= panel.Header?.Alignment;
return Header(panel, new PanelHeader(text, style, alignment));
}
///
/// Sets the panel header style.
///
/// The panel.
/// The header style.
/// The same instance so that multiple calls can be chained.
public static Panel HeaderStyle(this Panel panel, Style style)
{
if (panel is null)
{
throw new ArgumentNullException(nameof(panel));
}
if (style is null)
{
throw new ArgumentNullException(nameof(style));
}
if (panel.Header != null)
{
// Update existing style
panel.Header.Style = style;
}
else
{
// Create header
Header(panel, string.Empty, style, null);
}
return panel;
}
///
/// Sets the panel header alignment.
///
/// The panel.
/// The header alignment.
/// The same instance so that multiple calls can be chained.
public static Panel HeaderAlignment(this Panel panel, Justify alignment)
{
if (panel is null)
{
throw new ArgumentNullException(nameof(panel));
}
if (panel.Header != null)
{
// Update existing style
panel.Header.Alignment = alignment;
}
else
{
// Create header
Header(panel, string.Empty, null, alignment);
}
return panel;
}
///
/// Sets the panel header.
///
/// The panel.
/// The header to use.
/// The same instance so that multiple calls can be chained.
public static Panel Header(this Panel panel, PanelHeader header)
{
if (panel is null)
{
throw new ArgumentNullException(nameof(panel));
}
panel.Header = header;
return panel;
}
}
}