示例#1
0
        private void SetupMinimumSizeExperience()
        {
            ConsolePanel   shield = null;
            ConsoleControl min    = null;

            min = ProtectedPanel.Add(new MinimumSizeEnforcerPanel(new MinimumSizeEnforcerPanelOptions()
            {
                MinWidth            = MinWidth,
                MinHeight           = MinHeight,
                OnMinimumSizeNotMet = () =>
                {
                    if (min == null)
                    {
                        return;
                    }
                    min.IsVisible = false;
                    shield        = ProtectedPanel.Add(new ConsolePanel()
                    {
                        Background = Foreground
                    }).Fill();
                    var date = new DateTime(Options.Year, Options.Month, 1);
                    shield.Add(new Label()
                    {
                        Text = date.ToString("Y").ToConsoleString(Background, Foreground)
                    }).CenterBoth();
                },
                OnMinimumSizeMet = () => shield?.Dispose()
            })).Fill();
        }
示例#2
0
 /// <summary>
 /// Creates a fixed aspect ratio panel
 /// </summary>
 /// <param name="widthOverHeight">the aspect ratio defined as the width divided by the height</param>
 /// <param name="content">the content to center on this panel</param>
 public FixedAspectRatioPanel(float widthOverHeight, ConsoleControl content)
 {
     this.content         = content;
     this.widthOverHeight = widthOverHeight;
     ProtectedPanel.Add(content).CenterBoth();
     this.SynchronizeForLifetime(nameof(Bounds), UpdateContentSize, this);
 }
示例#3
0
 private void InitLayout()
 {
     layout = ProtectedPanel.Add(new GridLayout(new GridLayoutOptions()
     {
         Columns = new List <GridColumnDefinition>()
         {
             new GridColumnDefinition()
             {
                 Type = GridValueType.Pixels, Width = 15
             },
             new GridColumnDefinition()
             {
                 Type = GridValueType.RemainderValue, Width = 1
             },
         },
         Rows = new List <GridRowDefinition>()
         {
             new GridRowDefinition()
             {
                 Type = GridValueType.Pixels, Height = 3
             },
             new GridRowDefinition()
             {
                 Type = GridValueType.RemainderValue, Height = 1
             }
         }
     })).Fill();
     layout.RefreshLayout();
     commandBar   = layout.Add(new ConsolePanel(), 0, 0, columnSpan: 2);
     framePanel   = layout.Add(new ConsolePanel(), 0, 1);
     previewPanel = layout.Add(new ConsolePanel(), 1, 1);
     layout.RefreshLayout();
 }
示例#4
0
 private void ComposeLoadingUX()
 {
     loadingPanel = ProtectedPanel.Add(new ConsolePanel()
     {
         ZIndex = int.MaxValue
     }).Fill();
     loadingPanel.Add(new Label()
     {
         Text = Options.LoadingMessage
     }).CenterBoth();
 }
示例#5
0
        private void PopulateMonthAndYearLabel()
        {
            var date = new DateTime(Options.Year, Options.Month, 1);
            var monthAndYearLabel = ProtectedPanel.Add(new Label()
            {
                Text = date.ToString("Y").ToConsoleString(HasFocus ? RGB.Black : Background, HasFocus ? RGB.Cyan : Foreground)
            });

            gridLayout.SynchronizeForLifetime(nameof(Bounds), () =>
            {
                monthAndYearLabel.X = gridLayout.X + gridLayout.Width - monthAndYearLabel.Width;
                monthAndYearLabel.Y = +gridLayout.Y + gridLayout.Height - 1;
            }, gridLayout);
        }
示例#6
0
        public DataGridPresenter(DataGridCoreOptions options)
        {
            this.Options         = options;
            recomposableControls = new List <ConsoleControl>();

            var columns = options.Columns.Select(c => c as GridColumnDefinition).ToList();

            if (columns.Where(c => c.Type == GridValueType.RemainderValue).Count() == 0)
            {
                columns.Add(new GridColumnDefinition()
                {
                    Type  = GridValueType.RemainderValue,
                    Width = 1
                });
            }

            gridLayout = ProtectedPanel.Add(new GridLayout(new GridLayoutOptions()
            {
                Columns = columns,
                Rows    = new List <GridRowDefinition>()
            })).Fill();

            SubscribeForLifetime(nameof(Bounds), Recompose, this);
        }
示例#7
0
        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;
        }
示例#8
0
        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);
            }
        }
示例#9
0
        private void SetupInvisiblePlaceholders()
        {
            var placeholderGrid = ProtectedPanel.Add(new GridLayout(new GridLayoutOptions()
            {
                Columns = new List <GridColumnDefinition>()
                {
                    new GridColumnDefinition()
                    {
                        Width = .01f, Type = GridValueType.Percentage
                    },
                    new GridColumnDefinition()
                    {
                        Width = .25f, Type = GridValueType.Percentage
                    },
                    new GridColumnDefinition()
                    {
                        Width = .01f, Type = GridValueType.Percentage
                    },
                    new GridColumnDefinition()
                    {
                        Width = .46f, Type = GridValueType.Percentage
                    },
                    new GridColumnDefinition()
                    {
                        Width = .01f, Type = GridValueType.Percentage
                    },
                    new GridColumnDefinition()
                    {
                        Width = .25f, Type = GridValueType.Percentage
                    },
                    new GridColumnDefinition()
                    {
                        Width = .01f, Type = GridValueType.Percentage
                    },
                },
                Rows = new List <GridRowDefinition>()
                {
                    // top margin
                    new GridRowDefinition()
                    {
                        Height = .1f, Type = GridValueType.Percentage
                    },

                    new GridRowDefinition()
                    {
                        Height = .15f, Type = GridValueType.Percentage
                    },
                    new GridRowDefinition()
                    {
                        Height = .5f, Type = GridValueType.Percentage
                    },
                    new GridRowDefinition()
                    {
                        Height = .15f, Type = GridValueType.Percentage
                    },

                    // bottom margin
                    new GridRowDefinition()
                    {
                        Height = .1f, Type = GridValueType.Percentage
                    },
                }
            })).Fill();

            placeholderGrid.RefreshLayout();
            leftPlaceHolder = placeholderGrid.Add(new ConsolePanel()
            {
                Background = RGB.Green
            }, 1, 2, 1, 1);
            centerPlaceHolder = placeholderGrid.Add(new ConsolePanel()
            {
                Background = RGB.Green
            }, 3, 1, 1, 3);
            rightPlaceHolder = placeholderGrid.Add(new ConsolePanel()
            {
                Background = RGB.Green
            }, 5, 2, 1, 1);
            placeholderGrid.RefreshLayout();
            placeholderGrid.IsVisible = false;
        }