Beispiel #1
0
        public void TestScrollableContentBasic()
        {
            var app = new CliTestHarness(this.TestContext, 80, 10, true);

            app.SecondsBetweenKeyframes = .1f;
            app.LayoutRoot.Background   = RGB.Red;
            app.InvokeNextCycle(async() =>
            {
                // We want to have a stack panel that can scroll if it gets too big

                // Step 1 - Create a scroll panel and size it how you like
                var scrollPanel = app.LayoutRoot.Add(new ScrollablePanel()
                {
                    Background = RGB.DarkBlue
                }).Fill();

                // Step 2 - Add scrollable content to the ScrollableContent container
                var stack = scrollPanel.ScrollableContent.Add(new StackPanel()
                {
                    Background = RGB.Yellow, AutoSize = true
                });

                // IMPORTANT - The ScrollableContent container is the thing that will scroll if it's bigger than the view
                //             so make sure it's height gets bigger as its content grows.
                stack.SubscribeForLifetime(nameof(stack.Bounds), () => scrollPanel.ScrollableContent.Height = stack.Height, stack);

                // Step 3 - Add 100 focusable rows to the stack panel. Making the rows focusable is critical since
                //          the scroll panel will automatically take care of scrolling to the currently focused control
                //          if that control is within the ScrollableContent.
                var rows = 100;
                for (var i = 1; i <= rows; i++)
                {
                    var label = stack.Add(new Label()
                    {
                        CanFocus = true, Text = $"row {i} of {rows}".ToWhite()
                    });
                    label.Focused.SubscribeForLifetime(() => label.Text = label.Text.ToCyan(), label);
                    label.Focused.SubscribeForLifetime(() => label.Text = label.Text.ToWhite(), label);
                }

                // Step 4 - Tab through all the rows. The scrollbar and scrollable content should automatically
                //        - keep the focused row in view.
                for (var i = 0; i < rows; i++)
                {
                    app.SendKey(new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false));
                    await app.PaintAndRecordKeyFrameAsync();
                }
                app.Stop();
            });

            app.Run();
            app.AssertThisTestMatchesLKG();
        }
Beispiel #2
0
        public void TestThreeMonthCalendarBasicRender()
        {
            var app = new CliTestHarness(this.TestContext, 120, 40);

            app.Invoke(async() =>
            {
                var carousel = new ThreeMonthCarousel(new ThreeMonthCarouselOptions()
                {
                    Month = 1, Year = 2000
                });
                var start = carousel.Options.Month + "/" + carousel.Options.Year;
                app.LayoutRoot.Add(new FixedAspectRatioPanel(4f / 1f, carousel)).Fill();
                Assert.IsTrue(await carousel.SeekAsync(true, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(true, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(true, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(true, carousel.Options.AnimationDuration));

                await Task.Delay(3000);

                var now = carousel.Options.Month + "/" + carousel.Options.Year;
                Assert.AreNotEqual(start, now);

                Assert.IsTrue(await carousel.SeekAsync(false, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(false, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(false, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(false, carousel.Options.AnimationDuration));
                await Task.Delay(1000);

                now = carousel.Options.Month + "/" + carousel.Options.Year;
                Assert.AreEqual(start, now);
                app.Stop();
            });
            app.Run();
            app.AssertThisTestMatchesLKGFirstAndLastFrame();
        }