コード例 #1
0
        public LengthCollection Clone()
        {
            var c = new LengthCollection();

            this.Items.ForEach(v => c.Import(v.Clone()));
            return(c);
        }
コード例 #2
0
        protected LengthCollection CalcTableLength()
        {
            // Console width
            int maxlength = CoEx.Width;

            // Items
            var items = this.Items.ToArray().ToList();

            // initialize array with one field per column
            LengthCollection collection = new LengthCollection();

            for (int i = 0; i < this.Items.Max(v => v.Data.Length); i++)
            {
                collection.Import(new LengthConf()
                {
                    Index = i
                });
            }

            // iterate rows
            for (int i = 0; i < this.Items.Count; i++)
            {
                // iterate columns
                for (int j = 0; j < this.Items[i].Data.Length; j++)
                {
                    // when length of cell > current length
                    if (this.Items[i].Data[j] != null && this.Items[i].Data[j].Length > (collection.Items[j].Length))
                    {
                        collection.Items[j].Length = collection.Items[j].OriginalLength = this.Items[i].Data[j].Length;
                    }
                }
            }

            // fix overflow by percentage
            if (collection.TotalLength > maxlength)
            {
                // diffrence
                int diff = collection.TotalLength - maxlength;
                foreach (var item in collection.BigItems)
                {
                    // remove i percent of diff in column i if percent>=minperc
                    item.Length -= ((int)Math.Round((diff * item.BigLengthPercent / 100)));
                }
            }

            if (this.Settings.StretchHorizontal)
            {
                // add remaining length to last column
                if (collection.TotalLength < maxlength)
                {
                    int diff = maxlength - collection.TotalLength;
                    collection.Items.Last().Length += diff;
                }
            }
            else
            {
                // add length for padding and border to last column
                int borderpadding = (3 * (collection.Items.Count - 1)) + 4;
                if (collection.TotalLength + borderpadding < maxlength)
                {
                    collection.Items.Last().Length += borderpadding;
                }
            }

            return(collection);
        }