예제 #1
0
        private Column AddTextOrInputColumn(string header  = null, string footer = null,
                                            float minWidth = -1, float maxWidth  = -1, bool isInput = false)
        {
            if (this.headerDatum == null)
            {
                this.headerDatum       = Datum.Header();
                this.headerDatum.table = this;
            }
            if (this.footerDatum == null)
            {
                this.footerDatum       = Datum.Footer();
                this.footerDatum.table = this;
            }
            this.headerDatum.elements.Add();
            this.footerDatum.elements.Add();
            Column c = Column.TextColumn(this, this.columns.Count,
                                         minWidth, maxWidth, this.headerDatum, this.footerDatum, isInput);

            this.columns.Add(c);
            c.headerValue = header;
            c.footerValue = footer;
            return(c);
        }
예제 #2
0
        private void FinishInitialize(Dictionary <string, Sprite> sprites = null, bool hasHeaderIcons = false,
                                      Action <Column, PointerEventData> headerClickCallback = null)
        {
            this.rowAnimationDecimalDuration = (decimal)this.rowAnimationDuration;
            this._sprites = sprites;

            this._hasHeader = false;
            this._hasFooter = false;

            if (this.font == null)
            {
                if (Defaults.Instance.font != null)
                {
                    this.font      = Defaults.Instance.font;
                    this.fontStyle = Defaults.Instance.fontStyle;
                }
                else
                {
#if TMP_PRESENT
                    this.error("Please provide a TextMeshPro Font under 'General Settings'");
#else
                    this.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
#endif
                }
            }

            // gab this in a temp value that won't get updated
            if (this._minRowHeight == -1f)
            {
                this._minRowHeight = this.minRowHeight;
            }

            if (this.minRowHeight < 14)
            {
                this.error("Table Min Row Height must be >= 14 (set this as high as practical in order to reduce initialization overhead)");
            }

            if (this.defaultFontSize <= 0)
            {
                this.error("Table Default Font Size must be > 0");
            }
            // match our UI colors for row and cell effects if we aren't in cell-selection mode
            if (this.selectionMode == SelectionMode.ROW || this.selectionMode == SelectionMode.MULTIROW)
            {
                this.cellDownColor   = this.rowDownColor;
                this.cellHoverColor  = this.rowHoverColor;
                this.cellSelectColor = this.rowSelectColor;
            }

            // this handles the case on table re-use where the row height was inrecemented and needs to be reset
            this.minRowHeight = this._minRowHeight;

            if (this.rowVerticalSpacing + this.defaultFontSize > this.minRowHeight)
            {
                this.minRowHeight = this.rowVerticalSpacing + this.defaultFontSize;
            }

            if (this.headerTopMargin + this.headerBottomMargin + this.defaultFontSize > this.minHeaderHeight)
            {
                this.minHeaderHeight = this.headerTopMargin + this.headerBottomMargin + this.defaultFontSize;
            }

            if (this.footerTopMargin + this.footerBottomMargin + this.defaultFontSize > this.minFooterHeight)
            {
                this.minFooterHeight = this.footerTopMargin + this.footerBottomMargin + this.defaultFontSize;
            }

            if (this.loadingOverlay != null)
            {
                this.loadingOverlay.gameObject.SetActive(true);
                this.loadingOverlay.alpha = 1f;
                this.overlayIsHiding      = false;
            }


            if (this.rows == null)
            {
                this.rows = new List <Row>();
            }

            for (int i = 0; i < this.columns.Count; i++)
            {
                Column c = this.columns[i];
                if (c.columnType == Column.ColumnType.IMAGE)
                {
                    if (this.sprites == null)
                    {
                        this.error("Cannot declare Image Column without spriteDict");
                    }

                    this.minRowHeight = Mathf.Max(this.minRowHeight,
                                                  c.imageHeight + this.rowVerticalSpacing);
                }
                if (c.headerValue != null)
                {
                    this._hasHeader = true;
                }

                if (c.footerValue != null)
                {
                    this._hasFooter = true;
                }
            }

            if (this.hasHeader)
            {
                this.minHeaderHeight = Mathf.Max(this.minHeaderHeight,
                                                 this.headerIconHeight + this.headerTopMargin +
                                                 this.headerBottomMargin);
            }

            this._hasHeaderIcons = hasHeaderIcons;

            if (this.columns.Count > 1)
            {
                this._hasColumnOverlay = true;
            }
            else
            {
                this._hasColumnOverlay = false;
            }

            if (this.columnOverlayLines == null)
            {
                this.columnOverlayLines = new List <RectTransform>();
            }

            if (this.factory == null)
            {
                this.factory = new Factory(this);
            }

            if (this.control == null)
            {
                this.control         = new Control(this, this.factory);
                this.extraTextColumn = Column.TextColumn(this, -1, -1, -1,
                                                         this.headerDatum, this.footerDatum, false);
            }

            if (this.data != null)
            {
                this.data.Clear();
            }
            //intentially make a new one here, dont reuse old
            this.data = new TableDatumList(this, this.control);

            this.factory.Build(this.headerDatum, this.footerDatum, this.control);

            //////////////////////////////////////////////
            // Do post factory cleanup and assigns here
            if (this.headerRow != null)
            {
                for (int i = 0; i < this.headerRow.cells.Count; i++)
                {
                    HeaderCell hc = this.headerRow.cells[i] as HeaderCell;
                    hc.icon.gameObject.SetActive(this.hasHeaderIcons);
                    if (this.columns.Count - 1 >= i)
                    {
                        hc.Initialize(this.columns[i], headerClickCallback);
                    }
                }
            }
            this.bodyRect.isMeasured = false;
            this.bodyScroller.horizontalNormalizedPosition = 0f;
            this.bodyScroller.verticalNormalizedPosition   = 1f;
        } // _initialize