Ejemplo n.º 1
0
            public override void DrawWithFrame(CGRect cellFrame, NSView inView)
            {
                var progress = FloatValue;

                if (float.IsNaN((float)progress))
                {
                    return;
                }

                base.DrawWithFrame(cellFrame, inView);

                string progressText = (int)(progress * 100f) + "%";
                var    str          = new NSMutableAttributedString(progressText, NSDictionary.FromObjectAndKey(ForegroundColor.ToNSUI(), NSAttributedString.ForegroundColorAttributeName));
                var    range        = new NSRange(0, str.Length);

                if (Font != null)
                {
                    str.AddAttributes(NSDictionary.FromObjectAndKey(Font, NSAttributedString.FontAttributeName), range);
                }
                var size = FontExtensions.MeasureString(str, cellFrame.Size.ToEto());
                var rect = cellFrame.ToEto();

                rect.Offset((rect.Size - size) / 2);

                str.DrawString(rect.ToNS());
            }
Ejemplo n.º 2
0
        public SizeF MeasureString(Font font, string text)
        {
            StartDrawing();
            var size = FontExtensions.MeasureString(text, font);

            EndDrawing();
            return(size);
        }
Ejemplo n.º 3
0
            public override void DrawWithFrame(CGRect cellFrame, NSView inView)
            {
                if (DrawsBackground && BackgroundColor != null && BackgroundColor.AlphaComponent > 0)
                {
                    BackgroundColor.Set();
                    NSGraphics.RectFill(cellFrame);
                }

                base.DrawWithFrame(cellFrame, inView);

                var progress = FloatValue;

                if (float.IsNaN((float)progress))
                {
                    return;
                }

                string progressText = (int)(progress * 100f) + "%";
                var    str          = new NSMutableAttributedString(progressText, NSDictionary.FromObjectAndKey(TextColor, NSStringAttributeKey.ForegroundColor));
                var    range        = new NSRange(0, str.Length);

                if (Font != null)
                {
                    str.AddAttributes(NSDictionary.FromObjectAndKey(Font, NSStringAttributeKey.Font), range);
                }
                var size   = FontExtensions.MeasureString(str, cellFrame.Size.ToEto());
                var rect   = cellFrame.ToEto();
                var offset = (rect.Size - size) / 2;

                if (!NSGraphicsContext.CurrentContext.IsFlipped)
                {
                    offset.Height = -offset.Height;
                }
                rect.Offset(offset);

                str.DrawString(rect.ToNS());
            }