ComponentFactory.Krypton.Ribbon.ViewDrawRibbonGroupCheckBoxText.GetPreferredSize C# (CSharp) Method

GetPreferredSize() public method

Discover the preferred size of the element.
public GetPreferredSize ( ViewLayoutContext context ) : Size
context ComponentFactory.Krypton.Toolkit.ViewLayoutContext Layout context.
return System.Drawing.Size
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null) throw new ArgumentNullException("context");

            // A change in state always causes a size and layout calculation
            if (_cacheState != State)
            {
                MakeDirty();
                _cacheState = State;
            }

            // If the palette has changed since we last calculated
            if (_ribbon.DirtyPaletteCounter != _dirtyPaletteSize)
            {
                // Ask the renderer for the contents preferred size
                _preferredSize = context.Renderer.RenderStandardContent.GetContentPreferredSize(context, _contentProvider,
                                                                                                this, VisualOrientation.Top,
                                                                                                State, false);

                // Subtract the extra space used to ensure it draws
                _heightExtra = (_ribbon.CalculatedValues.DrawFontHeight - _ribbon.CalculatedValues.RawFontHeight) * 2;
                _preferredSize.Height -= _heightExtra;

                // If the text is actually empty, then force it to be zero width
                if (string.IsNullOrEmpty(GetShortText()))
                    _preferredSize.Width = 0;

                // Cached value is valid till dirty palette noticed
                _dirtyPaletteSize = _ribbon.DirtyPaletteCounter;
            }

            return _preferredSize;
        }