diff --git a/src/Ursa/Controls/Timeline/Timeline.cs b/src/Ursa/Controls/Timeline/Timeline.cs new file mode 100644 index 0000000..34daef6 --- /dev/null +++ b/src/Ursa/Controls/Timeline/Timeline.cs @@ -0,0 +1,50 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Generators; +using Avalonia.Controls.Templates; + +namespace Ursa.Controls; + +public class Timeline: ItemsControl +{ + + public static readonly StyledProperty ItemDescriptionTemplateProperty = AvaloniaProperty.Register( + nameof(ItemDescriptionTemplate)); + + public IDataTemplate? ItemDescriptionTemplate + { + get => GetValue(ItemDescriptionTemplateProperty); + set => SetValue(ItemDescriptionTemplateProperty, value); + } + + protected override bool IsItemItsOwnContainerOverride(Control item) + { + return item is TimelineItem; + } + + protected override Control CreateContainerForItemOverride() + { + return new TimelineItem(); + } + + protected override void PrepareContainerForItemOverride(Control container, object? item, int index) + { + base.PrepareContainerForItemOverride(container, item, index); + if (container is TimelineItem c ) + { + if (item is ITimelineItemData data) + { + c[TimelineItem.TimeProperty] = data; + c[ContentControl.ContentProperty] = data.Content; + c[TimelineItem.DescriptionProperty] = data.Description; + if(ItemTemplate is {}) c[ContentControl.ContentTemplateProperty] = this.ItemTemplate; + if(ItemDescriptionTemplate is {}) c[TimelineItem.DescriptionTemplateProperty] = this.ItemDescriptionTemplate; + } + else + { + c.Content = item; + if (ItemTemplate is { }) c[ContentControl.ContentTemplateProperty] = this.ItemTemplate; + } + } + } +} \ No newline at end of file diff --git a/src/Ursa/Controls/Timeline/TimelineItem.cs b/src/Ursa/Controls/Timeline/TimelineItem.cs new file mode 100644 index 0000000..8628063 --- /dev/null +++ b/src/Ursa/Controls/Timeline/TimelineItem.cs @@ -0,0 +1,59 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Metadata; +using Avalonia.Controls.Templates; +using Avalonia.Data; +using Avalonia.Media; + +namespace Ursa.Controls; + +[PseudoClasses(PC_First, PC_Last)] +public class TimelineItem: ContentControl +{ + public const string PC_First = ":first"; + public const string PC_Last = ":last"; + + public static readonly StyledProperty IconForegroundProperty = + AvaloniaProperty.Register(nameof(IconForeground)); + + public IBrush IconForeground + { + get => GetValue(IconForegroundProperty); + set => SetValue(IconForegroundProperty, value); + } + + public static readonly StyledProperty DescriptionProperty = + AvaloniaProperty.Register(nameof(Description)); + + public object? Description + { + get => GetValue(DescriptionProperty); + set => SetValue(DescriptionProperty, value); + } + + public static readonly StyledProperty TimeProperty = AvaloniaProperty.Register( + nameof(Time)); + public DateTime Time + { + get => GetValue(TimeProperty); + set => SetValue(TimeProperty, value); + } + + public static readonly StyledProperty TimeFormatProperty = AvaloniaProperty.Register( + nameof(TimeFormat)); + + public string? TimeFormat + { + get => GetValue(TimeFormatProperty); + set => SetValue(TimeFormatProperty, value); + } + + public static readonly StyledProperty DescriptionTemplateProperty = AvaloniaProperty.Register( + nameof(DescriptionTemplate)); + + public IDataTemplate DescriptionTemplate + { + get => GetValue(DescriptionTemplateProperty); + set => SetValue(DescriptionTemplateProperty, value); + } +} \ No newline at end of file diff --git a/src/Ursa/Controls/Timeline/TimelineItemData.cs b/src/Ursa/Controls/Timeline/TimelineItemData.cs new file mode 100644 index 0000000..1d4b7c0 --- /dev/null +++ b/src/Ursa/Controls/Timeline/TimelineItemData.cs @@ -0,0 +1,9 @@ +namespace Ursa.Controls; + +public interface ITimelineItemData +{ + public DateTime Time { get; set; } + public object Content { get; set; } + public object Description { get; set; } + public TimelineItemType ItemType { get; set; } +} \ No newline at end of file diff --git a/src/Ursa/Controls/Timeline/TimelineItemType.cs b/src/Ursa/Controls/Timeline/TimelineItemType.cs new file mode 100644 index 0000000..2fa2f60 --- /dev/null +++ b/src/Ursa/Controls/Timeline/TimelineItemType.cs @@ -0,0 +1,11 @@ +namespace Ursa.Controls; + +public enum TimelineItemType +{ + None, + Default, + Ongoing, + Success, + Warning, + Error, +} \ No newline at end of file diff --git a/src/Ursa/Controls/Timeline/TimelinePlacement.cs b/src/Ursa/Controls/Timeline/TimelinePlacement.cs new file mode 100644 index 0000000..adf11bb --- /dev/null +++ b/src/Ursa/Controls/Timeline/TimelinePlacement.cs @@ -0,0 +1,12 @@ +namespace Ursa.Controls; + +/// +/// Describe how TimelineItem components should be placed around the line. +/// +public enum TimelinePlacement +{ + Left, + Right, + Center, + Alternate, +} \ No newline at end of file