feat: add documentation.
This commit is contained in:
@@ -8,6 +8,9 @@ using Ursa.Common;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Badge control that can display a notification indicator or count on top of other content.
|
||||
/// </summary>
|
||||
[TemplatePart(PART_BadgeContainer, typeof(Control))]
|
||||
public class Badge : HeaderedContentControl
|
||||
{
|
||||
@@ -15,18 +18,33 @@ public class Badge : HeaderedContentControl
|
||||
public const string PART_BadgeContainer = "PART_BadgeContainer";
|
||||
public const string PART_HeaderPresenter = "PART_HeaderPresenter";
|
||||
|
||||
/// <summary>
|
||||
/// Defines the theme applied to the badge.
|
||||
/// </summary>
|
||||
public static readonly StyledProperty<ControlTheme> BadgeThemeProperty =
|
||||
AvaloniaProperty.Register<Badge, ControlTheme>(nameof(BadgeTheme));
|
||||
|
||||
/// <summary>
|
||||
/// Defines whether the badge should be displayed as a dot.
|
||||
/// </summary>
|
||||
public static readonly StyledProperty<bool> DotProperty =
|
||||
AvaloniaProperty.Register<Badge, bool>(nameof(Dot));
|
||||
|
||||
/// <summary>
|
||||
/// Defines the corner position where the badge should be displayed.
|
||||
/// </summary>
|
||||
public static readonly StyledProperty<CornerPosition> CornerPositionProperty =
|
||||
AvaloniaProperty.Register<Badge, CornerPosition>(nameof(CornerPosition));
|
||||
|
||||
/// <summary>
|
||||
/// Defines the maximum count to display before showing overflow indicator.
|
||||
/// </summary>
|
||||
public static readonly StyledProperty<int> OverflowCountProperty =
|
||||
AvaloniaProperty.Register<Badge, int>(nameof(OverflowCount));
|
||||
|
||||
/// <summary>
|
||||
/// Defines the font size of the badge text.
|
||||
/// </summary>
|
||||
public static readonly StyledProperty<double> BadgeFontSizeProperty =
|
||||
AvaloniaProperty.Register<Badge, double>(nameof(BadgeFontSize));
|
||||
|
||||
@@ -38,36 +56,52 @@ public class Badge : HeaderedContentControl
|
||||
DotProperty.Changed.AddClassHandler<Badge>((badge, _) => badge.UpdateBadgePosition());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the theme applied to the badge.
|
||||
/// </summary>
|
||||
public ControlTheme BadgeTheme
|
||||
{
|
||||
get => GetValue(BadgeThemeProperty);
|
||||
set => SetValue(BadgeThemeProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the badge should be displayed as a dot.
|
||||
/// </summary>
|
||||
public bool Dot
|
||||
{
|
||||
get => GetValue(DotProperty);
|
||||
set => SetValue(DotProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the corner position where the badge should be displayed.
|
||||
/// </summary>
|
||||
public CornerPosition CornerPosition
|
||||
{
|
||||
get => GetValue(CornerPositionProperty);
|
||||
set => SetValue(CornerPositionProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum count to display before showing overflow indicator.
|
||||
/// </summary>
|
||||
public int OverflowCount
|
||||
{
|
||||
get => GetValue(OverflowCountProperty);
|
||||
set => SetValue(OverflowCountProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the font size of the badge text.
|
||||
/// </summary>
|
||||
public double BadgeFontSize
|
||||
{
|
||||
get => GetValue(BadgeFontSizeProperty);
|
||||
set => SetValue(BadgeFontSizeProperty, value);
|
||||
}
|
||||
|
||||
/// <inheirtdoc/>
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
_badgeContainer?.RemoveHandler(SizeChangedEvent, OnBadgeSizeChanged);
|
||||
@@ -76,11 +110,17 @@ public class Badge : HeaderedContentControl
|
||||
_badgeContainer?.AddHandler(SizeChangedEvent, OnBadgeSizeChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the size changed event of the badge container and updates its position.
|
||||
/// </summary>
|
||||
private void OnBadgeSizeChanged(object? sender, SizeChangedEventArgs e)
|
||||
{
|
||||
UpdateBadgePosition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the badge position based on the current corner position and size.
|
||||
/// </summary>
|
||||
private void UpdateBadgePosition()
|
||||
{
|
||||
var vertical = CornerPosition is CornerPosition.BottomLeft or CornerPosition.BottomRight ? 1 : -1;
|
||||
|
||||
Reference in New Issue
Block a user