/** * Returns the specified element's layout bounds as a Rectangle or null * if the index is invalid, the corresponding element is null, * <code>includeInLayout=false</code>, * or if this layout's <code>target</code> property is null. * * <p>Layout subclasses that support <code>useVirtualLayout=true</code> must * override this method to compute a potentially approximate value for * elements that are not in view.</p> * * Param: index Index of the layout element. * * Returns: The specified element's layout bounds. */ internal virtual Rectangle GetElementBounds(int index) // TEMP internal { GroupBase g = Target; if (null == g) { return(null); } int n = g.NumberOfChildren; if ((index < 0) || (index >= n)) { return(null); } ILayoutElement elt = (ILayoutElement)g.GetChildAt(index); if (null == elt || !elt.IncludeInLayout) { return(null); } float eltX = LayoutUtil.GetLayoutBoundsX((InvalidationManagerClient)elt); float eltY = LayoutUtil.GetLayoutBoundsY((InvalidationManagerClient)elt); float eltW = LayoutUtil.GetLayoutBoundsWidth((InvalidationManagerClient)elt); float eltH = LayoutUtil.GetLayoutBoundsHeight((InvalidationManagerClient)elt); return(new Rectangle(eltX, eltY, eltW, eltH)); }
///<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)); }