Exemplo n.º 1
0
        public void DoMeasure(Row r)
        {
            Datum d = r.datum;

            this.datumRevision = d.revision;
            d.ClearMeasure();
            for (int i = 0; i < d.elements.Count; i++)
            {
                this.MeasureCell(d, d.elements[i], this.table.columns[i]);
            }
            this.MeasureCell(d, d.extraText, this.table.extraTextColumn);

            d.isDirty = false;

            if (!d.isHeader && !d.isFooter && (this.table.min100PercentWidth || this.table.max100PercentWidth))
            {
                float bodyw = this.table.root.rect.width -
                              this.table.leftMargin - this.table.rightMargin -
                              ((this.table.columns.Count + 1) *
                               this.table.horizontalSpacing);

                float wsum = this.SumColumnWidths();


                bool hasNullMaxWidth = false;

                for (int i = 0; i < this.table.columns.Count; i++)
                {
                    Column c = this.table.columns[i];
                    if (!c.measuredMaxWidth.HasValue)
                    {
                        hasNullMaxWidth = true;
                        break;
                    }
                }

                // we are too wide... set us so we try to fit
                // (+1 here cause sometimes wierd rounding on prev loop)
                if (this.table.max100PercentWidth && (hasNullMaxWidth || wsum > bodyw + 1f))
                {
                    int  tries        = 0;
                    bool hadFudge     = true;
                    int  nonImageCols = 0;

                    for (int i = 0; i < this.table.columns.Count; i++)
                    {
                        Column c = this.table.columns[i];
                        // clear our previously set min (if any)
                        c.measuredMinWidth = null;
                        if (c.columnType != Column.ColumnType.IMAGE)
                        {
                            nonImageCols += 1;
                        }
                    }

                    while (hadFudge && tries < 100)
                    {
                        //Debug.Log("COL RESIZE: " + tries);

                        tries += 1;

                        // yeah, i get it... this will be run for the first
                        //  iteration and it doesn't need to be.  want to fight about it?
                        wsum     = this.SumColumnWidths();
                        hadFudge = false;

                        for (int i = 0; i < this.table.columns.Count; i++)
                        {
                            Column c = this.table.columns[i];

                            if (nonImageCols == 0 || c.columnType != Column.ColumnType.IMAGE)
                            {
                                float usew = (c.safeWidth / wsum) * bodyw;
                                if (usew < c.minWidth)
                                {
                                    c.measuredMaxWidth = c.minWidth;
                                    r.foundMax         = true;
                                    hadFudge           = true;
                                    break;
                                }
                                else
                                {
                                    c.measuredMaxWidth = usew;
                                    r.foundMax         = true;
                                }
                            }
                            else
                            {
                                c.measuredMaxWidth = c.safeWidth;
                                r.foundMax         = true;
                            }
                        }
                    } // while fudge

                    return;
                } // if max100

                // we are too narrow... set us so we try to fit
                // (-1 here cause sometimes wierd rounding on prev loop)
                if (this.table.min100PercentWidth && wsum < bodyw - 1f)
                {
                    //Debug.Log(d.uid + " DOING MIN!: " + wsum + " vs" + bodyw);

                    int   nonImageCols = 0;
                    float minSum       = 0;

                    for (int i = 0; i < this.table.columns.Count; i++)
                    {
                        Column c = this.table.columns[i];
                        // clear our previously set max (if any)
                        c.measuredMaxWidth = null;
                        if (c.minWidth > 0f)
                        {
                            minSum += Mathf.Max(c.minWidth);
                        }
                        if (c.columnType != Column.ColumnType.IMAGE)
                        {
                            nonImageCols += 1;
                        }
                    }

                    for (int i = 0; i < this.table.columns.Count; i++)
                    {
                        Column c    = this.table.columns[i];
                        float  usew = 0;
                        if (nonImageCols > 0 && c.columnType == Column.ColumnType.IMAGE)
                        {
                            usew = c.minWidth;
                        }
                        else if (minSum > 0)
                        {
                            usew = (c.minWidth / minSum) * (bodyw - wsum);
                        }
                        else
                        {
                            if (nonImageCols > 0)
                            {
                                usew = (1f / nonImageCols) * (bodyw - wsum);
                            }
                            else
                            {
                                usew = (1f / this.table.columns.Count) * (bodyw - wsum);
                            }
                        }

                        c.measuredMinWidth = c.rawWidth + usew;
                        //Debug.Log(d.uid + " Seting measured MW!: " + c.measuredMinWidth.Value + ": " + c.idx);
                    }
                } // if min100
            }     // if !isHeader and !isFooter
        }         // doMeasure
Exemplo n.º 2
0
        public void DoMeasure(Datum d)
        {
            this.datumRevision = d.revision;
            d.ClearMeasure();
            for (int i = 0; i < d.elements.Count; i++)
            {
                this.MeasureCell(d, d.elements[i], this.table.columns[i]);
            }
            this.MeasureCell(d, d.extraText, this.table.extraTextColumn);

            d.isDirty = false;

            //Debug.Log("Completed measure on: " + d.uid + " REV: " + d.revision + " safeHeight: " + d.safeHeight() + " " + d.safeCellHeight());

            if (!d.isHeader && !d.isFooter)
            {
                // size us based on 100% table settings
                if (this.table.min100PercentWidth || this.table.max100PercentWidth)
                {
                    float bodyw = this.table.root.rect.width -
                                  this.table.leftMargin - this.table.rightMargin -
                                  ((this.table.columns.Count + 1) *
                                   this.table.horizontalSpacing);

                    float wsum = this.table.SumColumnWidths();

                    // we are too wide... set us so we try to fit
                    // (+1 here cause sometimes wierd rounding on prev loop)
                    if (this.table.max100PercentWidth &&
                        wsum > bodyw + 1f)
                    {
                        //Debug.Log(d.uid + " DOING MAX!: " + wsum + " vs" + bodyw);

                        int  tries        = 0;
                        bool hadFudge     = true;
                        int  nonImageCols = 0;

                        for (int i = 0; i < this.table.columns.Count; i++)
                        {
                            Column c = this.table.columns[i];
                            // clear our previously set min (if any)
                            c.measuredMinWidth = null;
                            if (c.columnType != Column.ColumnType.IMAGE)
                            {
                                nonImageCols += 1;
                            }
                        }

                        while (hadFudge && tries < 100)
                        {
                            //Debug.Log("COL RESIZE: " + tries);

                            tries += 1;

                            // yeah, i get it... this will be run for the first
                            //  iteration and it doesn't need to be.  want to fight about it?
                            wsum     = this.table.SumColumnWidths();
                            hadFudge = false;

                            for (int i = 0; i < this.table.columns.Count; i++)
                            {
                                Column c = this.table.columns[i];

                                if (nonImageCols == 0 ||
                                    c.columnType != Column.ColumnType.IMAGE)
                                {
                                    float usew = (c.safeWidth / wsum) * bodyw;
                                    if (usew < c.minWidth)
                                    {
                                        c.measuredMaxWidth = c.minWidth;
                                        hadFudge           = true;
                                        continue;
                                    }
                                    else
                                    {
                                        c.measuredMaxWidth = usew;
                                    }
                                }
                            }
                        } // while fudge

                        return;
                    } // if max100

                    // we are too narrow... set us so we try to fit
                    // (-1 here cause sometimes wierd rounding on prev loop)
                    if (this.table.min100PercentWidth &&
                        wsum < bodyw - 1f)
                    {
                        //Debug.Log(d.uid + " DOING MIN!: " + wsum + " vs" + bodyw);

                        int   nonImageCols = 0;
                        float minSum       = 0;

                        for (int i = 0; i < this.table.columns.Count; i++)
                        {
                            Column c = this.table.columns[i];
                            // clear our previously set max (if any)
                            c.measuredMaxWidth = null;
                            if (c.minWidth > 0f)
                            {
                                minSum += Mathf.Max(c.minWidth);
                            }
                            if (c.columnType != Column.ColumnType.IMAGE)
                            {
                                nonImageCols += 1;
                            }
                        }

                        for (int i = 0; i < this.table.columns.Count; i++)
                        {
                            Column c    = this.table.columns[i];
                            float  usew = 0;
                            if (nonImageCols > 0 && c.columnType == Column.ColumnType.IMAGE)
                            {
                                usew = c.minWidth;
                            }
                            else if (minSum > 0)
                            {
                                usew = (c.minWidth / minSum) * (bodyw - wsum);
                            }
                            else
                            {
                                if (nonImageCols > 0)
                                {
                                    usew = (1f / nonImageCols) * (bodyw - wsum);
                                }
                                else
                                {
                                    usew = (1f / this.table.columns.Count) * (bodyw - wsum);
                                }
                            }

                            c.measuredMinWidth = c.rawWidth + usew;
                            //Debug.Log(d.uid + " Seting measured MW!: " + c.measuredMinWidth.Value + ": " + c.idx);
                        }
                    } // if min100
                }     // if min100 or max 100

                /*
                 * Row r = this.table.getRowForDatum(d);
                 * if (r != null) {
                 * r.checkAnimation();
                 * this.table.dirtyLater();
                 * }
                 */
            } // if !isHeader and !isFooter

            else if (d.isHeader)
            {
                /*
                 * if (d.safeCellHeight() >= 0) {
                 * this.table.headerRow.checkAnimation();
                 * //print("HEADER COMPLETE: " + d.uid + ": " + d.safeHeight());
                 * if (d.safeCellHeight() + this.table.headerTopMargin +
                 *    this.table.headerBottomMargin > this.table.minHeaderHeight) {
                 *  this.table.dirtyLater();
                 * }
                 * }
                 */
            }
            else
            {
                /*
                 * if (d.safeCellHeight() >= 0) {
                 * this.table.footerRow.checkAnimation();
                 * //print("FOOTER COMPLETE: " + d.uid + ": " + d.safeHeight());
                 * if (d.safeCellHeight() + this.table.footerTopMargin +
                 *    this.table.footerBottomMargin > this.table.minFooterHeight) {
                 *  this.table.dirtyLater();
                 * }
                 * }
                 */
            }
        } // doMeasure