コード例 #1
0
ファイル: ListItem.cs プロジェクト: gaozhou/Delight
        /// <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);
        }
コード例 #2
0
        /// <summary>
        /// Scales view content.
        /// </summary>
        public void SetScale(Vector3 scale)
        {
            if (_displayedView == null)
            {
                ContentRegionCanvas.Scale = Vector3.one;
                return;
            }

            ContentRegionCanvas.Scale = scale;

            // adjust size of view region based on size of view and viewport
            var viewportWidth  = ScrollableContentRegion.ActualWidth;
            var viewportHeight = ScrollableContentRegion.ActualHeight;

            var width  = _displayedView.OverrideWidth ?? _displayedView.Width ?? ElementSize.FromPercents(1);
            var height = _displayedView.OverrideHeight ?? _displayedView.Height ?? ElementSize.FromPercents(1);

            float adjustedWidth  = viewportWidth * Mathf.Max(scale.x, 1.0f);
            float adjustedHeight = viewportHeight * Mathf.Max(scale.y, 1.0f);

            if (width.Unit != ElementSizeUnit.Percents)
            {
                float viewWidth = width.Pixels * Mathf.Max(scale.x, 1.0f);
                adjustedWidth = Mathf.Max(viewWidth, adjustedWidth);
            }

            if (height.Unit != ElementSizeUnit.Percents)
            {
                float viewHeight = height.Pixels * Mathf.Max(scale.y, 1.0f);
                adjustedHeight = Mathf.Max(viewHeight, adjustedHeight);
            }

            // adjust content regions to size
            ContentRegionCanvas.SetSize(adjustedWidth * 2, adjustedHeight * 2);
            ViewContentRegion.SetSize(adjustedWidth, adjustedHeight);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public VirtualItem(ElementSize width, ElementSize height)
 {
     Width  = width != null ? new ElementSize(width) : ElementSize.FromPercents(1);
     Height = height != null ? new ElementSize(height) : ElementSize.FromPercents(1);
     Offset = new ElementMargin();
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public VirtualItem()
 {
     Width  = ElementSize.FromPercents(1);
     Height = ElementSize.FromPercents(1);
     Offset = new ElementMargin();
 }
コード例 #5
0
ファイル: ListItem.cs プロジェクト: gaozhou/Delight
        /// <summary>
        /// Adjusts the size of the list item to its content.
        /// </summary>
        public new bool AdjustSizeToContent()
        {
            bool hasNewSize = false;

            // the default behavior of the list-item is to adjust its height and width to its content
            bool  percentageWidth  = true;
            bool  percentageHeight = true;
            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;
                    percentageWidth = false;
                }

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

            // 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 = percentageWidth ? ElementSize.FromPercents(1) : new ElementSize(maxWidth);

            if (!newWidth.Equals(Width))
            {
                Width      = newWidth;
                hasNewSize = true;
            }
            var newHeight = percentageHeight ? ElementSize.FromPercents(1) : new ElementSize(maxHeight);

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

            return(hasNewSize);
        }