From 2b183027b19fb4e0752c167eecb1a04c22f7a8df Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 23 Mar 2023 23:14:29 +0800 Subject: [PATCH] feat: update timelineitem layout. --- demo/Ursa.Demo/Pages/TimelineDemo.axaml | 65 ++++------------- demo/Ursa.Demo/Ursa.Demo.csproj | 1 + src/Ursa.Themes.Semi/Controls/Timeline.axaml | 75 ++++++++++++++------ src/Ursa/Controls/Timeline/Timeline.cs | 5 +- src/Ursa/Controls/Timeline/TimelineItem.cs | 51 ++++++++++++- 5 files changed, 120 insertions(+), 77 deletions(-) diff --git a/demo/Ursa.Demo/Pages/TimelineDemo.axaml b/demo/Ursa.Demo/Pages/TimelineDemo.axaml index 0093166..d77dbca 100644 --- a/demo/Ursa.Demo/Pages/TimelineDemo.axaml +++ b/demo/Ursa.Demo/Pages/TimelineDemo.axaml @@ -15,57 +15,20 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/demo/Ursa.Demo/Ursa.Demo.csproj b/demo/Ursa.Demo/Ursa.Demo.csproj index 7cc1b6c..f66e639 100644 --- a/demo/Ursa.Demo/Ursa.Demo.csproj +++ b/demo/Ursa.Demo/Ursa.Demo.csproj @@ -5,6 +5,7 @@ enable true app.manifest + false diff --git a/src/Ursa.Themes.Semi/Controls/Timeline.axaml b/src/Ursa.Themes.Semi/Controls/Timeline.axaml index 8d01b88..b36677a 100644 --- a/src/Ursa.Themes.Semi/Controls/Timeline.axaml +++ b/src/Ursa.Themes.Semi/Controls/Timeline.axaml @@ -17,9 +17,7 @@ - - - + @@ -27,16 +25,51 @@ - - - - - - - + + + + + + + + + VerticalAlignment="Bottom" + Foreground="DarkGray"> @@ -44,26 +77,22 @@ - - - diff --git a/src/Ursa/Controls/Timeline/Timeline.cs b/src/Ursa/Controls/Timeline/Timeline.cs index 23e52dc..3304ab0 100644 --- a/src/Ursa/Controls/Timeline/Timeline.cs +++ b/src/Ursa/Controls/Timeline/Timeline.cs @@ -44,12 +44,13 @@ public class Timeline: ItemsControl { if (this.LogicalChildren[i] is TimelineItem t) { - t.SetPosition(i == 0, i == this.LogicalChildren.Count - 1); + t.SetIndex(i == 0, i == this.LogicalChildren.Count - 1); } else if (this.LogicalChildren[i] is ContentPresenter { Child: TimelineItem t2 }) { - t2.SetPosition(i == 0, i == this.LogicalChildren.Count - 1); + t2.SetIndex(i == 0, i == this.LogicalChildren.Count - 1); } } } + } \ No newline at end of file diff --git a/src/Ursa/Controls/Timeline/TimelineItem.cs b/src/Ursa/Controls/Timeline/TimelineItem.cs index 0139823..2760bb7 100644 --- a/src/Ursa/Controls/Timeline/TimelineItem.cs +++ b/src/Ursa/Controls/Timeline/TimelineItem.cs @@ -58,9 +58,58 @@ public class TimelineItem: ContentControl set => SetValue(DescriptionTemplateProperty, value); } - internal void SetPosition(bool isFirst, bool isLast) + internal void SetIndex(bool isFirst, bool isLast) { PseudoClasses.Set(PC_First, isFirst); PseudoClasses.Set(PC_Last, isLast); } +} + +public class TimelineItemLayoutProperties: AvaloniaObject +{ + private double _dimensionDelta = 0.01; + + public static readonly StyledProperty TimeSlotWidthProperty = AvaloniaProperty.Register( + nameof(TimeSlotWidth)); + + public double TimeSlotWidth + { + get => GetValue(TimeSlotWidthProperty); + set + { + if (Math.Abs(GetValue(TimeSlotWidthProperty) - value) < _dimensionDelta) return; + SetValue(TimeSlotWidthProperty, value); + } + } + + public static readonly StyledProperty TimeSlotHeightProperty = AvaloniaProperty.Register( + nameof(TimeSlotHeight)); + + public double TimeSlotHeight + { + get => GetValue(TimeSlotHeightProperty); + set + { + if (Math.Abs(GetValue(TimeSlotHeightProperty) - value) < _dimensionDelta) return; + SetValue(TimeSlotHeightProperty, value); + } + } + + public static readonly StyledProperty ContentSlotWidthProperty = AvaloniaProperty.Register( + nameof(ContentSlotWidth)); + + public double ContentSlotWidth + { + get => GetValue(ContentSlotWidthProperty); + set => SetValue(ContentSlotWidthProperty, value); + } + + public static readonly StyledProperty ContentSlotHeightProperty = AvaloniaProperty.Register( + nameof(ContentSlotHeight)); + + public double ContentSlotHeight + { + get => GetValue(ContentSlotHeightProperty); + set => SetValue(ContentSlotHeightProperty, value); + } } \ No newline at end of file