Beispiel #1
0
        /**
         *  
         *  This method is called by updateDisplayList() after initial values for 
         *  visibleStartIndex, visibleEndIndex have been calculated.  We 
         *  re-calculateDisplayParameters() to account for the possibility that
         *  larger cells may have been exposed.  Since tileWdth,Height can only
         *  increase, the new visibleStart,EndIndex values will be greater than or
         *  equal to the old ones. 
         */
         /*private void updateVirtualLayout(int unscaledWidth, int unscaledHeight)
         {
            int oldVisibleStartIndex = _visibleStartIndex;
            int oldVisibleEndIndex = _visibleEndIndex;
            calculateDisplayParameters(unscaledWidth, unscaledHeight);  // compute new visibleStart,EndIndex values
            
            // We're responsible for laying out *all* of the elements requested
            // with getVirtualElementAt(), even if they don't fall within the final
            // visible range.  Hide any extra ones.  On the next layout pass, they'll
            // be added to DataGroup::freeRenderers
            
            GroupBase layoutTarget = Target;
            for (int i = oldVisibleStartIndex; i <= oldVisibleEndIndex; i++)
            {
                if ((i >= _visibleStartIndex) && (i <= _visibleEndIndex)) // skip past the visible range
                {
                    i = _visibleEndIndex;
                    continue;
                } 
                //ILayoutElement el = layoutTarget.getVirtualElementAt(i);
                //if (null == el)
                //    continue;
                //el.setLayoutBoundsSize(0, 0);
                //if (el is IVisualElement)
                //    IVisualElement(el).visible = false; 
            }
        } */

        /**
         *  Sets the size and the position of the specified layout element and cell bounds.
         *  Param: element - the element to resize and position.
         *  Param: cellX - the x coordinate of the cell.
         *  Param: cellY - the y coordinate of the cell.
         *  Param: cellWidth - the width of the cell.
         *  Param: cellHeight - the height of the cell.
         */
        private void sizeAndPositionElement(ILayoutElement element,
                                                  int cellX,
                                                  int cellY,
                                                  int cellWidth,
                                                  int cellHeight)
        {
            float childWidth;
            float childHeight;

            // Determine size of the element
            if (_horizontalAlign == HorizontalAlign.Justify)
                childWidth = cellWidth;
            else if (null != element.PercentWidth)
                childWidth = Mathf.Round((float) (cellWidth * element.PercentWidth * 0.01f));
            else
                childWidth = LayoutUtil.GetPreferredBoundsWidth((InvalidationManagerClient) element);

            if (_verticalAlign == global::eDriven.Gui.Layout.VerticalAlign.Justify)
                childHeight = cellHeight;
            else if (null != element.PercentHeight)
                childHeight = Mathf.Round((float) (cellHeight * element.PercentHeight * 0.01f));
            else
                childHeight = LayoutUtil.GetPreferredBoundsHeight((InvalidationManagerClient) element);

            // Enforce min and max limits
            float maxChildWidth = Math.Min(LayoutUtil.GetMaxBoundsWidth((InvalidationManagerClient) element), cellWidth);
            float maxChildHeight = Math.Min(LayoutUtil.GetMaxBoundsHeight((InvalidationManagerClient) element), cellHeight);
            // Make sure we enforce element's minimum last, since it has the highest priority
            childWidth = Math.Max(LayoutUtil.GetMinBoundsWidth((InvalidationManagerClient) element), Math.Min(maxChildWidth, childWidth));
            childHeight = Math.Max(LayoutUtil.GetMinBoundsHeight((InvalidationManagerClient) element), Math.Min(maxChildHeight, childHeight));

            // Size the element
            element.SetLayoutBoundsSize(childWidth, childHeight);

            float x = cellX;
            switch (_horizontalAlign)
            {
                case HorizontalAlign.Right:
                    x += cellWidth - LayoutUtil.GetLayoutBoundsWidth((InvalidationManagerClient) element);
                break;
                case HorizontalAlign.Center:
                    // Make sure division result is integer - Math.floor() the result.
                    x = cellX + Mathf.Floor((cellWidth - LayoutUtil.GetLayoutBoundsWidth((InvalidationManagerClient) element)) / 2);
                break;
            }

            float y = cellY;
            switch (_verticalAlign)
            {
                case VerticalAlign.Bottom:
                    y += cellHeight - LayoutUtil.GetLayoutBoundsHeight((InvalidationManagerClient)element);
                break;
                case VerticalAlign.Middle:
                    // Make sure division result is integer - Math.floor() the result.
                y += Mathf.Floor((cellHeight - LayoutUtil.GetLayoutBoundsHeight((InvalidationManagerClient) element)) / 2);
                break;
            }

            // Position the element
            element.SetLayoutBoundsPosition(x, y);
        }
Beispiel #2
0
        ///<summary>
        ///</summary>
        ///<param name="width"></param>
        ///<param name="height"></param>
        override internal void UpdateDisplayList(float width, float height)
        {
            //if (((Component)Target.Owner).Id == "test")
            //    Debug.Log("AbsoluteLayout -> UpdateDisplayList: " + width + ", " + height);

            //base.UpdateDisplayList(width, height);

            GroupBase layoutTarget = Target;

            if (null == layoutTarget)
            {
                return;
            }

            int   count = layoutTarget.NumberOfChildren;
            float maxX  = 0;
            float maxY  = 0;

            for (int i = 0; i < count; i++)
            {
                //Debug.Log("layoutTarget.GetChildAt(i): " + layoutTarget.GetChildAt(i));

                ILayoutElement layoutElement = (ILayoutElement)layoutTarget.GetChildAt(i);

                //if (layoutElement is LoadingMaskBase)
                //    Debug.Log(string.Format("*** A) layoutElement is LoadingMaskBase: layoutElement.IncludeInLayout: {0};", layoutElement.IncludeInLayout));

                if (null == layoutElement || !layoutElement.IncludeInLayout)
                {
                    continue;
                }

                //if (layoutElement is LoadingMaskBase)
                //    Debug.Log(string.Format("*** B) layoutElement is LoadingMaskBase: layoutElement.IncludeInLayout: {0};", layoutElement.IncludeInLayout));

                float?left          = LayoutUtil.ParseConstraintValue(layoutElement.Left);
                float?right         = LayoutUtil.ParseConstraintValue(layoutElement.Right);
                float?top           = LayoutUtil.ParseConstraintValue(layoutElement.Top);
                float?bottom        = LayoutUtil.ParseConstraintValue(layoutElement.Bottom);
                float?hCenter       = LayoutUtil.ParseConstraintValue(layoutElement.HorizontalCenter);
                float?vCenter       = LayoutUtil.ParseConstraintValue(layoutElement.VerticalCenter);
                float?percentWidth  = layoutElement.PercentWidth;
                float?percentHeight = layoutElement.PercentHeight;

                float?elementMaxWidth  = null;
                float?elementMaxHeight = null;

                // Calculate size
                float?childWidth  = null;
                float?childHeight = null;

                if (null != percentWidth)
                {
                    var availableWidth = width;
                    if (null != left)
                    {
                        availableWidth -= (float)left;
                    }
                    if (null != right)
                    {
                        availableWidth -= (float)right;
                    }

                    childWidth      = (float?)Math.Round(availableWidth * Math.Min((float)percentWidth * 0.01f, 1f));
                    elementMaxWidth = Math.Min(LayoutUtil.GetMaxBoundsWidth(layoutElement as InvalidationManagerClient),
                                               MaxSizeToFitIn(width, hCenter, left, right, LayoutUtil.GetLayoutBoundsX(layoutElement as InvalidationManagerClient)));
                }
                else if (null != left && null != right)
                {
                    childWidth = width - right - left;
                }

                if (null != percentHeight)
                {
                    float availableHeight = height;
                    if (null != top)
                    {
                        availableHeight -= (float)top;
                    }
                    if (null != bottom)
                    {
                        availableHeight -= (float)bottom;
                    }

                    childHeight      = (float?)Math.Round(availableHeight * Math.Min((float)percentHeight * 0.01, 1));
                    elementMaxHeight = Math.Min(LayoutUtil.GetMaxBoundsHeight(layoutElement as InvalidationManagerClient),
                                                MaxSizeToFitIn(height, vCenter, top, bottom, LayoutUtil.GetLayoutBoundsY(layoutElement as InvalidationManagerClient)));
                }
                else if (null != top && null != bottom)
                {
                    childHeight = height - bottom - top;
                }

                // Apply min and max constraints, make sure min is applied last. In the cases
                // where childWidth and childHeight are NaN, setLayoutBoundsSize will use preferredSize
                // which is already constrained between min and max.
                if (null != childWidth)
                {
                    if (null == elementMaxWidth)
                    {
                        elementMaxWidth = LayoutUtil.GetMaxBoundsWidth(layoutElement as InvalidationManagerClient);
                    }
                    childWidth = Math.Max(LayoutUtil.GetMinBoundsWidth(layoutElement as InvalidationManagerClient), Math.Min((float)elementMaxWidth, (float)childWidth));
                }
                if (null != childHeight)
                {
                    if (null == elementMaxHeight)
                    {
                        elementMaxHeight = LayoutUtil.GetMaxBoundsHeight(layoutElement as InvalidationManagerClient);
                    }
                    childHeight = Math.Max(LayoutUtil.GetMinBoundsHeight(layoutElement as InvalidationManagerClient), Math.Min((float)elementMaxHeight, (float)childHeight));
                }

                // Set the size.
                LayoutUtil.SetLayoutBoundsSize(layoutElement as InvalidationManagerClient, childWidth, childHeight);
                float elementWidth  = LayoutUtil.GetLayoutBoundsWidth(layoutElement as InvalidationManagerClient);
                float elementHeight = LayoutUtil.GetLayoutBoundsHeight(layoutElement as InvalidationManagerClient);

                float childX;
                float childY;

                // Horizontal position
                if (null != hCenter)
                {
                    childX = (float)Math.Round((width - elementWidth) / 2 + (float)hCenter);
                }
                else if (null != left)
                {
                    childX = (float)left;
                }
                else if (null != right)
                {
                    childX = (float)(width - elementWidth - right);
                }
                else
                {
                    childX = LayoutUtil.GetLayoutBoundsX(layoutElement as InvalidationManagerClient);
                }

                // Vertical position
                if (null != vCenter)
                {
                    childY = (float)Math.Round((height - elementHeight) / 2 + (float)vCenter);
                }
                else if (null != top)
                {
                    childY = (float)top;
                }
                else if (null != bottom)
                {
                    childY = (float)(height - elementHeight - bottom);
                }
                else
                {
                    childY = LayoutUtil.GetLayoutBoundsY(layoutElement as InvalidationManagerClient);
                }

                // Set position
                //LayoutUtil.SetLayoutBoundsPosition(layoutElement as InvalidationManagerClient, childX, childY);
                layoutElement.SetLayoutBoundsPosition(childX, childY);

                // update content limits
                maxX = Math.Max(maxX, childX + elementWidth);
                maxY = Math.Max(maxY, childY + elementHeight);
            }

            // Make sure that if the content spans partially over a pixel to the right/bottom,
            // the content size includes the whole pixel.
            layoutTarget.SetContentSize(Mathf.Ceil(maxX), Mathf.Ceil(maxY));
        }