Пример #1
0
        public void OnBodyScroll(Vector2 val)
        {
            if (!this.table.isRunning)
            {
                return;
            }

            if (this.table.hasHeader)
            {
                this.table.headerRow.rt.localPosition =
                    new Vector3(this.table.bodySizer.localPosition.x, 0f);
            }
            if (this.table.hasFooter)
            {
                this.table.footerRow.rt.localPosition =
                    new Vector3(this.table.bodySizer.localPosition.x, 0f);
            }
            if (this.table.hasColumnOverlay)
            {
                this.table.columnOverlayContent.localPosition =
                    new Vector3(this.table.bodySizer.localPosition.x, 0f);
            }

            VerticalControl res = this.GetVerticalControl();

            //Debug.Log("TOP: " + res.top + " VPOS: " + res.verticalPosition);

            if (this.table.rows.Count > 0)
            {
                this.table.rows[0].rt.localPosition =
                    new Vector3(0, res.verticalPosition * -1f);
            }

            for (int i = 0; i < this.table.rows.Count; i++)
            {
                Row row = this.table.rows[i];
                if (i + res.top >= this.table.data.Count)
                {
                    row.gameObject.SetActive(false);
                }
                else
                {
                    row.gameObject.SetActive(true);
                    row.datum = this.table.data[res.top + i];
                }
                this.HorPosExtraText(row);
            }
        }
Пример #2
0
        private VerticalControl GetVerticalControl()
        {
            VerticalControl res     = new VerticalControl();
            float           vscroll = 1f - this.table.bodyScroller.verticalNormalizedPosition;
            float           visY    = ((this.table.bodySizer.rect.height - this.table.bodyRect.rt.rect.height) * vscroll);

            int   i        = 0;
            float useH     = 0;
            bool  hadUndef = false;

            // use our cached vpos if available
            Datum lastD;
            Datum d = this.table.rows[0].datum;

            i = this.table.data.IndexOf(d);

            if (d != null && d.measuredVertPos.HasValue && i >= 0)
            {
                useH = d.measuredVertPos.Value;

                //Debug.Log("CHECKING: " + useH + " : " +
                //    visY + " : " + i);

                // if our top visible row (useH) is 'below' or screen top
                //   so we need to move our top visible row 'up'
                if (useH > visY)
                {
                    while (d != null && d.measuredVertPos.HasValue)
                    {
                        useH = d.measuredVertPos.Value;
                        //Debug.Log("trying cached BELOW result: " + useH + " : " +
                        //          visY + " : " + i);
                        if (useH <= visY)
                        {
                            res.top = i;
                            res.verticalPosition = useH;
                            //Debug.Log("returning cached below val: " + useH + " : " +
                            //        visY + " : " + i);
                            return(res);
                        }
                        i -= 1;
                        if (i >= 0)
                        {
                            d = this.table.data[i];
                        }
                        else
                        {
                            d = null;
                        }
                    }
                } // if useH > visY


                // else our top visible row (useH) is 'above' our screen top
                //   so we need to move our top visible row 'down'
                else
                {
                    while (d != null && d.measuredVertPos.HasValue)
                    {
                        useH = d.measuredVertPos.Value;
                        //Debug.Log("trying cached ABOVE result: " + useH + " : " +
                        //          visY + " : " + i);
                        if (useH > visY || i == this.table.data.Count - 1)
                        {
                            d = this.table.data[i - 1];
                            if (d == null)
                            {
                                break;
                            }
                            // this handles the special case where we have a data update
                            //  and haven't measured yet, or we contain no data
                            if (!d.measuredVertPos.HasValue)
                            {
                                break;
                            }
                            res.top = i - 1;
                            res.verticalPosition = d.measuredVertPos.Value;
                            //Debug.Log("returning from ABOVE");
                            return(res);
                        }
                        i += 1;
                        if (i < this.table.data.Count)
                        {
                            lastD = d;
                            d     = this.table.data[i];
                            if (!d.measuredVertPos.HasValue &&
                                d.SafeHeight() >= 0 &&
                                lastD.SafeHeight() >= 0)
                            {
                                d.measuredVertPos = useH +
                                                    Mathf.Max(this.table.minRowHeight, lastD.SafeHeight());
                            }
                            //Debug.Log(i + " HasValue " + d.measuredVertPos.HasValue);
                        }
                        else
                        {
                            d = this.table.data[i - 1];
                            // this handles the special case where we have a data update
                            //  and haven't measured yet
                            if (!d.measuredVertPos.HasValue)
                            {
                                break;
                            }
                            res.top = i - 1;
                            res.verticalPosition = d.measuredVertPos.Value;
                            //Debug.Log("returning LAST ROW from ABOVE");
                            return(res);
                        }
                    }
                } // else (useH <= visY)
            }     // if d!= null & d.measuredVertPos.HasValue

            //Debug.LogWarning("CACHE FAILED!");

            // else if we didn't return anything yet,
            //    brute force and cache what we can
            useH = 0;
            for (i = 0; i < this.table.data.Count; i++)
            {
                if (this.table.data[i].SafeHeight() >= 0)
                {
                    if (!hadUndef)
                    {
                        this.table.data[i].measuredVertPos = res.verticalPosition;
                    }
                    useH = Mathf.Max(this.table.minRowHeight,
                                     this.table.data[i].SafeHeight());
                }
                else
                {
                    hadUndef = true;
                    useH     = this.table.data.safeTempRowHeight;
                }
                if (res.verticalPosition + useH > visY)
                {
                    res.top = i;
                    return(res);
                }
                else
                {
                    res.verticalPosition += useH;
                }
            }
            res.top = Math.Max(0, this.table.data.Count - 1);
            return(res);
        }