feat: initialize control.
This commit is contained in:
50
src/Ursa/Controls/Timeline/Timeline.cs
Normal file
50
src/Ursa/Controls/Timeline/Timeline.cs
Normal file
@@ -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<IDataTemplate?> ItemDescriptionTemplateProperty = AvaloniaProperty.Register<Timeline, IDataTemplate?>(
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
59
src/Ursa/Controls/Timeline/TimelineItem.cs
Normal file
59
src/Ursa/Controls/Timeline/TimelineItem.cs
Normal file
@@ -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<IBrush> IconForegroundProperty =
|
||||||
|
AvaloniaProperty.Register<TimelineItem, IBrush>(nameof(IconForeground));
|
||||||
|
|
||||||
|
public IBrush IconForeground
|
||||||
|
{
|
||||||
|
get => GetValue(IconForegroundProperty);
|
||||||
|
set => SetValue(IconForegroundProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<object?> DescriptionProperty =
|
||||||
|
AvaloniaProperty.Register<TimelineItem, object?>(nameof(Description));
|
||||||
|
|
||||||
|
public object? Description
|
||||||
|
{
|
||||||
|
get => GetValue(DescriptionProperty);
|
||||||
|
set => SetValue(DescriptionProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<DateTime> TimeProperty = AvaloniaProperty.Register<TimelineItem, DateTime>(
|
||||||
|
nameof(Time));
|
||||||
|
public DateTime Time
|
||||||
|
{
|
||||||
|
get => GetValue(TimeProperty);
|
||||||
|
set => SetValue(TimeProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<string?> TimeFormatProperty = AvaloniaProperty.Register<TimelineItem, string?>(
|
||||||
|
nameof(TimeFormat));
|
||||||
|
|
||||||
|
public string? TimeFormat
|
||||||
|
{
|
||||||
|
get => GetValue(TimeFormatProperty);
|
||||||
|
set => SetValue(TimeFormatProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<IDataTemplate> DescriptionTemplateProperty = AvaloniaProperty.Register<TimelineItem, IDataTemplate>(
|
||||||
|
nameof(DescriptionTemplate));
|
||||||
|
|
||||||
|
public IDataTemplate DescriptionTemplate
|
||||||
|
{
|
||||||
|
get => GetValue(DescriptionTemplateProperty);
|
||||||
|
set => SetValue(DescriptionTemplateProperty, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/Ursa/Controls/Timeline/TimelineItemData.cs
Normal file
9
src/Ursa/Controls/Timeline/TimelineItemData.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
11
src/Ursa/Controls/Timeline/TimelineItemType.cs
Normal file
11
src/Ursa/Controls/Timeline/TimelineItemType.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
public enum TimelineItemType
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Default,
|
||||||
|
Ongoing,
|
||||||
|
Success,
|
||||||
|
Warning,
|
||||||
|
Error,
|
||||||
|
}
|
||||||
12
src/Ursa/Controls/Timeline/TimelinePlacement.cs
Normal file
12
src/Ursa/Controls/Timeline/TimelinePlacement.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Describe how TimelineItem components should be placed around the line.
|
||||||
|
/// </summary>
|
||||||
|
public enum TimelinePlacement
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Center,
|
||||||
|
Alternate,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user