コード例 #1
0
ファイル: ShellFlyoutTests.cs プロジェクト: Glepooek/maui
        public async Task FlyoutCustomContentMargin(Func <Shell, object, string> shellPart)
        {
            var baselineContent = new VerticalStackLayout()
            {
                new Label()
                {
                    Text = "Flyout Layout Part"
                }
            };
            Rect frameWithoutMargin = Rect.Zero;

            // determine the location of the templated content on the screen without a margin
            await RunShellTest(shell =>
            {
                _ = shellPart(shell, baselineContent);
            },
                               async (shell, handler) =>
            {
                await OpenFlyout(handler);
                frameWithoutMargin = GetFrameRelativeToFlyout(handler, baselineContent);
            });

            var content = new VerticalStackLayout()
            {
                new Label()
                {
                    Text = "Flyout Layout Part"
                }
            };
            string partTesting = string.Empty;

            await RunShellTest(shell =>
            {
                content.Margin = new Thickness(20, 30, 0, 30);
                partTesting    = shellPart(shell, content);
            },
                               async (shell, handler) =>
            {
                await OpenFlyout(handler);

                var frameWithMargin = GetFrameRelativeToFlyout(handler, content);
                var leftDiff        = Math.Abs(Math.Abs(frameWithMargin.Left - frameWithoutMargin.Left) - 20);
                var verticalDiff    = Math.Abs(Math.Abs(frameWithMargin.Top - frameWithoutMargin.Top) - 30);

                AssertionExtensions.AssertWithMessage(() =>
                                                      Assert.True(leftDiff < 0.2),
                                                      $"{partTesting} Left Margin Incorrect. Frame w/ margin: {frameWithMargin}. Frame w/o marin : {frameWithoutMargin}"
                                                      );

                AssertionExtensions.AssertWithMessage(() =>
                                                      Assert.True(verticalDiff < 0.2),
                                                      $"{partTesting} Top Margin Incorrect. Frame w/ margin: {frameWithMargin}. Frame w/o marin : {frameWithoutMargin}"
                                                      );
            });
        }
コード例 #2
0
        public async Task GetVisualTreeElements()
        {
            SetupBuilder();
            var label = new Label()
            {
                Text = "Find Me"
            };
            var page = new ContentPage()
            {
                Title = "Title Page"
            };

            page.Content = new VerticalStackLayout()
            {
                label
            };

            var rootPage = await InvokeOnMainThreadAsync(() =>
                                                         new NavigationPage(page)
                                                         );

            await CreateHandlerAndAddToWindow <IWindowHandler>(rootPage, async handler =>
            {
                await OnFrameSetToNotEmpty(label);
                var locationOnScreen = label.GetLocationOnScreen().Value;
                var labelFrame       = label.Frame;
                var window           = rootPage.Window;

                // Find label at the top left corner
                var topLeft = new Graphics.Point(locationOnScreen.X + 1, locationOnScreen.Y + 1);

                AssertionExtensions.AssertWithMessage(
                    () => Assert.Contains(label, window.GetVisualTreeElements(topLeft)),
                    $"Unable to find label using top left coordinate: {topLeft} with label location: {label.GetBoundingBox()}");

                // find label at the bottom right corner
                var bottomRight = new Graphics.Point(
                    locationOnScreen.X + labelFrame.Width - 1,
                    locationOnScreen.Y + labelFrame.Height - 1);

                AssertionExtensions.AssertWithMessage(
                    () => Assert.Contains(label, window.GetVisualTreeElements(bottomRight)),
                    $"Unable to find label using bottom right coordinate: {bottomRight} with label location: {label.GetBoundingBox()}");

                // Ensure that the point directly outside the bounds of the label doesn't
                // return the label
                Assert.DoesNotContain(label, window.GetVisualTreeElements(
                                          locationOnScreen.X + labelFrame.Width + 1,
                                          locationOnScreen.Y + labelFrame.Height + 1
                                          ));
            });
        }
コード例 #3
0
ファイル: ShellFlyoutTests.cs プロジェクト: Glepooek/maui
        public async Task FlyoutHeaderMinimumHeight(FlyoutHeaderBehavior behavior)
        {
            await RunShellTest(shell =>
            {
                var layout = new VerticalStackLayout()
                {
                    new Label()
                    {
                        Text = "Flyout Header"
                    }
                };

                shell.FlyoutHeader         = layout;
                shell.FlyoutHeaderBehavior = behavior;
            },
                               async (shell, handler) =>
            {
                await OpenFlyout(handler);
                var flyoutFrame = GetFrameRelativeToFlyout(handler, shell.FlyoutHeader as IView);


                if (behavior == FlyoutHeaderBehavior.CollapseOnScroll)
                {
                    // 56 was pulled from the ActionBar height on Android
                    // and then just used across all three platforms for
                    // the min height when using collapse on scroll
                    AssertionExtensions.CloseEnough(56, flyoutFrame.Height);
                }
                else
                {
                    AssertionExtensions.AssertWithMessage(() =>
                                                          Assert.True(flyoutFrame.Height < 56),
                                                          $"Expected < 56 Actual: {flyoutFrame.Height}"
                                                          );
                }
            });
        }