Example #1
0
        /// <summary>Met à jour la propriété <see cref="P:System.Windows.UIElement.DesiredSize" /> de la classe <see cref="T:System.Windows.UIElement" />.Les éléments parents appellent cette méthode depuis leur propre implémentation <see cref="M:System.Windows.UIElement.MeasureCore(System.Windows.Size)" /> pour former une actualisation récursive de la disposition.L'appel à cette méthode constitue la première passe (la passe de "Measure") d'une actualisation de disposition.</summary>
        /// <param name="availableSize">Espace disponible qu'un élément parent peut allouer à un élément enfant.Un élément enfant peut demander un espace plus grand que ce qui est disponible ; les dimensions fournies peuvent être adaptées si le défilement est possible dans le modèle de contenu pour l'élément actif.</param>
        public virtual void Measure(SKSize availableSize)
        {
            bool sameConstraint = FloatUtil.AreClose(availableSize, this.previousAvailableSize);

            if (this.Visibility == false)
            {
                if (!sameConstraint)
                {
                    this.MeasureDirty          = true;
                    this.previousAvailableSize = availableSize;
                }
            }
            else if (!((this.IsMeasureValid && !NeverMeasured) & sameConstraint))
            {
                this.NeverMeasured = false;
                this.InvalidateArrange();
                this.MeasureInProgress = true;
                SKSize size = new SKSize(0.0f, 0.0f);
                try
                {
                    size = this.MeasureOverride(availableSize);
                }
                finally
                {
                    this.MeasureInProgress     = false;
                    this.previousAvailableSize = availableSize;
                }
                this.MeasureDirty = false;
                this.desiredSize  = size;
            }
        }
 public float Measure(int level, IEnumerable <HierarchicalNode> elements, float offsetx, SKSize availableSize, List <HierarchicalNode> allreadyPassed)
 {
     foreach (var element in elements)
     {
         if (allreadyPassed.Contains(element) == false)
         {
             allreadyPassed.Add(element);
             element.Measure(availableSize);
             bool withChild = element.ChildrenNode.Count > 0;
             if (withChild)
             {
                 float startOffset = offsetx;
                 float endOffset   = Measure(level + 1, element.ChildrenNode, startOffset, availableSize, allreadyPassed);
                 if (FloatUtil.AreClose(endOffset, startOffset))
                 {
                     withChild = false;
                 }
                 else
                 {
                     offsetx = endOffset;
                     element.Bag.ChildrenWidth = endOffset - startOffset;
                 }
             }
             else
             {
                 float elementWidth = element.DesiredSize.Width;
                 offsetx += elementWidth + HorizontalSpacing;
             }
         }
     }
     return(offsetx);
 }
Example #3
0
        public override void Measure(SKSize availableSize)
        {
            SKSize desiredSize    = this.DesiredSize;
            bool   sameConstraint = FloatUtil.AreClose(availableSize, this.previousConstraint);

            base.Measure(availableSize);
            if (this.Parent != null &&
                this.Visibility &&
                (!((this.IsMeasureValid && !NeverMeasured) & sameConstraint)) &&
                !this.MeasureDuringArrange &&
                !FloatUtil.AreClose(DesiredSize, desiredSize))
            {
                this.Parent.OnChildDesiredSizeChanged(this);
            }
        }
        public float Arrange(int level, IEnumerable <HierarchicalNode> elements, float offsety, float offsetx, float widthRatio, float heightRatio, List <HierarchicalNode> allreadyPassed)
        {
            float levelHeight = heightByLevel[level] * heightRatio;

            foreach (var element in elements)
            {
                if (allreadyPassed.Contains(element) == false)
                {
                    allreadyPassed.Add(element);
                    float elementWidth   = (element.DesiredSize.Width * widthRatio);
                    float elementHeight  = element.DesiredSize.Height * heightRatio;
                    float elementOffsetY = offsety + ((levelHeight - elementHeight) / 2.0f);
                    bool  withChild      = element.ChildrenNode.Count > 0;
                    if (withChild)
                    {
                        float childrenWith = element.Bag.ChildrenWidth * widthRatio;
                        float startOffset  = offsetx;
                        if (childrenWith < elementWidth)
                        {
                            startOffset += (elementWidth - childrenWith) / 2.0f;
                        }
                        float endOffset = Arrange(level + 1, element.ChildrenNode, offsety + levelHeight + VerticalSpacing, startOffset, widthRatio, heightRatio, allreadyPassed);
                        if (FloatUtil.AreClose(endOffset, startOffset))
                        {
                            withChild = false;
                        }
                        else
                        {
                            float  elementOffsetX = startOffset + ((endOffset - startOffset - HorizontalSpacing) / 2.0f) - (elementWidth / 2.0f);
                            SKRect elementBounds  = new SKRect(elementOffsetX, elementOffsetY, elementOffsetX + elementWidth, elementOffsetY + elementHeight);
                            element.Arrange(elementBounds);
                            offsetx = endOffset;
                        }
                    }
                    else
                    {
                        SKRect elementBounds = new SKRect(offsetx, elementOffsetY, offsetx + elementWidth, elementOffsetY + elementHeight);
                        element.Arrange(elementBounds);
                        offsetx += elementWidth + HorizontalSpacing;
                    }
                }
            }
            return(offsetx);
        }
Example #5
0
        /// <summary>
        /// Compares two colors for fuzzy equality.  This function
        /// helps compensate for the fact that float values can
        /// acquire error when operated upon
        /// </summary>
        /// <param name='color'>The color to compare to this</param>
        /// <returns>Whether or not the two colors are equal</returns>
        private bool IsClose(Color color)
        {
            // Alpha is the least likely channel to differ
            bool result = true;

            if (context == null || color.nativeColorValue == null)
            {
                result = result && FloatUtil.AreClose(scRgbColor.r, color.scRgbColor.r);
                result = result && FloatUtil.AreClose(scRgbColor.g, color.scRgbColor.g);
                result = result && FloatUtil.AreClose(scRgbColor.b, color.scRgbColor.b);
            }
            else
            {
                for (int i = 0; i < color.nativeColorValue.GetLength(0); i++)
                {
                    result = result && FloatUtil.AreClose(nativeColorValue[i], color.nativeColorValue[i]);
                }
            }

            return(result && FloatUtil.AreClose(scRgbColor.a, color.scRgbColor.a));
        }
Example #6
0
        /// <summary>Positionne des éléments enfants et détermine une taille pour <see cref="T:System.Windows.UIElement" />.Les éléments parents appellent cette méthode depuis leur implémentation <see cref="M:System.Windows.UIElement.ArrangeCore(System.Windows.Rect)" /> (ou un équivalent au niveau de l'infrastructure WPF) pour former une actualisation de disposition récursive.Cette méthode constitue la seconde passe d'une actualisation de disposition.</summary>
        /// <param name="finalRect">La taille finale que le parent calcule pour l'élément enfant, fournie sous forme d'instance <see cref="T:System.Windows.Rect" />.</param>
        public void Arrange(SKRect finalRect)
        {
            if (this.Visibility == false)
            {
                this.finalRect = finalRect;
            }
            else
            {
                if (this.MeasureDirty || this.NeverMeasured)
                {
                    try
                    {
                        this.MeasureDuringArrange = true;
                        if (this.NeverMeasured)
                        {
                            this.Measure(finalRect.Size);
                        }
                        else
                        {
                            this.Measure(this.previousAvailableSize);
                        }
                    }
                    finally
                    {
                        this.MeasureDuringArrange = false;
                    }
                }

                if (!this.IsArrangeValid || this.NeverArranged || NeverTransform || TransformationDirty || !FloatUtil.AreClose(finalRect, this.finalRect))
                {
                    this.NeverArranged     = false;
                    this.ArrangeInProgress = true;
                    try
                    {
                        this.ArrangeCore(finalRect);
                    }
                    finally
                    {
                        this.ArrangeInProgress = false;
                    }
                    this.finalRect    = finalRect;
                    this.ArrangeDirty = false;
                }
            }
        }