Beispiel #1
0
        /// <summary>
        /// Draws the Legend and all entries into the area within <see cref="Bounds"/>
        /// </summary>
        /// <param name="graph"></param>
        public void Render(GraphView graph)
        {
            if (Border)
            {
                graph.DrawFrame(Bounds, 0, true);
            }

            // start the legend at
            int y = Bounds.Top + (Border ? 1 : 0);
            int x = Bounds.Left + (Border ? 1 : 0);

            // how much horizontal space is available for writing legend entries?
            int availableWidth  = Bounds.Width - (Border ? 2 : 0);
            int availableHeight = Bounds.Height - (Border ? 2 : 0);

            int linesDrawn = 0;

            foreach (var entry in entries)
            {
                if (entry.Item1.Color.HasValue)
                {
                    Application.Driver.SetAttribute(entry.Item1.Color.Value);
                }
                else
                {
                    graph.SetDriverColorToGraphColor();
                }

                // add the symbol
                graph.AddRune(x, y + linesDrawn, entry.Item1.Rune);

                // switch to normal coloring (for the text)
                graph.SetDriverColorToGraphColor();

                // add the text
                graph.Move(x + 1, y + linesDrawn);

                string str = TextFormatter.ClipOrPad(entry.Item2, availableWidth - 1);
                Application.Driver.AddStr(str);

                linesDrawn++;

                // Legend has run out of space
                if (linesDrawn >= availableHeight)
                {
                    break;
                }
            }
        }