Esempio n. 1
0
 protected override GameObject RenderToObject(LayoutInformation layout)
 {
     throw new NotImplementedException();
 }
Esempio n. 2
0
        internal bool HitTest(Point touchPoint)
        {
            Rect layoutSlot = LayoutInformation.GetLayoutSlot(this);

            return(layoutSlot.Contains(touchPoint));
        }
Esempio n. 3
0
 internal override void InvalidateMeasureInternal(InvalidationTrigger trigger)
 {
     _layoutInformation = new LayoutInformation();
     base.InvalidateMeasureInternal(trigger);
 }
Esempio n. 4
0
        void ProcessExpanders(LayoutInformation layout, StackOrientation orientation, double x, double y, double widthConstraint, double heightConstraint)
        {
            if (layout.Expanders <= 0)
            {
                return;
            }

            if (orientation == StackOrientation.Vertical)
            {
                double extraSpace = heightConstraint - layout.Bounds.Height;
                if (extraSpace <= 0)
                {
                    return;
                }

                double spacePerExpander = extraSpace / layout.Expanders;
                double yOffset          = 0;

                for (var i = 0; i < LogicalChildrenInternal.Count; i++)
                {
                    var child = (View)LogicalChildrenInternal[i];
                    if (!child.IsVisible)
                    {
                        continue;
                    }
                    Rectangle plot = layout.Plots[i];
                    plot.Y += yOffset;

                    if (child.VerticalOptions.Expands)
                    {
                        plot.Height += spacePerExpander;
                        yOffset     += spacePerExpander;
                    }

                    layout.Plots[i] = plot;
                }

                layout.Bounds.Height = heightConstraint;
            }
            else
            {
                double extraSpace = widthConstraint - layout.Bounds.Width;
                if (extraSpace <= 0)
                {
                    return;
                }

                double spacePerExpander = extraSpace / layout.Expanders;
                double xOffset          = 0;

                for (var i = 0; i < LogicalChildrenInternal.Count; i++)
                {
                    var child = (View)LogicalChildrenInternal[i];
                    if (!child.IsVisible)
                    {
                        continue;
                    }
                    Rectangle plot = layout.Plots[i];
                    plot.X += xOffset;

                    if (child.HorizontalOptions.Expands)
                    {
                        plot.Width += spacePerExpander;
                        xOffset    += spacePerExpander;
                    }

                    layout.Plots[i] = plot;
                }

                layout.Bounds.Width = widthConstraint;
            }
        }
Esempio n. 5
0
        private RectangleGeometry GetBoundingRectangle(FrameworkElement element)
        {
            Rect rect = element == this.ChartArea ? new Rect(0.0, 0.0, this.ActualWidth, this.ActualHeight) : LayoutInformation.GetLayoutSlot(element);

            return(new RectangleGeometry()
            {
                Rect = RectExtensions.TranslateToParent(rect, element, (FrameworkElement)this.ChartArea)
            });
        }
Esempio n. 6
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.Execute(() =>
            {
                TestServices.WindowHelper.WindowContent = null;
            });

            Grid SUT = null;
            await RunOnUIThread.Execute(() =>
            {
                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.Execute(() =>
            {
                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;
            });
        }
Esempio n. 7
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (box != null && box.IsSpellCheckEnabled && box.IsSpellcheckCompleted)
            {
                foreach (var word in box.Checker.MisspelledWords)
                {
                    List <Word> words = new List <Word>();

                    Word wordpart = word;
                    do
                    {
                        var split = Split(wordpart);
                        words.Add(split.Item1);
                        wordpart = split.Item2;
                    }while (wordpart != null);

                    foreach (var mWord in words)
                    {
                        Rect rectangleBounds = new Rect();
                        rectangleBounds = box.TransformToVisual(GetTopLevelControl(box) as Visual).TransformBounds(LayoutInformation.GetLayoutSlot(box));

                        Rect startRect = box.GetRectFromCharacterIndex((Math.Min(mWord.Index, box.Text.Length)));
                        Rect endRect   = box.GetRectFromCharacterIndex(Math.Min(mWord.Index + mWord.Length, box.Text.Length));

                        Rect startRectM = box.GetRectFromCharacterIndex((Math.Min(mWord.Index, box.Text.Length)));
                        Rect endRectM   = box.GetRectFromCharacterIndex(Math.Min(mWord.Index + mWord.Length, box.Text.Length));

                        startRectM.X += rectangleBounds.X;
                        startRectM.Y += rectangleBounds.Y;
                        endRectM.X   += rectangleBounds.X;
                        endRectM.Y   += rectangleBounds.Y;

                        if (rectangleBounds.Contains(startRectM) && rectangleBounds.Contains(endRectM))
                        {
                            drawingContext.DrawLine(pen, startRect.BottomLeft, endRect.BottomRight);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a work item layout.
        /// </summary>
        /// <param name="layoutInformation">The list information to be used to create the work item layout.</param>
        /// <returns>An instance of the <see cref="WorkItemLayout"/> class.</returns>
        private WorkItemLayout CreateWorkItemLayout(LayoutInformation layoutInformation)
        {
            WorkItemLayout sut = new WorkItemLayout(layoutInformation, this.mockTeamProjectTemplate.Object);

            return(sut);
        }
        /// §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
        /// <summary>
        /// Arrange pass.  Call base method to figure out menu item placement,
        /// then place tick marks at the centers of the menu items.
        /// </summary>
        /// <param name="arrangeBounds"></param>
        /// <returns></returns>
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            Size returnSize = base.ArrangeOverride(arrangeBounds);

            FrameworkElement topElement    = null;
            FrameworkElement bottomElement = null;

            for (int i = 0; i < Items.Count; i++)
            {
                FrameworkElement elem = Items[i] as FrameworkElement;

                Debug.Assert(elem != null, "Added an object that wasn't a FrameworkElement??");

                // Find the bottom element.  It must have a value greater or equal to the
                // top element
                if (topElement != null)
                {
                    if ((double)elem.GetValue(SliderMenuItem.ValueProperty) >=
                        (double)topElement.GetValue(SliderMenuItem.ValueProperty))
                    {
                        bottomElement = elem;
                    }
                }

                // Move along.  Nothing to see here.
                if ((bool)(elem.GetValue(SliderMenuItem.SkipProperty)))
                {
                    continue;
                }

                // set the first element
                if (topElement == null)
                {
                    topElement = elem;
                }
            }

            // Single element.  Not much of a slider, but don't crash
            if (bottomElement == null && topElement != null)
            {
                bottomElement = topElement;
            }

            // No elements.  Nothing to do.
            if (bottomElement == null && topElement == null)
            {
                return(returnSize);
            }

            // Calculate top, bottom margins.
            // This margin enables the thumb stop at 0 and 100 to line up with
            // the center of the top and bottom menu items.
            Rect bound = LayoutInformation.GetLayoutSlot(topElement);

            double topMargin = bound.Top + ThumbHeight / 2;
            double pointZero = bound.Top + bound.Height / 2.0;

            bound = LayoutInformation.GetLayoutSlot(bottomElement);

            double bottomMargin    = returnSize.Height - bound.Bottom + ThumbHeight / 2.0d;
            double pointOneHundred = bound.Top + bound.Height / 2.0d;

            // Set the margin.
            m_Slider.Margin = new Thickness(0, topMargin, 0, bottomMargin);


            for (int i = 0; i < Items.Count; i++)
            {
                FrameworkElement elem = Items[i] as FrameworkElement;

                if (elem is MenuItem)
                {
                    ((MenuItem)elem).Click += new RoutedEventHandler(SliderMenuItem_Click);
                }

                // Move along.  Nothing to see here.
                if ((bool)(elem.GetValue(SliderMenuItem.SkipProperty)))
                {
                    continue;
                }

                // Grab the coordinates of the child menu item
                bound = LayoutInformation.GetLayoutSlot(elem);

                // Get the number of steps, or tick spots between this child menu item
                //  and the previous one.
                int steps = (int)elem.GetValue(SliderMenuItem.StepsProperty);

                // A value of 0 for Steps is like setting Skip = true
                if (steps < 1)
                {
                    continue;
                }

                // Calculate tick spot.
                double thisTickSpot = 1000.0d * (bound.Top - pointZero + bound.Height / 2.0d)
                                      / (pointOneHundred - pointZero);

                // Calculate continuous tick spots.  Only allow continuous after the first element.
                if (m_Slider.Ticks.Count > 0)
                {
                    double lastTickSpot = m_Slider.Ticks[m_Slider.Ticks.Count - 1];
                    double division     = (thisTickSpot - lastTickSpot) / steps;

                    for (int current_step = 1; current_step < steps; current_step++)
                    {
                        double intermediateTickSpot = lastTickSpot + current_step * division;
                        m_Slider.Ticks.Add(intermediateTickSpot);
                    }
                }

                m_Slider.Ticks.Add(thisTickSpot);
                double sliderValue = (double)elem.GetValue(SliderMenuItem.ValueProperty);
                m_TickValueMap[thisTickSpot] = sliderValue;
            }

            // At end of arrange pass, set the tick to the inital value
            SetTickToValue(this, Value);

            return(returnSize);
        }
Esempio n. 10
0
        /// <inheritdoc />
        protected override void OnRender(DrawingContext drawingContext)
        {
            Visual topLevelControl = GetTopLevelControl(textBox) as Visual;
            Rect   controlBounds, wordBounds, startRect, endRect;

            if (topLevelControl != null)
            {
                try
                {
                    controlBounds = textBox.TransformToVisual(topLevelControl).TransformBounds(
                        LayoutInformation.GetLayoutSlot(textBox));

                    // If the scroll bars are visible, shrink the control bounds to avoid drawing over them
                    var scrollViewer = GetDescendants(textBox).OfType <ScrollViewer>().First();

                    if (scrollViewer != null)
                    {
                        if (scrollViewer.ComputedVerticalScrollBarVisibility == Visibility.Visible)
                        {
                            controlBounds.Width -= SystemParameters.VerticalScrollBarWidth + 1;
                        }

                        if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
                        {
                            controlBounds.Height -= SystemParameters.HorizontalScrollBarHeight + 1;
                        }
                    }

                    // Limit what's drawn to what's visible to improve performance in text boxes with lots of
                    // content.  We also cache the computed bounds below.
                    int nearestIndex = textBox.GetCharacterIndexFromLineIndex(textBox.GetFirstVisibleLineIndex());

                    foreach (var word in misspelledWords)
                    {
                        if (word.Span.Start < nearestIndex)
                        {
                            continue;
                        }

                        if (word.ActualBounds == Rect.Empty)
                        {
                            if (word.Span.Start + word.Span.Length > textBox.Text.Length)
                            {
                                continue;
                            }

                            startRect = textBox.GetRectFromCharacterIndex(word.Span.Start);
                            endRect   = textBox.GetRectFromCharacterIndex(word.Span.Start + word.Span.Length);

                            word.ActualBounds = new Rect(startRect.X + textBox.HorizontalOffset,
                                                         startRect.Y + textBox.VerticalOffset, Math.Max(endRect.X - startRect.X, 0),
                                                         endRect.Height);
                        }

                        wordBounds = word.ActualBounds;
                        wordBounds.Offset(controlBounds.X - textBox.HorizontalOffset,
                                          controlBounds.Y - textBox.VerticalOffset);

                        if (wordBounds.Y > controlBounds.Y + controlBounds.Height)
                        {
                            break;
                        }

                        if (word.ActualBounds.Width > 0 && controlBounds.Contains(wordBounds.BottomLeft))
                        {
                            drawingContext.DrawLine(pen,
                                                    new Point(word.ActualBounds.Left - textBox.HorizontalOffset,
                                                              Math.Min((word.ActualBounds.Y + word.ActualBounds.Height - textBox.VerticalOffset),
                                                                       controlBounds.Height)),
                                                    new Point(Math.Min(word.ActualBounds.Right - textBox.HorizontalOffset, controlBounds.Width),
                                                              Math.Min((word.ActualBounds.Y + word.ActualBounds.Height - textBox.VerticalOffset),
                                                                       controlBounds.Height)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    // If we get any out of bounds errors, just ignore them
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }
        }
Esempio n. 11
0
 public static Rect GetContainerRectangle([NotNull] this FrameworkElement element)
 {
     return(element.TransformToVisual(Window.Current.Content).TransformBounds(LayoutInformation.GetLayoutSlot(element)));
 }
        protected override Size ArrangeOverride(Size finalSize)
        {
            //Rect ro = new Rect(0, 0, AdornedElement.DesiredSize.Width, AdornedElement.DesiredSize.Height);
            Rect             ro = LayoutInformation.GetLayoutSlot(AdornedElement as FrameworkElement);
            FrameworkElement control;

            foreach (Visual v in visualChildren)
            {
                if (v is FrameworkElement)
                {
                    control = v as FrameworkElement;
                }
                else
                {
                    continue;
                }

                Rect aligmentRect = new Rect();
                aligmentRect.Width  = control.DesiredSize.Width;
                aligmentRect.Height = control.DesiredSize.Height;
                aligmentRect.Y      = ro.Y;
                aligmentRect.X      = ro.X;
                switch (control.VerticalAlignment)
                {
                case VerticalAlignment.Top: aligmentRect.Y += 0;
                    break;

                case VerticalAlignment.Bottom: aligmentRect.Y += ro.Height;
                    break;

                case VerticalAlignment.Center: aligmentRect.Y += ro.Height / 2;
                    break;

                case VerticalAlignment.Stretch: aligmentRect.Height = ro.Height;    // *Math.Abs((AdornedElement.RenderTransform as TransformGroup).Children[0].Value.M22);
                    break;

                default:
                    break;
                }
                switch (control.HorizontalAlignment)
                {
                case HorizontalAlignment.Left: aligmentRect.X += -aligmentRect.Width;
                    break;

                case HorizontalAlignment.Right: aligmentRect.X += ro.Width;
                    break;

                case HorizontalAlignment.Center: aligmentRect.X += ro.Width / 2;
                    break;

                case HorizontalAlignment.Stretch: aligmentRect.Width = ro.Width;    // *Math.Abs((AdornedElement.RenderTransform as TransformGroup).Children[0].Value.M11);
                    break;

                default:
                    break;
                }

                aligmentRect.X = _view.MainPanel.TranslatePoint(aligmentRect.TopLeft, this).X;
                aligmentRect.Y = _view.MainPanel.TranslatePoint(aligmentRect.TopLeft, this).Y;

                control.Arrange(aligmentRect);
            }
            return(finalSize);
        }
Esempio n. 13
0
        public void When_Child_Is_Stretch()
        {
            var parentSize = new Windows.Foundation.Size(500, 500);

            var SUT = new Border()
            {
                Width  = parentSize.Width,
                Height = parentSize.Height
            };

            var child = new View();

            SUT.Child = child;

            SUT.Measure(new Windows.Foundation.Size(500, 500));
            var measuredSize = SUT.DesiredSize;

            SUT.Arrange(new Windows.Foundation.Rect(0, 0, 500, 500));

            Assert.AreEqual(parentSize, measuredSize);
            Assert.AreEqual(new Windows.Foundation.Rect(0, 0, parentSize.Width, parentSize.Height), LayoutInformation.GetLayoutSlot(child));
        }
Esempio n. 14
0
 /// <summary>
 /// Computes the bound of a framework element relatively to a given visual host.
 /// </summary>
 /// <param name="pElement">The element of interest.</param>
 /// <param name="pRelativeTo">The visual host.</param>
 /// <returns>The computed bound.</returns>
 public static Rect BoundsRelativeTo(this FrameworkElement pElement, Visual pRelativeTo)
 {
     return(pElement.TransformToVisual(pRelativeTo).TransformBounds(LayoutInformation.GetLayoutSlot(pElement)));
 }
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (box != null && box.IsSpellCheckEnabled && !adornerClear)
            {
                int startLineIndex = box.GetFirstVisibleLineIndex();
                int endLineIndex   = box.GetLastVisibleLineIndex();

                int lineFirstCharIndex = 0;
                int lastLineIndex      = 0;

                for (var i = 0; i < box.misspelledWords.Count; i++)
                {
                    Word word = box.misspelledWords[i];
                    if (word.LineIndex < startLineIndex)
                    {
                        continue;
                    }
                    if (word.LineIndex > endLineIndex)
                    {
                        break;
                    }
                    if (lastLineIndex != word.LineIndex)
                    {
                        lineFirstCharIndex = box.GetCharacterIndexFromLineIndex(word.LineIndex);
                    }
                    var rectangleBounds = box.TransformToVisual(GetTopLevelControl(box) as Visual).TransformBounds(LayoutInformation.GetLayoutSlot(box));

                    Rect startRect = box.GetRectFromCharacterIndex((Math.Min(lineFirstCharIndex + word.Index, box.Text.Length)));
                    Rect endRect   = box.GetRectFromCharacterIndex(Math.Min(lineFirstCharIndex + word.Index + word.Length, box.Text.Length));

                    //new Rect(startRect.BottomLeft.X,startRect.BottomLeft.Y, endRect.BottomRight.X, endRect.BottomRight.Y
                    //Contains(double x, double y)

                    if ((rectangleBounds.Contains(startRect.TopLeft.X + rectangleBounds.X, startRect.TopLeft.Y + rectangleBounds.Y) && rectangleBounds.Contains(startRect.BottomRight.X + rectangleBounds.X, startRect.BottomRight.Y + rectangleBounds.Y)))
                    {
                        drawingContext.DrawLine(pen, startRect.BottomLeft, endRect.BottomRight);
                    }
                }
            }
        }
Esempio n. 16
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            Point renderLocation = Location.Resolve(layout, layoutContext.Options);

            TextAlignment tempAlignment = Alignment;

            if (layout.IsFlipped && layout.Orientation == Orientation.Horizontal)
            {
                switch (Alignment)
                {
                case TextAlignment.BottomLeft:
                    tempAlignment = TextAlignment.BottomRight;
                    break;

                case TextAlignment.BottomRight:
                    tempAlignment = TextAlignment.BottomLeft;
                    break;

                case TextAlignment.CentreLeft:
                    tempAlignment = TextAlignment.CentreRight;
                    break;

                case TextAlignment.CentreRight:
                    tempAlignment = TextAlignment.CentreLeft;
                    break;

                case TextAlignment.TopLeft:
                    tempAlignment = TextAlignment.TopRight;
                    break;

                case TextAlignment.TopRight:
                    tempAlignment = TextAlignment.TopLeft;
                    break;
                }
            }
            else if (layout.IsFlipped && layout.Orientation == Orientation.Vertical)
            {
                switch (Alignment)
                {
                case TextAlignment.BottomCentre:
                    tempAlignment = TextAlignment.TopCentre;
                    break;

                case TextAlignment.BottomLeft:
                    tempAlignment = TextAlignment.TopLeft;
                    break;

                case TextAlignment.BottomRight:
                    tempAlignment = TextAlignment.TopRight;
                    break;

                case TextAlignment.TopCentre:
                    tempAlignment = TextAlignment.BottomCentre;
                    break;

                case TextAlignment.TopLeft:
                    tempAlignment = TextAlignment.BottomLeft;
                    break;

                case TextAlignment.TopRight:
                    tempAlignment = TextAlignment.BottomRight;
                    break;
                }
            }

            List <TextRun> renderTextRuns = new List <TextRun>(TextRuns.Count);

            // Build runs
            foreach (TextRun run in TextRuns)
            {
                // Resolve value
                string renderValue;
                if (run.Text.StartsWith("$"))
                {
                    renderValue = layoutContext.GetFormattedVariable(run.Text);
                }
                else
                {
                    renderValue = run.Text;
                }

                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\\[uU]([0-9A-F]{4})");
                renderValue = regex.Replace(renderValue, match => ((char)int.Parse(match.Value.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToString());

                renderTextRuns.Add(new TextRun(renderValue, run.Formatting));
            }

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawText(Point.Add(renderLocation, layout.Location), tempAlignment, renderTextRuns);
            }
            else
            {
                drawingContext.DrawText(renderLocation, tempAlignment, renderTextRuns);
            }
        }
Esempio n. 17
0
 public static Rect BoundsRelativeTo(FrameworkElement element, Visual relativeTo)
 {
     return(element.TransformToVisual(relativeTo).TransformBounds(LayoutInformation.GetLayoutSlot(element)));
 }
Esempio n. 18
0
        public void ConstructorChecksTeamProjectTemplateParameterForNull()
        {
            LayoutInformation li = TestHelper.CreateTestLayoutInformation(BuildingBlockName.Default);

            TestHelper.TestForArgumentNullException(() => new WorkItemLayout(li, null), "teamProjectTemplate");
        }
Esempio n. 19
0
 /// <summary>
 /// Handles the <see cref="ILayoutPickerWizardPageView.LayoutSelected"/> event and sets the button state according to the state of the query selection.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="e">The event data</param>
 private void HandleLayoutSelected(object sender, LayoutItemEventArgs e)
 {
     this.SelectedLayout = e.LayoutItem;
     this.IsValid        = true;
     this.OnValidityChanged();
 }
Esempio n. 20
0
 public static Rect Clamp(this Rect source, [NotNull] FrameworkElement element)
 {
     return(RectHelper.Intersect(LayoutInformation.GetLayoutSlot(element), source));
 }
Esempio n. 21
0
        internal static Rect GetLayoutRect(FrameworkElement element)
        {
            var actualWidth  = element.ActualWidth;
            var actualHeight = element.ActualHeight;

            if (element is Image || element is MediaElement)
            {
                if (element.Parent is Canvas)
                {
                    actualWidth  = double.IsNaN(element.Width) ? actualWidth : element.Width;
                    actualHeight = double.IsNaN(element.Height) ? actualHeight : element.Height;
                }
                else
                {
                    actualWidth  = element.RenderSize.Width;
                    actualHeight = element.RenderSize.Height;
                }
            }
            actualWidth  = element.Visibility == Visibility.Collapsed ? 0.0 : actualWidth;
            actualHeight = element.Visibility == Visibility.Collapsed ? 0.0 : actualHeight;
            var margin     = element.Margin;
            var layoutSlot = LayoutInformation.GetLayoutSlot(element);
            var x          = 0.0;
            var y          = 0.0;

            switch (element.HorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                x = layoutSlot.Left + margin.Left;
                break;

            case HorizontalAlignment.Center:
                x = (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - actualWidth / 2.0;
                break;

            case HorizontalAlignment.Right:
                x = layoutSlot.Right - margin.Right - actualWidth;
                break;

            case HorizontalAlignment.Stretch:
                x = Math.Max(layoutSlot.Left + margin.Left,
                             (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - actualWidth / 2.0);
                break;
            }
            switch (element.VerticalAlignment)
            {
            case VerticalAlignment.Top:
                y = layoutSlot.Top + margin.Top;
                break;

            case VerticalAlignment.Center:
                y = (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - actualHeight / 2.0;
                break;

            case VerticalAlignment.Bottom:
                y = layoutSlot.Bottom - margin.Bottom - actualHeight;
                break;

            case VerticalAlignment.Stretch:
                y = Math.Max(layoutSlot.Top + margin.Top,
                             (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - actualHeight / 2.0);
                break;
            }
            return(new Rect(x, y, actualWidth, actualHeight));
        }
Esempio n. 22
0
        internal static Rect GetLayoutRect(FrameworkElement element)
        {
            double num  = element.ActualWidth;
            double num2 = element.ActualHeight;

            if (element is Image || element is MediaElement)
            {
                if (element.Parent.GetType() == typeof(Canvas))
                {
                    num  = (double.IsNaN(element.Width) ? num : element.Width);
                    num2 = (double.IsNaN(element.Height) ? num2 : element.Height);
                }
                else
                {
                    num  = element.RenderSize.Width;
                    num2 = element.RenderSize.Height;
                }
            }
            num  = ((element.Visibility == Visibility.Collapsed) ? 0.0 : num);
            num2 = ((element.Visibility == Visibility.Collapsed) ? 0.0 : num2);
            Thickness margin     = element.Margin;
            Rect      layoutSlot = LayoutInformation.GetLayoutSlot(element);
            double    x          = 0.0;
            double    y          = 0.0;

            switch (element.HorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                x = layoutSlot.Left + margin.Left;
                break;

            case HorizontalAlignment.Center:
                x = (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - num / 2.0;
                break;

            case HorizontalAlignment.Right:
                x = layoutSlot.Right - margin.Right - num;
                break;

            case HorizontalAlignment.Stretch:
                x = Math.Max(layoutSlot.Left + margin.Left, (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - num / 2.0);
                break;
            }
            switch (element.VerticalAlignment)
            {
            case VerticalAlignment.Top:
                y = layoutSlot.Top + margin.Top;
                break;

            case VerticalAlignment.Center:
                y = (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - num2 / 2.0;
                break;

            case VerticalAlignment.Bottom:
                y = layoutSlot.Bottom - margin.Bottom - num2;
                break;

            case VerticalAlignment.Stretch:
                y = Math.Max(layoutSlot.Top + margin.Top, (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - num2 / 2.0);
                break;
            }
            return(new Rect(x, y, num, num2));
        }
        /// <summary>
        /// Gets a layout from a template.
        /// </summary>
        /// <param name="projectTemplate">The template to get the layout from.</param>
        /// <param name="layoutName">The name of the layout to get.</param>
        /// <returns>The layout, <c>null</c> if not found.</returns>
        private static LayoutInformation GetLayout(ITeamProjectTemplate projectTemplate, string layoutName)
        {
            LayoutInformation layout = projectTemplate.Layouts.Where(li => li.Name == layoutName).SingleOrDefault();

            return(layout);
        }
Esempio n. 24
0
        void CalculateNaiveLayout(LayoutInformation layout, StackOrientation orientation, double x, double y, double widthConstraint, double heightConstraint)
        {
            layout.CompressionSpace = 0;

            double xOffset       = x;
            double yOffset       = y;
            double boundsWidth   = 0;
            double boundsHeight  = 0;
            double minimumWidth  = 0;
            double minimumHeight = 0;
            double spacing       = Spacing;

            if (orientation == StackOrientation.Vertical)
            {
                View expander = null;
                for (var i = 0; i < LogicalChildrenInternal.Count; i++)
                {
                    var child = (View)LogicalChildrenInternal[i];
                    if (!child.IsVisible)
                    {
                        continue;
                    }

                    if (child.VerticalOptions.Expands)
                    {
                        layout.Expanders++;
                        if (expander != null)
                        {
                            // we have multiple expanders, make sure previous expanders are reset to not be fixed because they no logner are
                            ComputeConstraintForView(child, false);
                        }
                        expander = child;
                    }
                    SizeRequest request = child.Measure(widthConstraint, double.PositiveInfinity, MeasureFlags.IncludeMargins);

                    var bounds = new Rectangle(x, yOffset, request.Request.Width, request.Request.Height);
                    layout.Plots[i]          = bounds;
                    layout.Requests[i]       = request;
                    layout.CompressionSpace += Math.Max(0, request.Request.Height - request.Minimum.Height);
                    yOffset = bounds.Bottom + spacing;

                    boundsWidth    = Math.Max(boundsWidth, request.Request.Width);
                    boundsHeight   = bounds.Bottom - y;
                    minimumHeight += request.Minimum.Height + spacing;
                    minimumWidth   = Math.Max(minimumWidth, request.Minimum.Width);
                }
                minimumHeight -= spacing;
                if (expander != null)
                {
                    ComputeConstraintForView(expander, layout.Expanders == 1);                     // warning : slightly obtuse, but we either need to setup the expander or clear the last one
                }
            }
            else
            {
                View expander = null;
                for (var i = 0; i < LogicalChildrenInternal.Count; i++)
                {
                    var child = (View)LogicalChildrenInternal[i];
                    if (!child.IsVisible)
                    {
                        continue;
                    }

                    if (child.HorizontalOptions.Expands)
                    {
                        layout.Expanders++;
                        if (expander != null)
                        {
                            ComputeConstraintForView(child, false);
                        }
                        expander = child;
                    }
                    SizeRequest request = child.Measure(double.PositiveInfinity, heightConstraint, MeasureFlags.IncludeMargins);

                    var bounds = new Rectangle(xOffset, y, request.Request.Width, request.Request.Height);
                    layout.Plots[i]          = bounds;
                    layout.Requests[i]       = request;
                    layout.CompressionSpace += Math.Max(0, request.Request.Width - request.Minimum.Width);
                    xOffset = bounds.Right + spacing;

                    boundsWidth   = bounds.Right - x;
                    boundsHeight  = Math.Max(boundsHeight, request.Request.Height);
                    minimumWidth += request.Minimum.Width + spacing;
                    minimumHeight = Math.Max(minimumHeight, request.Minimum.Height);
                }
                minimumWidth -= spacing;
                if (expander != null)
                {
                    ComputeConstraintForView(expander, layout.Expanders == 1);
                }
            }

            layout.Bounds      = new Rectangle(x, y, boundsWidth, boundsHeight);
            layout.MinimumSize = new Size(minimumWidth, minimumHeight);
        }
Esempio n. 25
0
        private static Rect GetActualBoundsCore(FrameworkElement element, bool inParent)
        {
            if (element == null)
            {
                return(new Rect());
            }
            Rect layoutSlot = LayoutInformation.GetLayoutSlot(element);
            HorizontalAlignment horizontalAlignment = element.HorizontalAlignment;
            VerticalAlignment   verticalAlignment   = element.VerticalAlignment;
            Thickness           margin = element.Margin;
            Point  point1    = new Point();
            Point  point2    = new Point();
            double width1    = element.RenderSize.Width;
            double height1   = element.RenderSize.Height;
            double width2    = element.Width;
            double height2   = element.Height;
            double minWidth  = element.MinWidth;
            double minHeight = element.MinHeight;
            double num1      = !double.IsNaN(width2) ? Math.Max(width2, minWidth) : (horizontalAlignment == HorizontalAlignment.Stretch ? Math.Max(minWidth, layoutSlot.Width - margin.Left - margin.Right) : width1);
            double num2      = !double.IsNaN(height2) ? Math.Max(height2, minHeight) : (verticalAlignment == VerticalAlignment.Stretch ? Math.Max(minHeight, layoutSlot.Height - margin.Top - margin.Bottom) : height1);
            double num3      = Math.Min(width1, num1);
            double num4      = Math.Min(height1, num2);

            switch (horizontalAlignment)
            {
            case HorizontalAlignment.Left:
                point1.X = layoutSlot.Left + margin.Left;
                point2.X = layoutSlot.Left + margin.Left;
                break;

            case HorizontalAlignment.Center:
                point1.X = (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - num1 / 2.0;
                point2.X = (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - num1 / 2.0;
                break;

            case HorizontalAlignment.Right:
                point1.X = layoutSlot.Right - margin.Right - num3;
                point2.X = layoutSlot.Right - margin.Right - num1;
                break;

            case HorizontalAlignment.Stretch:
                point1.X = Math.Max(layoutSlot.Left + margin.Left, (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - num3 / 2.0);
                point2.X = Math.Max(layoutSlot.Left + margin.Left, (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - num1 / 2.0);
                break;
            }
            switch (verticalAlignment)
            {
            case VerticalAlignment.Top:
                point1.Y = layoutSlot.Top + margin.Top;
                point2.Y = layoutSlot.Top + margin.Top;
                break;

            case VerticalAlignment.Center:
                point1.Y = (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - num2 / 2.0;
                point2.Y = (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - num2 / 2.0;
                break;

            case VerticalAlignment.Bottom:
                point1.Y = layoutSlot.Bottom - margin.Bottom - num4;
                point2.Y = layoutSlot.Bottom - margin.Bottom - num2;
                break;

            case VerticalAlignment.Stretch:
                point1.Y = Math.Max(layoutSlot.Top + margin.Top, (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - num4 / 2.0);
                point2.Y = Math.Max(layoutSlot.Top + margin.Top, (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - num2 / 2.0);
                break;
            }
            if (inParent)
            {
                return(new Rect(point2.X, point2.Y, num1, num2));
            }
            return(new Rect(point2.X - point1.X, point2.Y - point1.Y, num1, num2));
        }
Esempio n. 26
0
        protected override void OnLayoutCore(bool changed, int left, int top, int right, int bottom)
        {
            try
            {
                base.OnLayoutCore(changed, left, top, right, bottom);

                Rect finalRect;
                if (TransientArrangeFinalRect is Rect tafr)
                {
                    // If the parent element is from managed code,
                    // we can recover the "Arrange" with double accuracy.
                    // We use that because the conversion to android's "int" is loosing too much precision.
                    finalRect = tafr;
                }
                else
                {
                    // Here the "arrange" is coming from a native element,
                    // so we convert those measurements to logical ones.
                    finalRect = new Rect(left, top, right - left, bottom - top).PhysicalToLogicalPixels();

                    // We also need to set the LayoutSlot as it was not set by the parent.
                    // Note: This is only an approximation of the LayoutSlot as margin and alignment might already been applied at this point.
                    LayoutInformation.SetLayoutSlot(this, finalRect);
                    LayoutSlotWithMarginsAndAlignments = finalRect;
                }

                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().DebugFormat(
                        "[{0}/{1}] OnLayoutCore({2}, {3}, {4}, {5}) (parent: {5},{6})",
                        GetType(),
                        Name,
                        left, top, right, bottom,
                        MeasuredWidth,
                        MeasuredHeight
                        );
                }

                var previousSize = AssignedActualSize;
                AssignedActualSize = finalRect.Size;

                if (
                    // If the layout has changed, but the final size has not, this is just a translation.
                    // So unless there was a layout requested, we can skip arranging the children.
                    (changed && _lastLayoutSize != finalRect.Size)

                    // Even if nothing changed, but a layout was requested, arrange the children.
                    || IsLayoutRequested
                    )
                {
                    _lastLayoutSize = finalRect.Size;

                    OnBeforeArrange();

                    _layouter.Arrange(finalRect);

                    OnAfterArrange();
                }

                if (previousSize != finalRect.Size)
                {
                    SizeChanged?.Invoke(this, new SizeChangedEventArgs(this, previousSize, finalRect.Size));
                    _renderTransform?.UpdateSize(finalRect.Size);
                }
            }
            catch (Exception e)
            {
                Application.Current.RaiseRecoverableUnhandledExceptionOrLog(e, this);
            }
        }
Esempio n. 27
0
            private void UpdateForegroundBrush(object sender, EventArgs e)
            {
                Geometry layoutClip = LayoutInformation.GetLayoutClip((FrameworkElement)this._textBlock);
                Rect     bounds;
                int      num;

                if (layoutClip != null)
                {
                    if (this._textBlock.TextWrapping == TextWrapping.NoWrap)
                    {
                        bounds = layoutClip.Bounds;
                        if (bounds.Width > 0.0)
                        {
                            bounds = layoutClip.Bounds;
                            if (bounds.Width < this._textBlock.ActualWidth)
                            {
                                num = 1;
                                goto label_10;
                            }
                        }
                    }
                    if (this._verticalFadingEnabled && this._textBlock.TextWrapping == TextWrapping.Wrap)
                    {
                        bounds = layoutClip.Bounds;
                        if (bounds.Height > 0.0)
                        {
                            bounds = layoutClip.Bounds;
                            num    = bounds.Height < this._textBlock.ActualHeight ? 1 : 0;
                            goto label_10;
                        }
                    }
                    num = 0;
                }
                else
                {
                    num = 0;
                }
label_10:
                bool flag1 = num != 0;

                if (this._isClipped && !flag1)
                {
                    this._textBlock.OpacityMask = this._opacityMask;
                    this._brush     = (LinearGradientBrush)null;
                    this._isClipped = false;
                }
                if (!flag1)
                {
                    return;
                }
                bounds = layoutClip.Bounds;
                double width = bounds.Width;

                bounds = layoutClip.Bounds;
                double height = bounds.Height;
                bool   flag2  = this._textBlock.TextWrapping == TextWrapping.Wrap;

                if (this._brush == null)
                {
                    this._brush = flag2 ? this.GetVerticalClipBrush(height) : this.GetHorizontalClipBrush(width);
                    this._textBlock.OpacityMask = (Brush)this._brush;
                }
                else if (flag2 && FadeTrimming.VerticalBrushNeedsUpdating(this._brush, height))
                {
                    this._brush.EndPoint = new Point(0.0, height);
                    this._brush.GradientStops[1].Offset = (height - 20.0) / height;
                }
                else if (!flag2 && FadeTrimming.HorizontalBrushNeedsUpdating(this._brush, width))
                {
                    this._brush.EndPoint = new Point(width, 0.0);
                    this._brush.GradientStops[1].Offset = (width - 10.0) / width;
                }
                this._isClipped = true;
            }
        /// <summary>
        ///     获取布局范围框
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static Rect GetLayoutRect(FrameworkElement element)
        {
            double num1 = element.ActualWidth;
            double num2 = element.ActualHeight;

            if (element is Image || element is MediaElement)
            {
                if (element.Parent is Canvas)
                {
                    num1 = double.IsNaN(element.Width) ? num1 : element.Width;
                    num2 = double.IsNaN(element.Height) ? num2 : element.Height;
                }
                else
                {
                    num1 = element.RenderSize.Width;
                    num2 = element.RenderSize.Height;
                }
            }

            double    width      = element.Visibility == Visibility.Collapsed ? 0.0 : num1;
            double    height     = element.Visibility == Visibility.Collapsed ? 0.0 : num2;
            Thickness margin     = element.Margin;
            Rect      layoutSlot = LayoutInformation.GetLayoutSlot(element);
            double    x          = 0.0;
            double    y          = 0.0;

            switch (element.HorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                x = layoutSlot.Left + margin.Left;
                break;

            case HorizontalAlignment.Center:
                x = (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - width / 2.0;
                break;

            case HorizontalAlignment.Right:
                x = layoutSlot.Right - margin.Right - width;
                break;

            case HorizontalAlignment.Stretch:
                x = Math.Max(layoutSlot.Left + margin.Left,
                             (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - width / 2.0);
                break;
            }
            switch (element.VerticalAlignment)
            {
            case VerticalAlignment.Top:
                y = layoutSlot.Top + margin.Top;
                break;

            case VerticalAlignment.Center:
                y = (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - height / 2.0;
                break;

            case VerticalAlignment.Bottom:
                y = layoutSlot.Bottom - margin.Bottom - height;
                break;

            case VerticalAlignment.Stretch:
                y = Math.Max(layoutSlot.Top + margin.Top,
                             (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - height / 2.0);
                break;
            }
            return(new Rect(x, y, width, height));
        }
Esempio n. 29
0
        private void DoMeasure(Size availableSize)
        {
            var isFirstMeasure = !IsLayoutFlagSet(LayoutFlag.FirstMeasureDone);

            var isDirty =
                isFirstMeasure ||
                (availableSize != LastAvailableSize) ||
                IsMeasureDirty ||
                !FeatureConfiguration.UIElement.UseInvalidateMeasurePath ||                 // dirty_path disabled globally
                IsMeasureDirtyPathDisabled;

            var isMeasureDirtyPath = IsMeasureDirtyPath;

            if (!isDirty && !isMeasureDirtyPath)
            {
                return;                 // Nothing to do
            }

            if (isFirstMeasure)
            {
                SetLayoutFlags(LayoutFlag.FirstMeasureDone);
            }

            var remainingTries = MaxLayoutIterations;

            while (--remainingTries > 0)
            {
                if (isDirty)
                {
                    // We must reset the flag **BEFORE** doing the actual measure, so the elements are able to re-invalidate themselves
                    ClearLayoutFlags(LayoutFlag.MeasureDirty | LayoutFlag.MeasureDirtyPath);

                    // The dirty flag is explicitly set on this element
#if DEBUG
                    try
#endif
                    {
                        MeasureCore(availableSize);
                        InvalidateArrange();
                    }
#if DEBUG
                    catch (Exception ex)
                    {
                        _log.Error($"Error measuring {this}", ex);
                        throw;
                    }
                    finally
#endif
                    {
                        LayoutInformation.SetAvailableSize(this, availableSize);
                    }

                    break;
                }

                // isMeasureDirtyPath is always true here
                ClearLayoutFlags(LayoutFlag.MeasureDirtyPath);

                // The dirty flag is set on one of the descendents:
                // it will bypass the current element's MeasureOverride()
                // since it shouldn't produce a different result and it's
                // just a waste of precious CPU time to call it.
                var children = GetChildren().GetEnumerator();

                //foreach (var child in children)
                while (children.MoveNext())
                {
                    if (children.Current is { IsMeasureOrMeasureDirtyPath : true } child)
                    {
                        // If the child is dirty (or is a path to a dirty descendant child),
                        // We're remeasuring it.

                        var previousDesiredSize = child.DesiredSize;
                        child.Measure(child.LastAvailableSize);
                        if (child.DesiredSize != previousDesiredSize)
                        {
                            isDirty = true;
                            break;
                        }
                    }
                }

                children.Dispose();                 // no "using" operator here to prevent an implicit try-catch on Wasm

                if (isDirty)
                {
                    continue;
                }

                break;
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Adds a layout; used to add default layouts. IWindowLayoutClients are queried for their
        /// current states.</summary>
        /// <param name="newLayoutName">New layout name</param>
        /// <param name="dockState">Dock state</param>
        public void AddLayout(string newLayoutName, object dockState)
        {
            // Save information about the dock state
            LayoutInformation info = new LayoutInformation { DockState = dockState };

            // Save information about each window layout client
            foreach (var client in m_clients.GetValues())
                info.LayoutData.Add(new Pair<IWindowLayoutClient, object>(client, client.LayoutData));

            m_layouts[newLayoutName] = info;
        }
Esempio n. 31
0
 /// <summary>
 /// Raises an event for the user selecting a layout.
 /// </summary>
 /// <param name="layout">The selected layout.</param>
 private void UserSelectsLayout(LayoutInformation layout)
 {
     this.mockView.Raise(view => view.LayoutSelected += null, new LayoutItemEventArgs(layout));
 }