Beispiel #1
0
        /// <summary>
        /// Formats a table item accordingly to the given option. The text should be without any modifiers or colors.
        /// It  also stores the returned result on the ModifiedText property of the item after applying the modifiers.
        /// </summary>
        public static string FormatTableItem(TextTableColumn column)
        {
            const int AddDotWrapCount = 3;

            string text = column.Text;

            if (text.Length > column.Size)
            {
                switch (column.WrapMode)
                {
                case WrapTextMode.Clamp:
                    text = text.Substring(0, column.Size);
                    break;

                case WrapTextMode.AddDots:
                    DebugUtil.Assert(text.Length <= 3, "TO USE ADD POINTS WRAP THE TEXT MUST BE AT LEAST 3 CHARS LONG");
                    text = text.Substring(0, column.Size - AddDotWrapCount);
                    text = text.PadRight(column.Size, '.');
                    break;
                }
            }

            var diff = column.Size - column.Text.Length;

            if (diff > 0)
            {
                switch (column.Align)
                {
                case TextTableAlign.Left:
                    text = text.PadRight(column.Size, column.PaddingChar);
                    break;

                case TextTableAlign.Center:
                    if (diff % 2 != 0)
                    {
                        diff++;
                        column.Size++;     // need to add one here to compensate for the one padding we are adding
                    }
                    diff /= 2;
                    text  = text.PadLeft(column.Size - diff, column.PaddingChar);
                    text  = text.PadRight(column.Size, column.PaddingChar);
                    break;

                case TextTableAlign.Right:
                    text = text.PadLeft(column.Size, column.PaddingChar);
                    break;
                }
            }

            text = ModifyText(text, column.ModifyTextOptions);
            column.ModifiedText = text;
            return(text);
        }
Beispiel #2
0
        public static TextTableColumn CreateColumn(
            string text,
            float weight,
            Color color,
            int textModifiers)
        {
            var item = new TextTableColumn();

            item.Align = TextTableAlign.Left;
            item.Text  = text;
            item.ModifyTextOptions.Color = color;
            item.PaddingChar             = ' ';
            item.WeightOnLine            = weight;
            item.WrapMode = WrapTextMode.Clamp;
            item.ModifyTextOptions.Modifiers = textModifiers;

            return(item);
        }
Beispiel #3
0
        /// <summary>
        /// Shorthand for calling FormatTableItem and retuning the length of the result.
        /// </summary>
        public static int CalculateTableColumnLength(TextTableColumn column)
        {
            var text = FormatTableItem(column);

            return(text.Length);
        }