예제 #1
0
        /// <summary>
        /// Updates control size based on font.
        /// </summary>
        /// <param name="font">font for menu item rendering.</param>
        internal void UpdateSizes(IFont font)
        {
            if (0 == this.menuItems.Count)
            {
                return;
            }

            if (this.controlsBounds.Width < 0)
            {
                int maxWidth = 40;                  // minimum Width == 40
                int h        = 1;

                // calculate max Width
                foreach (MenuItem menuItem in this.menuItems)
                {
                    if (false == menuItem.IsHr)
                    {
                        int len = 24 + ((null != font) ? font.TextLength(menuItem.Text) : menuItem.Text.Length * Menu.defaultCharWidth);

                        if (len > maxWidth)
                        {
                            maxWidth = len;
                        }
                    }
                }

                maxWidth += 32 + 4 + 4 + Menu.defaultCharWidth * 2;

                int offX          = this.bounds.X;
                int offY          = this.bounds.Y;
                int nButtonHeight = (null != font) ? 15 + font.TextHeight("") : 23;

                if (true == this.topItem)
                {
                    offY += this.bounds.Height;
                }
                else
                {
                    offX += this.bounds.Width + 1;
                }

                // Update sizes
                foreach (MenuItem menuItem in this.menuItems)
                {
                    if (true == menuItem.IsHr)
                    {
                        menuItem.SetSize(offX + 2, offY + h + 1, maxWidth - 4, 1);

                        h += 2;
                    }
                    else
                    {
                        menuItem.SetSize(offX + 2, offY + h + 1, maxWidth - 4, nButtonHeight - 1);

                        h += nButtonHeight;

                        menuItem.UpdateSizes(font);
                    }
                }

                h += 2;

                this.controlsBounds.X      = offX;
                this.controlsBounds.Y      = offY;
                this.controlsBounds.Width  = maxWidth;
                this.controlsBounds.Height = h;
            }
        }