Exemplo n.º 1
0
        /// <summary>
        /// Updates layout.
        /// </summary>
        public override bool UpdateLayout(bool notifyParent = true)
        {
            bool defaultDisableLayoutUpdate = DisableLayoutUpdate;

            DisableLayoutUpdate = true;

            bool hasNewSize = false;

            if (AutoSizeToContent && !_sizeSet)
            {
                hasNewSize = AdjustSizeToContent();
            }
            else
            {
                ElementSize newWidth  = Width;
                ElementSize newHeight = Height;

                // adjust width and height to ParentList
                if (ParentList == null || ParentList.Orientation == ElementOrientation.Horizontal)
                {
                    newWidth = Width != null && Width.Unit != ElementSizeUnit.Percents
                        ? Width
                        : new ElementSize(Length);

                    if (Height == null)
                    {
                        newHeight = Breadth != null ? new ElementSize(Breadth) : ElementSize.FromPercents(1);
                    }
                }
                else
                {
                    // if neither width nor length is set, use 100% width
                    if (Width == null)
                    {
                        newWidth = Length != null ? new ElementSize(Length) : ElementSize.FromPercents(1);
                    }

                    newHeight = Height != null && Height.Unit != ElementSizeUnit.Percents
                        ? Height
                        : new ElementSize(Breadth);
                }

                // adjust size to content unless it has been set
                if (!newWidth.Equals(Width))
                {
                    Width      = newWidth;
                    hasNewSize = true;
                }

                if (!newHeight.Equals(Height))
                {
                    Height     = newHeight;
                    hasNewSize = true;
                }
            }

            DisableLayoutUpdate = defaultDisableLayoutUpdate;
            return(base.UpdateLayout(notifyParent) || hasNewSize);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adjusts the size of the list item to its content.
        /// </summary>
        private bool AdjustSizeToContent()
        {
            bool hasNewSize = false;

            // the default behavior of the list-item is to adjust its height and width to its content
            float maxWidth   = 0f;
            float maxHeight  = 0f;
            int   childCount = LayoutChildren.Count;

            // get size of content and set content offsets and alignment
            for (int i = 0; i < childCount; ++i)
            {
                var childView = LayoutChildren[i] as UIView;
                if (childView == null)
                {
                    continue;
                }

                var childWidth  = childView.OverrideWidth ?? (childView.Width ?? ElementSize.Default);
                var childHeight = childView.OverrideHeight ?? (childView.Height ?? ElementSize.Default);

                // get size of content
                if (childWidth.Unit != ElementSizeUnit.Percents)
                {
                    maxWidth = childWidth.Pixels > maxWidth ? childWidth.Pixels : maxWidth;
                }

                if (childHeight.Unit != ElementSizeUnit.Percents)
                {
                    maxHeight = childHeight.Pixels > maxHeight ? childHeight.Pixels : maxHeight;
                }
            }

            // add margins
            var margin = Margin ?? ElementMargin.Default;

            maxWidth  += margin.Left.Pixels + margin.Right.Pixels;
            maxHeight += margin.Top.Pixels + margin.Bottom.Pixels;

            // adjust size to content unless it has been set
            var newWidth = new ElementSize(maxWidth);

            if (!newWidth.Equals(Width))
            {
                Width      = newWidth;
                hasNewSize = true;
            }
            var newHeight = new ElementSize(maxHeight);

            if (!newHeight.Equals(Height))
            {
                Height     = newHeight;
                hasNewSize = true;
            }

            return(hasNewSize);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates layout.
        /// </summary>
        public override bool UpdateLayout(bool notifyParent = true)
        {
            bool hasNewSize = false;
            var  newWidth   = new ElementSize(HeaderGroup.ActualWidth, ElementSizeUnit.Pixels);

            if (!newWidth.Equals(Width))
            {
                WidthProperty.SetValue(this, newWidth, false);
                hasNewSize = true;
            }

            return(base.UpdateLayout(notifyParent) || hasNewSize);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates based on expanded content size.
        /// </summary>
        public override bool UpdateLayout(bool notifyParent = true)
        {
            bool defaultDisableLayoutUpdate = DisableLayoutUpdate;

            DisableLayoutUpdate = true;

            // adjust width to content unless it has been explicitly set
            bool hasNewSize = false;

            if (Width == null)
            {
                float       headerWidth  = GetPixelWidth(_expanderHeader);
                float       contentWidth = GetPixelWidth(_expanderContent);
                float       totalWidth   = Mathf.Max(headerWidth, contentWidth);
                ElementSize newWidth     = totalWidth > 0 ? new ElementSize(totalWidth) : ElementSize.DefaultLayout;

                if (!newWidth.Equals(OverrideWidth))
                {
                    OverrideWidth = newWidth;
                    hasNewSize    = true;
                }
            }

            // adjust height to content unless it has been explicitly set
            if (Height == null)
            {
                float       headerHeight  = GetPixelHeight(_expanderHeader);
                float       contentHeight = GetPixelHeight(_expanderContent);
                float       totalHeight   = headerHeight + contentHeight;
                ElementSize newHeight     = totalHeight > 0 ? new ElementSize(totalHeight) : 40;

                if (!newHeight.Equals(OverrideHeight))
                {
                    OverrideHeight = newHeight;
                    hasNewSize     = true;
                }
            }

            DisableLayoutUpdate = defaultDisableLayoutUpdate;
            return(base.UpdateLayout(notifyParent) || hasNewSize);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adjusts the size of the view to its content.
        /// </summary>
        public bool AdjustSizeToContent()
        {
            bool hasNewSize = false;

            float maxWidth   = -1f;
            float maxHeight  = -1f;
            int   childCount = LayoutChildren.Count;

            // get size of content and set content offsets and alignment
            for (int i = 0; i < childCount; ++i)
            {
                var childView = LayoutChildren[i] as UIView;
                if (childView == null || !childView.IsActive)
                {
                    continue;
                }

                var childWidth  = childView.OverrideWidth ?? (childView.Width ?? ElementSize.DefaultLayout);
                var childHeight = childView.OverrideHeight ?? (childView.Height ?? ElementSize.DefaultLayout);

                // get size of content
                if (childWidth.Unit != ElementSizeUnit.Percents)
                {
                    maxWidth = childWidth.Pixels > maxWidth ? childWidth.Pixels : maxWidth;
                }

                if (childHeight.Unit != ElementSizeUnit.Percents)
                {
                    maxHeight = childHeight.Pixels > maxHeight ? childHeight.Pixels : maxHeight;
                }
            }

            // add margins
            var margin = Margin ?? ElementMargin.Default;

            if (maxWidth >= 0)
            {
                maxWidth += margin.Left.Pixels + margin.Right.Pixels;

                // adjust size to content unless it has been set
                var newWidth = new ElementSize(maxWidth);
                if (!newWidth.Equals(Width))
                {
                    Width      = newWidth;
                    hasNewSize = true;
                }
            }

            if (maxHeight >= 0)
            {
                maxHeight += margin.Top.Pixels + margin.Bottom.Pixels;
                var newHeight = new ElementSize(maxHeight);
                if (!newHeight.Equals(Height))
                {
                    Height     = newHeight;
                    hasNewSize = true;
                }
            }

            return(hasNewSize);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the layout of the group.
        /// </summary>
        public override bool UpdateLayout(bool notifyParent = true)
        {
            bool defaultDisableLayoutUpdate = DisableLayoutUpdate;

            DisableLayoutUpdate = true;

            bool          hasNewSize       = false;
            float         maxWidth         = 0f;
            float         maxHeight        = 0f;
            float         totalWidth       = 0f;
            float         totalHeight      = 0f;
            bool          percentageWidth  = false;
            bool          percentageHeight = false;
            bool          isHorizontal     = Orientation == ElementOrientation.Horizontal;
            List <UIView> children         = new List <UIView>();

            this.ForEach <UIView>(x =>
            {
                children.Add(x);
            }, false);

            // get size of content and set content offsets and alignment
            var spacing    = Spacing ?? ElementSize.Default;
            int childCount = children.Count;
            int childIndex = 0;

            for (int i = 0; i < childCount; ++i)
            {
                var childView = children[i];
                if (!childView.IsActive)
                {
                    // don't group inactive views
                    continue;
                }

                var childWidth  = childView.OverrideWidth ?? (childView.Width ?? ElementSize.Default);
                var childHeight = childView.OverrideHeight ?? (childView.Height ?? ElementSize.Default);

                if (childWidth.Unit == ElementSizeUnit.Percents)
                {
                    if (isHorizontal)
                    {
                        Debug.LogWarning(String.Format("#Delight# Unable to group view \"{0}\" horizontally as it doesn't specify its width in pixels.", childView.Name));
                        continue;
                    }
                    else
                    {
                        percentageWidth = true;
                    }
                }

                if (childHeight.Unit == ElementSizeUnit.Percents)
                {
                    if (!isHorizontal)
                    {
                        Debug.LogWarning(String.Format("#Delight# Unable to group view \"{0}\" vertically as it doesn't specify its height in pixels or elements.", childView.Name));
                        continue;
                    }
                    else
                    {
                        percentageHeight = true;
                    }
                }

                bool defaultDisableChildLayoutUpdate = childView.DisableLayoutUpdate;
                childView.DisableLayoutUpdate = true;

                // set offsets and alignment
                var offset = new ElementMargin(
                    new ElementSize(isHorizontal ? totalWidth + spacing.Pixels * childIndex : 0f, ElementSizeUnit.Pixels),
                    new ElementSize(!isHorizontal ? totalHeight + spacing.Pixels * childIndex : 0f, ElementSizeUnit.Pixels));

                // set desired alignment if it is valid for the orientation otherwise use defaults
                var alignment        = ElementAlignment.Center;
                var defaultAlignment = isHorizontal ? ElementAlignment.Left : ElementAlignment.Top;
                var desiredAlignment = !ContentAlignmentProperty.IsUndefined(this) ? ContentAlignment : childView.Alignment;
                if (isHorizontal && (desiredAlignment == ElementAlignment.Top || desiredAlignment == ElementAlignment.Bottom ||
                                     desiredAlignment == ElementAlignment.TopLeft || desiredAlignment == ElementAlignment.BottomLeft))
                {
                    alignment = defaultAlignment | desiredAlignment;
                }
                else if (!isHorizontal && (desiredAlignment == ElementAlignment.Left || desiredAlignment == ElementAlignment.Right ||
                                           desiredAlignment == ElementAlignment.TopLeft || desiredAlignment == ElementAlignment.TopRight))
                {
                    alignment = defaultAlignment | desiredAlignment;
                }
                else
                {
                    alignment = defaultAlignment;
                }

                // get size of content
                if (!percentageWidth)
                {
                    totalWidth += childWidth;
                    maxWidth    = childWidth.Pixels > maxWidth ? childWidth.Pixels : maxWidth;
                }

                if (!percentageHeight)
                {
                    totalHeight += childHeight;
                    maxHeight    = childHeight.Pixels > maxHeight ? childHeight.Pixels : maxHeight;
                }

                // update child layout
                if (!offset.Equals(childView.OffsetFromParent) || alignment != childView.Alignment)
                {
                    childView.OffsetFromParent = offset;
                    childView.Alignment        = alignment;

                    childView.UpdateLayout(false);
                }
                ++childIndex;
                childView.DisableLayoutUpdate = defaultDisableChildLayoutUpdate;
            }

            // set width and height
            float totalSpacing = childCount > 1 ? (childIndex - 1) * spacing.Pixels : 0f;

            // adjust width to content
            if (WidthProperty.IsUndefined(this))
            {
                if (!percentageWidth)
                {
                    // add margins
                    var margin = Margin ?? ElementMargin.Default;
                    totalWidth += isHorizontal ? totalSpacing : 0f;
                    totalWidth += margin.Left.Pixels + margin.Right.Pixels;
                    maxWidth   += margin.Left.Pixels + margin.Right.Pixels;

                    // adjust width to content
                    var newWidth = new ElementSize(isHorizontal ? totalWidth : maxWidth, ElementSizeUnit.Pixels);
                    if (!newWidth.Equals(Width))
                    {
                        OverrideWidth = newWidth;
                        hasNewSize    = true;
                    }
                }
                else
                {
                    var newWidth = new ElementSize(1, ElementSizeUnit.Percents);
                    if (!newWidth.Equals(Width))
                    {
                        OverrideWidth = newWidth;
                        hasNewSize    = true;
                    }
                }
            }
            else if (OverrideWidth != null && !OverrideWidth.Equals(Width))
            {
                // clear override
                OverrideWidth = null;
                hasNewSize    = true;
            }

            // adjust height to content
            if (HeightProperty.IsUndefined(this))
            {
                if (!percentageHeight)
                {
                    // add margins
                    var margin = Margin ?? ElementMargin.Default;
                    totalHeight += !isHorizontal ? totalSpacing : 0f;
                    totalHeight += margin.Top.Pixels + margin.Bottom.Pixels;
                    maxHeight   += margin.Top.Pixels + margin.Bottom.Pixels;

                    // adjust height to content
                    var newHeight = new ElementSize(!isHorizontal ? totalHeight : maxHeight, ElementSizeUnit.Pixels);
                    if (!newHeight.Equals(Height))
                    {
                        OverrideHeight = newHeight;
                        hasNewSize     = true;
                    }
                }
                else
                {
                    var newHeight = new ElementSize(1, ElementSizeUnit.Percents);
                    if (!newHeight.Equals(Height))
                    {
                        OverrideHeight = newHeight;
                        hasNewSize     = true;
                    }
                }
            }
            else if (OverrideHeight != null && !OverrideHeight.Equals(Height))
            {
                // clear override
                OverrideHeight = null;
                hasNewSize     = true;
            }

            DisableLayoutUpdate = defaultDisableLayoutUpdate;

            return(base.UpdateLayout(notifyParent) || hasNewSize);
        }