//public override Rectangle GetElementBounds(int index)
        //{
        //    //if (!UseVirtualLayout)
        //        return base.GetElementBounds(index);

        //    //var g = Target;
        //    //if (null == g || (index < 0) || (index >= g.NumberOfContentChildren)) 
        //    //    return null;

        //    //return llv.getBounds(index);
        //}

        //public LayoutDirection Direction;
        //public int HorizontalSpacing;
        //public int VerticalSpacing;

        #endregion
        
        ///<summary>
        ///</summary>
        override internal void Measure()
        {
            GroupBase layoutTarget = Target;
            if (null == layoutTarget)
                return;

            SizesAndLimit size = new SizesAndLimit();
            bool justify = _verticalAlign == VerticalAlign.Justify;
            int numElements = layoutTarget.NumberOfContentChildren; // How many elements there are in the target
            int numElementsInLayout = numElements;      // How many elements have includeInLayout == true, start off with numElements.
            int requestedColumnCount = RequestedColumnCount;
            int columnsMeasured = 0;
      
            float preferredHeight = 0; // sum of the elt preferred heights
            float preferredWidth = 0;  // max of the elt preferred widths
            float minHeight = 0;       // sum of the elt minimum heights
            float minWidth = 0;        // max of the elt minimum widths

            float? fixedColumnWidth = null;
            if (!_variableColumnWidth)
                fixedColumnWidth = _columnWidth;  // may query typicalLayoutElement, elt at index=0
        
            ILayoutElement element;
            for (int i = 0; i < numElements; i++)
            {
                element = (ILayoutElement) layoutTarget.GetContentChildAt(i);
                if (null == element || !element.IncludeInLayout)
                {
                    numElementsInLayout--;
                    continue;
                }

                //Debug.Log(element + " measured. preferredHeight: " + preferredHeight);

                // Consider the width of each element, inclusive of those outside
                // the RequestedColumnCount range.
                GetElementHeight(element, justify, size);
                preferredHeight = Mathf.Max(preferredHeight, size.PreferredSize);
                minHeight = Mathf.Max(minHeight, size.MinSize);

                // Can we measure this row height?
                if (RequestedColumnCount == -1 || columnsMeasured < RequestedColumnCount)
                {
                    GetElementWidth(element, fixedColumnWidth, size);
                    preferredWidth += size.PreferredSize;
                    minWidth += size.MinSize;
                    columnsMeasured++;
                }
            }

            // Calculate the total number of rows to measure
            int columnsToMeasure = (_requestedColumnCount != -1) ? requestedColumnCount : 
                                                                Mathf.Max(_requestedMinColumnCount, numElementsInLayout);
            // Do we need to measure more rows?
            if (columnsMeasured < columnsToMeasure)
            {
                // Use the typical element
                element = TypicalLayoutElement;
                if (null != element)
                {
                    // Height
                    GetElementHeight(element, justify, size);
                    preferredHeight = Mathf.Max(preferredHeight, size.PreferredSize);
                    minHeight = Mathf.Max(minHeight, size.MinSize);
                    
                    // Width
                    GetElementWidth(element, fixedColumnWidth, size);
                    preferredWidth += size.PreferredSize * (columnsToMeasure - columnsMeasured);
                    minWidth += size.MinSize * (columnsToMeasure - columnsMeasured);
                    columnsMeasured = columnsToMeasure;
                }
            }

            // Add gaps
            if (columnsMeasured > 1)
            {
                float hgap = _gap * (columnsMeasured - 1);
                preferredWidth += hgap;
                minWidth += hgap;
            }

            float hPadding = _paddingLeft + _paddingRight;
            float vPadding = _paddingTop + _paddingBottom;
            
            //layoutTarget.MeasuredHeight = preferredHeight + vPadding;
            //layoutTarget.MeasuredWidth = preferredWidth + hPadding;
            //layoutTarget.MeasuredMinHeight = minHeight + vPadding;
            //layoutTarget.MeasuredMinWidth  = minWidth + hPadding;

            layoutTarget.MeasuredWidth = Mathf.Ceil(preferredWidth + hPadding);
            layoutTarget.MeasuredHeight = Mathf.Ceil(preferredHeight + vPadding);
            layoutTarget.MeasuredMinWidth = Mathf.Ceil(minWidth + hPadding);
            layoutTarget.MeasuredMinHeight = Mathf.Ceil(minHeight + vPadding);  

            /*if (((Component)Target.Parent).Id == "horiz")
                Debug.Log("Measured: " + Target.MeasuredWidth + ", " + Target.MeasuredHeight);*/
        }
 /**
  *  
  *  Fills in the result with preferred and min sizes of the element.
  */
 private void GetElementWidth(ILayoutElement element, float? fixedColumnWidth, SizesAndLimit result)
 {
     // Calculate preferred height first, as it's being used to calculate min height below
     float elementPreferredWidth = fixedColumnWidth ?? Mathf.Ceil(LayoutUtil.GetPreferredBoundsWidth((InvalidationManagerClient)element));
     // Calculate min height
     bool flexibleWidth = null != element.PercentWidth;
     float elementMinWidth = flexibleWidth ? Mathf.Ceil(LayoutUtil.GetMinBoundsWidth((InvalidationManagerClient)element)) :
                                                    elementPreferredWidth;
     result.PreferredSize = elementPreferredWidth;
     result.MinSize = elementMinWidth;
 }
 /**
  *  
  *  Fills in the result with preferred and min sizes of the element.
  */
 private void GetElementHeight(ILayoutElement element, bool justify, SizesAndLimit result)
 {
     // Calculate preferred width first, as it's being used to calculate min width
     float elementPreferredHeight = Mathf.Ceil(LayoutUtil.GetPreferredBoundsHeight((InvalidationManagerClient)element));
     
     // Calculate min width
     bool flexibleHeight = null != element.PercentHeight || justify;
     float elementMinHeight = flexibleHeight ? Mathf.Ceil(LayoutUtil.GetMinBoundsHeight((InvalidationManagerClient)element)) : 
                                                  elementPreferredHeight;
     result.PreferredSize = elementPreferredHeight;
     result.MinSize = elementMinHeight;
 }
Beispiel #4
0
 /**
  *  
  *  Fills in the result with preferred and min sizes of the element.
  */
 private void GetElementHeight(ILayoutElement element, float? fixedRowHeight, SizesAndLimit result)
 {
     // Calculate preferred height first, as it's being used to calculate min height below
     float elementPreferredHeight = fixedRowHeight ?? Mathf.Ceil(LayoutUtil.GetPreferredBoundsHeight((InvalidationManagerClient) element));
     // Calculate min height
     bool flexibleHeight = null != element.PercentHeight;
     float elementMinHeight = flexibleHeight ? Mathf.Ceil(LayoutUtil.GetMinBoundsHeight((InvalidationManagerClient) element)) : 
                                                    elementPreferredHeight;
     result.PreferredSize = elementPreferredHeight;
     result.MinSize = elementMinHeight;
 }