Example #1
0
    // Return string of rendered menu
    public string Draw(int textWidth = 40, int textHeight = 7)
    {
        // long clock = DateTime.Now.Ticks; // used to scroll menu text if it is too wide
        string output = "";

        var currentItem = this.path.Peek();

        if (currentItem == null)
        {
            throw new Exception("Menu: currentItem is null");
        }

        output += this.breadcrumbs() + "\n\n";


        int selected = currentItem.children.IndexOf(this.selectedItem);

        int start  = 0;
        int length = currentItem.children.Count;


        if (selected > (textHeight - 2) / 2)
        {
            start = selected - (textHeight - 2) / 2;
        }

        if (length > textHeight - 2)
        {
            length = textHeight - 2;
        }

        if (start + length > currentItem.children.Count)
        {
            start  = currentItem.children.Count - (textHeight - 2);
            length = textHeight - 2;
        }

        if (start < 0)
        {
            start = 0;
        }

        for (int n = start; (n < (start + length) && n < currentItem.children.Count); n++)
        {
            EasyMenuItem child = currentItem.children[n];
            if (child == this.selectedItem)
            {
                // Todo, if text is too wide, have it scroll horizontally
                output += "> " + child.GetText() + " <\n";
            }
            else
            {
                output += child.GetText() + "\n";
            }
        }

        return(output);
    }
Example #2
0
    public int CompareTo(object obj)
    {
        if (obj == null)
        {
            return(1);
        }

        EasyMenuItem otherItem = obj as EasyMenuItem;

        if (otherItem != null)
        {
            return(this.GetText().CompareTo(otherItem.GetText()));
        }
        else
        {
            throw new ArgumentException("Object is not a EasyMenuItem");
        }
    }