private void Refresh() { if (Width == 0 || Height == 0) { return; } seekLt?.Dispose(); var leftDest = CalculateLeftDestination(); var centerDest = CalculateCenterDestination(); var rightDest = CalculateRightDestination(); if (center == null) { var thisMonth = new DateTime(Options.Year, Options.Month, 1); var lastMonth = thisMonth.AddMonths(-1); var nextMonth = thisMonth.AddMonths(1); left = ProtectedPanel.Add(new MonthCalendar(new MonthCalendarOptions() { CustomizeContent = Options.CustomizeContent, MinMonth = Options.MinMonth, MaxMonth = Options.MaxMonth, AdvanceMonthBackwardKey = null, AdvanceMonthForwardKey = null, TodayHighlightColor = Options.TodayHighlightColor, Month = lastMonth.Month, Year = lastMonth.Year })); center = ProtectedPanel.Add(new MonthCalendar(new MonthCalendarOptions() { CustomizeContent = Options.CustomizeContent, MinMonth = Options.MinMonth, MaxMonth = Options.MaxMonth, AdvanceMonthBackwardKey = null, AdvanceMonthForwardKey = null, TodayHighlightColor = Options.TodayHighlightColor, Month = thisMonth.Month, Year = thisMonth.Year })); right = ProtectedPanel.Add(new MonthCalendar(new MonthCalendarOptions() { CustomizeContent = Options.CustomizeContent, MinMonth = Options.MinMonth, MaxMonth = Options.MaxMonth, AdvanceMonthBackwardKey = null, AdvanceMonthForwardKey = null, TodayHighlightColor = Options.TodayHighlightColor, Month = nextMonth.Month, Year = nextMonth.Year })); } left.Bounds = leftDest; center.Bounds = centerDest; right.Bounds = rightDest; }
public async Task <bool> SeekAsync(bool forward, float duration) { if (seekLt != null && seekLt.IsExpired == false) { return(false); } using (seekLt = this.CreateChildLifetime()) { var thisMonth = new DateTime(Options.Year, Options.Month, 1); thisMonth = thisMonth.AddMonths(forward ? 1 : -1); this.Options.Month = thisMonth.Month; this.Options.Year = thisMonth.Year; var lastMonth = thisMonth.AddMonths(-1); var nextMonth = thisMonth.AddMonths(1); var leftDest = CalculateLeftDestination(); var centerDest = CalculateCenterDestination(); var rightDest = CalculateRightDestination(); var tempMonth = !forward ? lastMonth : nextMonth; var temp = ProtectedPanel.Add(new MonthCalendar(new MonthCalendarOptions() { CustomizeContent = Options.CustomizeContent, MinMonth = Options.MinMonth, MaxMonth = Options.MaxMonth, AdvanceMonthBackwardKey = null, AdvanceMonthForwardKey = null, TodayHighlightColor = Options.TodayHighlightColor, Month = tempMonth.Month, Year = tempMonth.Year })); temp.Width = 2; temp.Height = 1; temp.X = !forward ? -temp.Width : Width + temp.Width; temp.Y = ConsoleMath.Round((Height - temp.Height) / 2f); var tempDest = !forward ? leftDest : rightDest; EasingFunction ease = Animator.EaseInOut; var tempAnimation = temp.AnimateAsync(new ConsoleControlAnimationOptions() { IsCancelled = () => seekLt.IsExpired, Destination = () => tempDest, Duration = duration, EasingFunction = ease }); if (!forward) { var rightAnimationDest = new RectF(Width + 2, Height / 2, 2, 1); var centerAnimationDest = right.Bounds; var leftAnimationDest = center.Bounds; await Task.WhenAll ( right.AnimateAsync(new ConsoleControlAnimationOptions() { IsCancelled = () => seekLt.IsExpired, EasingFunction = ease, Destination = () => rightAnimationDest, Duration = duration }), center.AnimateAsync(new ConsoleControlAnimationOptions() { IsCancelled = () => seekLt.IsExpired, EasingFunction = ease, Destination = () => centerAnimationDest, Duration = duration }), left.AnimateAsync(new ConsoleControlAnimationOptions() { IsCancelled = () => seekLt.IsExpired, EasingFunction = ease, Destination = () => leftAnimationDest, Duration = duration }), tempAnimation ); right.Dispose(); right = center; center = left; left = temp; } else { var rightAnimationDest = ((ICollider)center).Bounds; var centerAnimationDest = ((ICollider)left).Bounds; var leftAnimationDest = new RectF(-2, Height / 2, 2, 1); await Task.WhenAll ( right.AnimateAsync(new ConsoleControlAnimationOptions() { IsCancelled = () => seekLt.IsExpired, EasingFunction = ease, Destination = () => rightAnimationDest, Duration = duration }), center.AnimateAsync(new ConsoleControlAnimationOptions() { IsCancelled = () => seekLt.IsExpired, EasingFunction = ease, Destination = () => centerAnimationDest, Duration = duration }), left.AnimateAsync(new ConsoleControlAnimationOptions() { IsCancelled = () => seekLt.IsExpired, EasingFunction = ease, Destination = () => leftAnimationDest, Duration = duration }), tempAnimation ); left.Dispose(); left = center; center = right; right = temp; left.Bounds = leftDest; center.Bounds = centerDest; right.Bounds = rightDest; await Task.Yield(); left.Refresh(); right.Refresh(); center.Refresh(); } return(true); } }