예제 #1
0
        private Record ComputeChildSize(UIElement child, Orientation orientation, ref Size finalSize, ref double totalLength, ref double starTotal)
        {
            var sizeHint = GetChildSizeHint(child);
            var size     = new Size();

            if (GridLengthHelper.GetIsStar(sizeHint))
            {
                starTotal += sizeHint.Value;
            }
            else if (GridLengthHelper.GetIsAuto(sizeHint))
            {
                ComputeChildAutoSize(child, orientation, ref finalSize, ref totalLength, ref size);
            }
            else if (GridLengthHelper.GetIsAbsolute(sizeHint))
            {
                ComputeChildAbsoluteSize(orientation, ref finalSize, ref totalLength, ref sizeHint, ref size);
            }

            return(new Record
            {
                Child = child,
                Size = size,
                SizeHint = sizeHint,
            });
        }
        private static bool FastDoubleConvert(Type outputType, double doubleInput, ref object output)
        {
            if (outputType == typeof(GridLength))
            {
                output = GridLengthHelper.FromPixels(doubleInput);
                return(true);
            }

            return(false);
        }
예제 #3
0
 private void MeasureStarChildren(Size availableSize, Orientation orientation, ref Size totalSize, double starTotal, UIElement[] children)
 {
     if (starTotal != 0)
     {
         foreach (UIElement child in children)
         {
             var sizeHint = GetChildSizeHint(child);
             if (GridLengthHelper.GetIsStar(sizeHint))
             {
                 MesureChildStar(child, orientation, availableSize, sizeHint, starTotal, ref totalSize);
             }
         }
     }
 }
예제 #4
0
        private void MeasureChild(UIElement child, Size availableSize, Orientation orientation, ref Size totalSize, ref double starTotal)
        {
            var sizeHint = GetChildSizeHint(child);

            if (GridLengthHelper.GetIsStar(sizeHint))
            {
                starTotal += sizeHint.Value;
            }
            else if (GridLengthHelper.GetIsAuto(sizeHint))
            {
                MesureChildAuto(child, orientation, availableSize, ref totalSize);
            }
            else if (GridLengthHelper.GetIsAbsolute(sizeHint))
            {
                MesureChildAbsolute(child, orientation, availableSize, sizeHint, ref totalSize);
            }
        }
예제 #5
0
        private static bool FastNumberConvert(Type outputType, object input, ref object output)
        {
            if (input is double doubleInput)
            {
                if (outputType == typeof(float))
                {
                    output = (float)doubleInput;
                    return(true);
                }
                if (outputType == typeof(TimeSpan))
                {
                    output = TimeSpan.FromSeconds(doubleInput);
                    return(true);
                }
                if (outputType == typeof(GridLength))
                {
                    output = GridLengthHelper.FromPixels(doubleInput);
                    return(true);
                }
            }

            if (input is int intInput)
            {
                if (outputType == typeof(float))
                {
                    output = (float)intInput;
                    return(true);
                }
                if (outputType == typeof(TimeSpan))
                {
                    output = TimeSpan.FromSeconds(intInput);
                    return(true);
                }
                if (outputType == typeof(GridLength))
                {
                    output = GridLengthHelper.FromPixels(intInput);
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
        private static Size ComputeFinalChildSize(Record record, Orientation orientation, ref Size finalSize, double starRatio)
        {
            var size = record.Size;

            if (GridLengthHelper.GetIsStar(record.SizeHint))
            {
                var portion = record.SizeHint.Value * starRatio;

                if (orientation == Orientation.Vertical)
                {
                    size.Width  = finalSize.Width;
                    size.Height = portion;
                }
                else
                {
                    size.Width  = portion;
                    size.Height = finalSize.Height;
                }
            }

            return(size);
        }
예제 #7
0
        private void UpdateExpandedMode()
        {
            if (_rootSplitView != null)
            {
                _rootSplitView.DisplayMode = SplitViewDisplayMode.CompactInline;
            }

            DisplayMode = NavigationViewDisplayMode.Expanded;

            if (_paneContentGrid != null && _navigationViewBackButton != null)
            {
                _paneContentGrid.RowDefinitions.ElementAt(1).Height = GridLengthHelper.FromPixels(_navigationViewBackButton.RenderSize.Height);
            }

            if (_paneTitleTextBlock != null && _togglePaneButton != null)
            {
                _paneTitleTextBlock.Margin = new Thickness(_togglePaneButton.RenderSize.Width, 0, 0, 0);
            }

            if (_togglePaneButton != null && _navigationViewBackButton != null)
            {
                _togglePaneButton.Margin = new Thickness(0, _navigationViewBackButton.Height, 0, 0);
            }
        }
예제 #8
0
        private void UpdateCompactMode()
        {
            if (_rootSplitView != null)
            {
                _rootSplitView.DisplayMode = SplitViewDisplayMode.Overlay;
            }

            DisplayMode = NavigationViewDisplayMode.Compact;

            if (_paneContentGrid != null && _buttonHolderGrid != null)
            {
                _paneContentGrid.RowDefinitions.ElementAt(1).Height = GridLengthHelper.FromPixels(0);
            }

            if (_paneTitleTextBlock != null)
            {
                _paneTitleTextBlock.Margin = IsPaneOpen ? new Thickness(_togglePaneButton.RenderSize.Width + _navigationViewBackButton.RenderSize.Width, 0, 0, 0) : new Thickness(0, 0, 0, 0);
            }

            if (_togglePaneButton != null && _navigationViewBackButton != null)
            {
                _togglePaneButton.Margin = new Thickness(_navigationViewBackButton.Width, 0, 0, 0);
            }
        }
예제 #9
0
        public async Task When_Has_ColumnSpacing(double columnSpacing,
                                                 double rowSpacing,
                                                 double gridDesiredWidthExpected, double gridDesiredHeightExpected,
                                                 double child0LeftExpected, double child0TopExpected, double child0WidthExpected, double child0HeightExpected,
                                                 double child1LeftExpected, double child1TopExpected, double child1WidthExpected, double child1HeightExpected,
                                                 double child2LeftExpected, double child2TopExpected, double child2WidthExpected, double child2HeightExpected,
                                                 double child3LeftExpected, double child3TopExpected, double child3WidthExpected, double child3HeightExpected,
                                                 double child4LeftExpected, double child4TopExpected, double child4WidthExpected, double child4HeightExpected,
                                                 double child5LeftExpected, double child5TopExpected, double child5WidthExpected, double child5HeightExpected,
                                                 double child6LeftExpected, double child6TopExpected, double child6WidthExpected, double child6HeightExpected
                                                 )
        {
            await RunOnUIThread.ExecuteAsync(() =>
            {
                TestServices.WindowHelper.WindowContent = null;
            });

            Grid SUT = null;
            await RunOnUIThread.ExecuteAsync(() =>
            {
                SUT = new Grid
                {
                    ColumnSpacing     = columnSpacing,
                    RowSpacing        = rowSpacing,
                    ColumnDefinitions =
                    {
                        new ColumnDefinition {
                            Width = GridLengthHelper.FromValueAndType(1, GridUnitType.Star)
                        },
                        new ColumnDefinition {
                            Width = GridLengthHelper.FromValueAndType(1, GridUnitType.Auto)
                        },
                        new ColumnDefinition {
                            Width = GridLengthHelper.FromValueAndType(1, GridUnitType.Star)
                        },
                    },
                    RowDefinitions =
                    {
                        new RowDefinition {
                            Height = GridLengthHelper.FromValueAndType(1, GridUnitType.Auto)
                        },
                        new RowDefinition {
                            Height = GridLengthHelper.FromValueAndType(1, GridUnitType.Star)
                        },
                        new RowDefinition {
                            Height = GridLengthHelper.FromValueAndType(1, GridUnitType.Star)
                        },
                    },
                    Children =
                    {
                        GetChild(0,  0, height: 20),
                        GetChild(1,  0, width:30,   height:20),
                        GetChild(2,  0, height:20),

                        GetChild(0,  1, rowSpan:2),
                        GetChild(1,  1, width:30),
                        GetChild(2, 1),

                        GetChild(1,  2, colSpan: 2)
                    }
                };

                var outerBorder = new Border {
                    Width = 250, Height = 300
                };
                outerBorder.Child = SUT;

                TestServices.WindowHelper.WindowContent = outerBorder;

                FrameworkElement GetChild(int gridCol, int gridRow, int?colSpan = null, int?rowSpan = null, double?width = null, double?height = null)
                {
                    var child = new Border();

                    Grid.SetColumn(child, gridCol);
                    Grid.SetRow(child, gridRow);
                    if (colSpan.HasValue)
                    {
                        Grid.SetColumnSpan(child, colSpan.Value);
                    }
                    if (rowSpan.HasValue)
                    {
                        Grid.SetRowSpan(child, rowSpan.Value);
                    }
                    if (width.HasValue)
                    {
                        child.Width = width.Value;
                    }
                    else
                    {
                        child.HorizontalAlignment = HorizontalAlignment.Stretch;
                    }
                    if (height.HasValue)
                    {
                        child.Height = height.Value;
                    }
                    else
                    {
                        child.VerticalAlignment = VerticalAlignment.Stretch;
                    }

                    return(child);
                }
            });

            await WaitForMeasure(SUT);

            await RunOnUIThread.ExecuteAsync(() =>
            {
                var desiredSize = SUT.DesiredSize;
                var data        = $"({columnSpacing}, {rowSpacing}, {desiredSize.Width}, {desiredSize.Height}";
                foreach (var child in SUT.Children)
                {
                    var layoutRect = LayoutInformation.GetLayoutSlot(child as FrameworkElement);
                    data          += $", {layoutRect.Left}, {layoutRect.Top}, {layoutRect.Width}, {layoutRect.Height}";
                }
                data += ")";
                Debug.WriteLine(data);

                Assert.AreEqual(new Size(gridDesiredWidthExpected, gridDesiredHeightExpected), desiredSize);

#if !__ANDROID__ && !__IOS__ // These assertions fail on Android/iOS because layout slots aren't set the same way as UWP
                var layoutRect0Actual   = LayoutInformation.GetLayoutSlot(SUT.Children[0] as FrameworkElement);
                var layoutRect0Expected = new Rect(child0LeftExpected, child0TopExpected, child0WidthExpected, child0HeightExpected);
                Assert.AreEqual(layoutRect0Expected, layoutRect0Actual);

                var layoutRect1Actual   = LayoutInformation.GetLayoutSlot(SUT.Children[1] as FrameworkElement);
                var layoutRect1Expected = new Rect(child1LeftExpected, child1TopExpected, child1WidthExpected, child1HeightExpected);
                Assert.AreEqual(layoutRect1Expected, layoutRect1Actual);

                var layoutRect2Actual   = LayoutInformation.GetLayoutSlot(SUT.Children[2] as FrameworkElement);
                var layoutRect2Expected = new Rect(child2LeftExpected, child2TopExpected, child2WidthExpected, child2HeightExpected);
                Assert.AreEqual(layoutRect2Expected, layoutRect2Actual);

                var layoutRect3Actual   = LayoutInformation.GetLayoutSlot(SUT.Children[3] as FrameworkElement);
                var layoutRect3Expected = new Rect(child3LeftExpected, child3TopExpected, child3WidthExpected, child3HeightExpected);
                Assert.AreEqual(layoutRect3Expected, layoutRect3Actual);

                var layoutRect4Actual   = LayoutInformation.GetLayoutSlot(SUT.Children[4] as FrameworkElement);
                var layoutRect4Expected = new Rect(child4LeftExpected, child4TopExpected, child4WidthExpected, child4HeightExpected);
                Assert.AreEqual(layoutRect4Expected, layoutRect4Actual);

                var layoutRect5Actual   = LayoutInformation.GetLayoutSlot(SUT.Children[5] as FrameworkElement);
                var layoutRect5Expected = new Rect(child5LeftExpected, child5TopExpected, child5WidthExpected, child5HeightExpected);
                Assert.AreEqual(layoutRect5Expected, layoutRect5Actual);

                var layoutRect6Actual   = LayoutInformation.GetLayoutSlot(SUT.Children[6] as FrameworkElement);
                var layoutRect6Expected = new Rect(child6LeftExpected, child6TopExpected, child6WidthExpected, child6HeightExpected);
                Assert.AreEqual(layoutRect6Expected, layoutRect6Actual);
#endif

                TestServices.WindowHelper.WindowContent = null;
            });
        }
예제 #10
0
 public object Convert(object value, Type targetType, object parameter, string language)
 {
     return(GridLengthHelper.FromPixels((value as IConvertible).ToDouble(null)));
 }