Example #1
0
        private void DrawText(string t, nfloat x, nfloat y, nfloat fontSize, CGContext gctx, int alignement, UIColor color, nfloat width, int position = PosCenter)
        {
            gctx.SaveState();
            UIGraphics.PushContext(gctx);
            gctx.SetFillColor(color.CGColor);

            var tfont = UIFont.FromName(FontName, fontSize);

            var nsstr = new NSString(t);
            var sz    = nsstr.StringSize(tfont, width, UILineBreakMode.WordWrap);

            while ((int)(sz.Width - width) == 0)
            {
                var temp = sz.Height;
                sz = nsstr.StringSize(tfont, new CGSize(width, sz.Height * 2.5f), UILineBreakMode.WordWrap);
                if (temp == sz.Height)
                {
                    break;
                }
            }
            var mitad = sz.Height / 2;

            switch (position)
            {
            case PosTop:
                mitad = 0;
                break;

            case PosCenter:
                mitad = sz.Height / 2;
                break;

            case PosBottom:
                mitad = sz.Height;
                break;
            }
            CGRect rect;

            switch (alignement)
            {
            case TextCenter:
                rect = new CGRect(x - sz.Width / 2, y - mitad, sz.Width, sz.Height * 2.5f);
                nsstr.DrawString(rect, tfont, UILineBreakMode.WordWrap, UITextAlignment.Center);
                break;

            case TextLeft:
                rect = new CGRect(x, y - mitad, sz.Width, sz.Height);
                nsstr.DrawString(rect, tfont, UILineBreakMode.WordWrap, UITextAlignment.Left);
                break;

            case TextRight:
                rect = new CGRect(x - sz.Width, y - mitad, sz.Width, sz.Height);
                nsstr.DrawString(rect, tfont, UILineBreakMode.WordWrap, UITextAlignment.Right);
                break;
            }

            UIGraphics.PopContext();
            gctx.RestoreState();
        }
Example #2
0
        public void Init(Recipe recipe, int step)
        {
            if (recipe == null)
            {
                throw new ArgumentNullException("recipe");
            }

            if (step < 0 || step >= recipe.PreparationSteps.Length)
            {
                throw new ArgumentException("step");
            }


            var ns       = new NSString(recipe.PreparationSteps [step]);
            var stepSize = ns.StringSize(UIFont.SystemFontOfSize(14), new CGSize(220, 1000));

            StepLabel.Text  = recipe.PreparationSteps [step];
            StepLabel.Lines = 0;

            var stepFrame = StepLabel.Frame;

            stepFrame.Height = stepSize.Height;
            StepLabel.Frame  = stepFrame;

            step++;
            CountLabel.Text  = "Step " + step.ToString();
            BulletLabel.Text = step.ToString();
        }
Example #3
0
        nfloat HeightForRow(UITableView tableView, NSIndexPath indexPath)
        {
            var ns       = new NSString(recipe.PreparationSteps[indexPath.Row]);
            var stepSize = ns.StringSize(UIFont.SystemFontOfSize(14), new CGSize(220, 1000));

            return(50 + stepSize.Height);
        }
        public override void Draw(RectangleF rect)
        {
            base.Draw (rect);
            var ctx = UIGraphics.GetCurrentContext();

            var center = new PointF(Bounds.X + Bounds.Width / 2.0f, Bounds.Y + Bounds.Height / 2.0f);

            var maxRadius = distance(Bounds.Width, Bounds.Height) / 2.0f;

            ctx.SetLineWidth(10);
            CircleColor.SetStroke();

            for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20.0f) {
                ctx.AddArc(center.X, center.Y, currentRadius, 0.0f, (float)Math.PI * 2.0f, true);
                ctx.StrokePath();
            }

            var text = new NSString("You are getting sleepy.");
            var font = UIFont.BoldSystemFontOfSize(28.0f);
            var textSize = text.StringSize(font);

            UIColor.Black.SetFill();

            var offset = new SizeF(4.0f, 3.0f);
            ctx.SetShadowWithColor(offset, 2.0f, UIColor.DarkGray.CGColor);

            text.DrawString(new PointF(center.X - textSize.Width / 2.0f, center.Y - textSize.Height / 2.0f), font);
        }
Example #5
0
        public void DrawText(Font font, SolidBrush brush, float x, float y, string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            StartDrawing();
#if OSX
            var nsfont = FontHandler.GetControl(font);
            var str    = new NSString(text);
            var dic    = new NSMutableDictionary();
            dic.Add(NSAttributedString.ForegroundColorAttributeName, brush.Color.ToNS());
            dic.Add(NSAttributedString.FontAttributeName, nsfont);
            //context.SetShouldAntialias(true);
            if (!Flipped)
            {
                var size = str.StringSize(dic);
                Control.ConcatCTM(new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight));
                y = ViewHeight - y - size.Height;
            }
            str.DrawString(TranslateView(new SD.PointF(x, y)), dic);
            //context.SetShouldAntialias(antialias);
#elif IOS
            var uifont = font.ToUI();
            var str    = new NSString(text);
            var size   = str.StringSize(uifont);
            //context.SetShouldAntialias(true);
            Control.SetFillColor(brush.Color.ToCGColor());
            str.DrawString(TranslateView(new SD.PointF(x, y), elementHeight: size.Height), uifont);
#endif

            EndDrawing();
        }
Example #6
0
        public override void Draw(CGRect rect)
        {
            var context = UIGraphics.GetCurrentContext();

            this.DrawRoundedRect(context, rect);

            if (!string.IsNullOrEmpty(_text))
            {
                _textColor.SetColor();
                var sizeOfFont = 13.5f * _scaleFactor;
                if (_text.Length < 2)
                {
                    sizeOfFont += sizeOfFont * 0.20f;
                }
                var font     = UIFont.BoldSystemFontOfSize(sizeOfFont);
                var text     = new NSString(this._text);
                var textSize = text.StringSize(font);
                var textPos  = new CGPoint(rect.Width / 2 - textSize.Width / 2, rect.Height / 2 - textSize.Height / 2);
                if (_text.Length < 2)
                {
                    textPos.X += 0.5f;
                }
                text.DrawString(textPos, font);
            }
        }
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            if (_styledPicker.ComponentFixedTextItems == null)
            {
                return;
            }

            nfloat accumulatedWidth = 0;
            var    ms = new CoreGraphics.CGSize(500, 500);

            for (int i = 0; i < _styledPicker.ComponentFixedTextItems.Count; i++)
            {
                CoreGraphics.CGSize sizeMax = new CoreGraphics.CGSize(0, 0);
                for (int j = 0; j < _styledPicker.ItemsSource[i].Count; j++)
                {
                    NSString text = new NSString(_styledPicker.ItemsSource[i][j]);
                    var      size = text.StringSize(_styledPicker.CustomFont.ToUIFont(), ms, UILineBreakMode.WordWrap);
                    if (size.Width > sizeMax.Width)
                    {
                        sizeMax = size;
                    }
                }
                NSString fixedText     = new NSString(_styledPicker.ComponentFixedTextItems[i]);
                var      fixedTextSize = fixedText.StringSize(_styledPicker.CustomFont.ToUIFont(), ms, UILineBreakMode.WordWrap);
                var      label         = new UILabel();
                label.Frame          = new CoreGraphics.CGRect(accumulatedWidth + Control.RowSizeForComponent(i).Width / 2 + sizeMax.Width / 2 + 30, Control.Frame.Size.Height / 2 - fixedTextSize.Height / 2, fixedTextSize.Width + 10, fixedTextSize.Height);
                accumulatedWidth    += Control.RowSizeForComponent(i).Width + 5;
                label.AttributedText = _styledPicker.CustomFont.BuildAttributedString(_styledPicker.ComponentFixedTextItems[i], label.TextAlignment);
                Control.AddSubview(label);
            }
        }
Example #8
0
        public HistoryBar(CGRect parentFrame, EventHandler onSettingsPressed) : base()
        {
            Layer.AnchorPoint = CGPoint.Empty;


            // setup the left label
            NSString leftLabel = new NSString("");

            SettingsButton      = UIButton.FromType(UIButtonType.System);
            SettingsButton.Font = Rock.Mobile.PlatformSpecific.iOS.Graphics.FontManager.GetFont(Settings.General_IconFont, 32);
            SettingsButton.SetTitle(leftLabel.ToString( ), UIControlState.Normal);
            SettingsButton.SetTitleColor(Theme.GetColor(Config.Instance.VisualSettings.FooterTextColor), UIControlState.Normal);
            SettingsButton.TouchUpInside += onSettingsPressed;

            CGSize labelSize = leftLabel.StringSize(SettingsButton.Font);

            SettingsButton.Bounds = new CGRect(0, 0, labelSize.Width, labelSize.Height);

            // create the list that will store our items
            HistoryList = new List <HistoryItem>();

            // even tho there's nothing, update it so we have our label.
            UpdateItems( );

            TintColor   = UIColor.Clear;
            Translucent = false;

            BarTintColor  = Theme.GetColor(Config.Instance.VisualSettings.FooterBGColor);
            Layer.Opacity = Settings.StatusBar_Opacity;

            Bounds = new CGRect(0, 0, parentFrame.Width, Settings.StatusBar_Height);
        }
Example #9
0
        private void DrawMark(CGContext canvas, nfloat startY, nfloat restY, nfloat startX, nfloat restX)
        {
            nfloat pixelPerTicks = restX / (days * TimeSpan.TicksPerDay);
            nfloat realValue     = (float)((weigths[selected].Value - minWeight) / (maxWeight - minWeight) * restY);
            var    pos           = startX + (weigths[selected].Date.Ticks - initDate.Ticks) * pixelPerTicks;
            String valor         = weigths[selected].Value.ToString("0.#");
            String unidades      = weigths[selected].Unit;
            var    tfont         = UIFont.FromName(FontName, 12);
            var    nsstr         = new NSString(valor);
            var    sz            = nsstr.StringSize(tfont, Frame.Width, UILineBreakMode.WordWrap);

            tfont = UIFont.FromName(FontName, 10);
            nsstr = new NSString(unidades);
            var    sz2  = nsstr.StringSize(tfont, Frame.Width, UILineBreakMode.WordWrap);
            String date = " - " + weigths[selected].Date.ToString("dd/MM/yy");

            tfont = UIFont.FromName(FontName, 10);
            nsstr = new NSString(date);
            var    sz3   = nsstr.StringSize(tfont, Frame.Width, UILineBreakMode.WordWrap);
            nfloat width = sz.Width + sz2.Width + sz3.Width;

            if (pos - width / 2 < startX)
            {
                pos = 0 + width / 2 + 3;
            }
            if (pos + width / 2 > startX + restX)
            {
                pos = startX + restX - width / 2 - 3;
            }
            DrawAxis(canvas, pos - width / 2 - 3, width + 6, startY + restY - realValue - 10, startY + restY - realValue - 10 - sz.Height - 6, UIColor.Red);
            DrawText(valor, pos - width / 2, startY + restY - realValue - 13, 12, canvas, TextLeft, UIColor.White, sz.Width, PosBottom);
            DrawText(unidades, pos - width / 2 + sz.Width, startY + restY - realValue - 13, 10, canvas, TextLeft, UIColor.White, sz2.Width, PosBottom);
            DrawText(date, pos - width / 2 + sz.Width + sz2.Width, startY + restY - realValue - 13, 10, canvas, TextLeft, UIColor.White, sz3.Width, PosBottom);

            /*nfloat maxWidth = width;
             * if (sz3.Width > width)
             *  maxWidth = sz3.Width;
             * if (pos - maxWidth / 2 < startX)
             *  pos = 0+maxWidth/2+3;
             * if (pos + maxWidth / 2 > startX+restX)
             *  pos = startX+restX- maxWidth / 2-3;
             * DrawAxis(canvas, pos-maxWidth/2-3, maxWidth+6, startY+ restY - realValue - 10, startY+restY - realValue - 10-sz.Height-sz3.Height-6, UIColor.Red);
             * DrawText(valor,pos-width/2,startY+restY - realValue-13-sz3.Height,12,canvas,TextLeft,UIColor.White,width,PosBottom);
             * DrawText(unidades, pos + width / 2, startY+restY - realValue - 13-sz3.Height, 10, canvas, TextRight, UIColor.White, width, PosBottom);
             * DrawText(date, pos , startY + restY - realValue - 13, 10, canvas, TextCenter, UIColor.White, sz3.Width, PosBottom);*/
            pos = startX + (weigths[selected].Date.Ticks - initDate.Ticks) * pixelPerTicks;//Pintar triangulo en su sitio
            canvas.SaveState();
            UIColor.Red.SetFill();
            UIColor.Red.SetStroke();
            canvas.SetLineWidth(0);
            var path = new CGPath();

            path.MoveToPoint(pos - 4f, startY + restY - realValue - 10f);
            path.AddLineToPoint(pos + 4f, startY + restY - realValue - 10f);
            path.AddLineToPoint(pos, startY + restY - realValue - 6);
            path.CloseSubpath();
            canvas.AddPath(path);
            canvas.DrawPath(CGPathDrawingMode.Fill);
            canvas.RestoreState();
        }
        internal void UpdateDetailLabelWithString(string newString, bool animated, Action completion)
        {
            var length            = animated ? AnimationLength : 0.0f;
            var labelWidth        = 15;      //padding
            var attribs           = new UIStringAttributes();
            var nsVersionOfString = new NSString(newString);

            if (!IsLessThanIOS6)
            {
                attribs.Font = DetailLabelFont;
                labelWidth  += (int)nsVersionOfString.GetSizeUsingAttributes(attribs).Width;
            }
            else
            {
                labelWidth += (int)nsVersionOfString.StringSize(DetailLabelFont).Width;
            }

            CATransition animation = new CATransition();

            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            animation.Type           = CATransition.TransitionFade;
            animation.Duration       = length;
            DetailLabel.Layer.AddAnimation(animation, "kCATransitionFade");
            DetailLabel.Text = newString;
            var pinSelectionTop = EnterPasscodeLabel.Frame.Y + EnterPasscodeLabel.Frame.Size.Height + 17.5;

            DetailLabel.Frame = new RectangleF((CorrectWidth / 2) - 100,
                                               (float)pinSelectionTop + 30f, 200, 23);
        }
Example #11
0
        public static float ContentSize(string text, float width, UIFont font)
        {
            var stringToSize = new NSString (text);
            var size = stringToSize.StringSize (font, new SizeF (width, float.MaxValue), UILineBreakMode.WordWrap);

            return size.Height;
        }
Example #12
0
        public override void LayoutSubviews()
        {
            if (_label == null)
            {
                _label = new UILabel(new CGRect(Padding, Padding / 2, Width - Padding * 2, Height - Padding));
                _label.AdjustsFontSizeToFitWidth = true;
                _label.LineBreakMode             = UILineBreakMode.TailTruncation;
                _label.Font = UIFont.SystemFontOfSize(16);

                var desc = new NSString(Message);
                var size = desc.StringSize(_label.Font);
                _label.Lines = size.Width > _label.Frame.Width ? 2 : 1;

                if (MessageType == MessageType.Error)
                {
                    _label.TextColor = UIColor.FromRGB(245, 109, 79);
                }
                else
                {
                    _label.TextColor = UIColor.FromRGB(255, 255, 255);
                }

                Add(_label);
            }

            _label.Text = Message;

            base.LayoutSubviews();
        }
Example #13
0
        static internal SizeF GetSizeForText(UIView tv, string text, UIFont font)
        {
            NSString s    = new NSString(text);
            var      size = s.StringSize(font, new CGSize(tv.Bounds.Width * .7f - 10 - 22, tv.Bounds.Height), UILineBreakMode.WordWrap);

            return(new SizeF((float)size.Width, (float)size.Height));
        }
        public HistoryBar( CGRect parentFrame, EventHandler onSettingsPressed )
            : base()
        {
            Layer.AnchorPoint = CGPoint.Empty;

            // setup the left label
            NSString leftLabel = new NSString( "" );

            SettingsButton = UIButton.FromType( UIButtonType.System );
            SettingsButton.Font = Rock.Mobile.PlatformSpecific.iOS.Graphics.FontManager.GetFont( Settings.General_IconFont, 32 );
            SettingsButton.SetTitle( leftLabel.ToString( ), UIControlState.Normal );
            SettingsButton.SetTitleColor( Theme.GetColor( Config.Instance.VisualSettings.FooterTextColor ), UIControlState.Normal );
            SettingsButton.TouchUpInside += onSettingsPressed;

            CGSize labelSize = leftLabel.StringSize( SettingsButton.Font );
            SettingsButton.Bounds = new CGRect( 0, 0, labelSize.Width, labelSize.Height );

            // create the list that will store our items
            HistoryList = new List<HistoryItem>();

            // even tho there's nothing, update it so we have our label.
            UpdateItems( );

            TintColor = UIColor.Clear;
            Translucent = false;

            BarTintColor = Theme.GetColor( Config.Instance.VisualSettings.FooterBGColor );
            Layer.Opacity = Settings.StatusBar_Opacity;

            Bounds = new CGRect( 0, 0, parentFrame.Width, Settings.StatusBar_Height );
        }
        private static float CellHeight(Tweet tweet)
        {
            var text       = new NSString(tweet.Title);
            var restrictTo = new SizeF(AppDelegate.IsPad ? BodyWidthIpad : BodyWidthIphone, 999999);

            return(text.StringSize(MainBodyFont, restrictTo).Height + MagicAdjustment);
        }
Example #16
0
        public static float ContentSize(string text, float width, UIFont font)
        {
            var stringToSize = new NSString(text);
            var size         = stringToSize.StringSize(font, new SizeF(width, float.MaxValue), UILineBreakMode.WordWrap);

            return(size.Height);
        }
Example #17
0
            public float GetHeight(UITableView tableView, NSIndexPath indexPath)
            {
                var str    = new NSString(Value ?? string.Empty);
                var height = (int)str.StringSize(CustomInputCell.InputFont, new SizeF(tableView.Bounds.Width - 24f, 10000), UILineBreakMode.WordWrap).Height + 60f;

                return(height > 60 ? height : 60);
            }
        public SizeF GetStringSize(string value, string fontName, float fontSize)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(new SizeF());
            }

            var    finalFontName = fontName ?? SystemFontName;
            var    nsString      = new NSString(value);
            UIFont uiFont;

            if (finalFontName == SystemFontName)
            {
                uiFont = UIFont.SystemFontOfSize(fontSize);
            }
            else if (finalFontName == BoldSystemFontName)
            {
                uiFont = UIFont.BoldSystemFontOfSize(fontSize);
            }
            else
            {
                uiFont = UIFont.FromName(finalFontName, fontSize);
            }

            var size = nsString.StringSize(uiFont);

            uiFont.Dispose();
            return(new SizeF((float)size.Width, (float)size.Height));
        }
        public override void DrawFooterForPage(nint index, CGRect footerRect)
        {
            base.DrawFooterForPage(index, footerRect);

            UIFont footerFont = UIFont.SystemFontOfSize(FOOTER_FONT_SIZE);

            //Draw Print date
            NSString dateStr  = new NSString(PAGE_FOOTER_DATE_STR + DateTime.Now.ToString("dd MMM yyyy "));
            CGSize   dateSize = dateStr.StringSize(footerFont);
            CGPoint  point    = new CGPoint(CONTENT_LEFT_RIGHT_MARGIN, footerRect.GetMaxY() - dateSize.Height - FOOTER_BOTTOM_PADDING);

            dateStr.DrawString(point, footerFont);

            //Draw "© 2015 LexisNexis" in the horizontal center of footer
            NSString copyrightStr  = new NSString(PAGE_FOOTER_COPYRIGHT);
            CGSize   copyrightSize = copyrightStr.StringSize(footerFont);

            point = new CGPoint(footerRect.GetMaxX() / 2 - copyrightSize.Width / 2, footerRect.GetMaxY() - copyrightSize.Height - FOOTER_BOTTOM_PADDING);
            copyrightStr.DrawString(point, footerFont);

            //Draw page num in the footer
            NSString pageNumStr  = new NSString(PAGE_FOOTER_PAGE_INFO + (index + 1));
            CGSize   pageNumSize = pageNumStr.StringSize(footerFont);

            point = new CGPoint(footerRect.GetMaxX() - pageNumSize.Width - CONTENT_LEFT_RIGHT_MARGIN, footerRect.GetMaxY() - pageNumSize.Height - FOOTER_BOTTOM_PADDING);
            pageNumStr.DrawString(point, footerFont);
        }
Example #20
0
        public static SizeF GetHeight(UIView tv, string text1, string text2)
        {
            SizeF textSize1, textSize2;

            if (text1 == null)
            {
                text1 = "";
            }
            using (NSString nssSomeString = new NSString(text1))
            {
                textSize1 = (System.Drawing.SizeF)nssSomeString.StringSize(font, new SizeF((float)tv.Bounds.Width * .7f - 10 - 22, 99999), UILineBreakMode.WordWrap);
                //Console.WriteLine(textSize);
            }
            if (text2 == null)
            {
                text2 = "";
            }
            using (NSString nssSomeString = new NSString(text2))
            {
                textSize2 = (System.Drawing.SizeF)nssSomeString.StringSize(fontDateStamp, new SizeF((float)tv.Bounds.Width * .7f - 10 - 22, 99999), UILineBreakMode.WordWrap);
                //Console.WriteLine(textSize);
            }

            ////  return textSize;

            //var size1 = GetSizeForText(tv, label.Text);
            //var size2 = GetSizeForText(tv, label2.Text);
            SizeF SmallPadding = new SizeF(0, 5);

            return(textSize1 + textSize2 + BubblePadding + SmallPadding);
        }
Example #21
0
        private Line[] SplitWordsByLines(SizeF size)
        {
            List <Line> lines       = new List <Line>();
            var         currentLine = new List <Word>();

            var remainingLineWidth = size.Width;
            var ellipsisWidth      = 0;

            if (maxLines > 0)
            {
                using (var s = new NSString("..."))
                {
                    var ellipsisSize = s.StringSize(Font);
                    ellipsisWidth = (int)ellipsisSize.Width;
                }
            }
            for (var i = 0; i < words.Length; i++)
            {
                var    word                 = words[i];
                var    nextWord             = i < words.Length - 1 ? (Word?)words[i + 1] : null;
                var    isAdjacentToNextWord = IsAdjacentToNextWord(word, nextWord);
                var    wordSpacing          = isAdjacentToNextWord ? 0 : this.wordSpacing;
                Action createLine           = () => lines.Add(new Line((int)(size.Width - remainingLineWidth), currentLine.ToArray()));

                if (maxLines > 0 && currentLine.Any() && lines.Count + 1 >= maxLines && remainingLineWidth - (word.Width + ellipsisWidth) < 0)
                {
                    // We've reached the end.  Go ahead and add the ellipsis word
                    remainingLineWidth -= ellipsisWidth;
                    currentLine.Add(new Word(word.Index, "...", Font, TextColor, TextDecoration, WordStyle.Suffix, null));
                    createLine();
                    break;
                }
                if (word.Width < remainingLineWidth || !currentLine.Any())
                {
                    currentLine.Add(word);
                    remainingLineWidth -= word.Width + wordSpacing;

                    if (i == words.Length - 1)
                    {
                        createLine();
                    }
                }
                else
                {
                    createLine();
                    currentLine        = new List <Word>();
                    remainingLineWidth = size.Width;

                    currentLine.Add(word);
                    remainingLineWidth -= word.Width + wordSpacing;

                    if (i == words.Length - 1)
                    {
                        createLine();
                    }
                }
            }
            return(lines.ToArray());
        }
Example #22
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            var  mainText   = new NSString(node.ToString());
            var  bounds     = this.Bounds.ToRectangleF();
            bool isSelected = node.IsSelected;

            var mainTextAttrs = new NSMutableDictionary();
            var mainTextPara  = new NSMutableParagraphStyle();

            mainTextPara.LineBreakMode = NSLineBreakMode.TruncatingTail;
            mainTextPara.TighteningFactorForTruncation = 0;
            mainTextAttrs.Add(NSStringAttributeKey.ParagraphStyle, mainTextPara);
            if (isSelected)
            {
                mainTextAttrs.Add(NSStringAttributeKey.ForegroundColor, NSColor.SelectedMenuItemText);
            }
            else
            {
                mainTextAttrs.Add(NSStringAttributeKey.ForegroundColor, NSColor.Text);
            }

            var   mainTextSz = mainText.StringSize(mainTextAttrs).ToSizeF();
            float nodeTextAndPrimaryPropHorzSpacing = 8;
            float spaceAvailableForDefaultPropValue =
                bounds.Width - mainTextSz.Width - nodeTextAndPrimaryPropHorzSpacing;

            var paintInfo = owner.ViewModel.PaintNode(node, spaceAvailableForDefaultPropValue > 30);

            if (paintInfo.PrimaryPropValue != null)
            {
                var r = new RectangleF(
                    bounds.Right - spaceAvailableForDefaultPropValue,
                    bounds.Y,
                    spaceAvailableForDefaultPropValue,
                    bounds.Height);

                // todo: move dict to a static field
                var dict = new NSMutableDictionary();
                var para = new NSMutableParagraphStyle();
                para.Alignment     = NSTextAlignment.Right;
                para.LineBreakMode = NSLineBreakMode.TruncatingTail;
                para.TighteningFactorForTruncation = 0;
                dict.Add(NSStringAttributeKey.ParagraphStyle, para);
                if (isSelected)
                {
                    dict.Add(NSStringAttributeKey.ForegroundColor, NSColor.FromDeviceRgba(0.9f, 0.9f, 0.9f, 1f));
                }
                else
                {
                    dict.Add(NSStringAttributeKey.ForegroundColor, NSColor.Gray);
                }

                new NSString(paintInfo.PrimaryPropValue).DrawString(r.ToCGRect(), dict);
            }

            mainText.DrawString(bounds.ToCGRect(), mainTextAttrs);
        }
Example #23
0
        public override float GetPreferredSize(object value, System.Drawing.SizeF cellSize, NSCell cell)
        {
            var font  = cell.Font ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize);
            var str   = new NSString(Convert.ToString(value));
            var attrs = NSDictionary.FromObjectAndKey(font, NSAttributedString.FontAttributeName);

            return(str.StringSize(attrs).Width + 8);             // for border
        }
Example #24
0
        public void SetText(NSString text, UIButton backButton)
        {
            var textSize = text.StringSize(backButton.TitleLabel.Font);
            var delta    = (textSize.Width + (backButtonCapWidth * 1.5)) > MAX_BACK_BUTTON_WIDTH ? MAX_BACK_BUTTON_WIDTH : (textSize.Width + (backButtonCapWidth * 1.5));

            backButton.Frame = new RectangleF(backButton.Frame.X, backButton.Frame.Y, (float)delta, backButton.Frame.Size.Height);
            backButton.SetTitle(text, UIControlState.Normal);
        }
Example #25
0
        public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
        {
            var content = Verses[Keys[indexPath.Section]][indexPath.Row].Content;
            var text    = new NSString(content);
            var size    = text.StringSize(FontConstants.SourceSansProRegular(13), new SizeF(278, 70));

            return(size.Height + 40);
        }
Example #26
0
        public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
        {
            var content = data[indexPath.Row].Content;
            var text = new NSString (content);
            var size = text.StringSize (FontConstants.SourceSansProRegular (15), new SizeF (278, 70));

            return size.Height + 40;
        }
        public float GetHeight(UITableView tableView, NSIndexPath indexPath)
        {
            var str    = new NSString(Value ?? string.Empty);
            var height = (int)str.StringSize(CustomInputCell.InputFont, new SizeF(tableView.Bounds.Width, 10000)).Height + 40f;

            Console.WriteLine("Calculated height: " + height);
            return(height > 200 ? height : 200);
        }
		private float TextHeight(RectangleF bounds)
		{
			SizeF size;
			using(NSString str = new NSString(this.Caption))
			{
				size = str.StringSize(_CaptionFont, new SizeF(bounds.Width - 20, 1000), UILineBreakMode.WordWrap);
			}			
			return size.Height;
		}
Example #29
0
        private void DrawStringOutline(string text, NSColor color, RectangleF rect, int align)
        {
            NSString nsString = new NSString(text);

            int halign = align % 3;
            int valign = align / 3;


            var objectsText    = new object[] { m_font, color };
            var keysText       = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
            var attributesText = NSDictionary.FromObjectsAndKeys(objectsText, keysText);

            var objectsOutline    = new object[] { m_font, NSColor.White };
            var keysOutline       = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
            var attributesOutline = NSDictionary.FromObjectsAndKeys(objectsOutline, keysOutline);


            SizeF size = nsString.StringSize(attributesText);

            if (halign == 0)
            {
            }
            else if (halign == 1)
            {
                rect.X = (rect.Left + rect.Right) / 2 - size.Width / 2;
            }
            else if (halign == 2)
            {
                rect.X = rect.Right - size.Width;
            }
            rect.Width = size.Width;

            if (valign == 0)
            {
            }
            else if (valign == 1)
            {
                rect.Y = (rect.Top + rect.Bottom) / 2 - size.Height / 2;
            }
            else if (valign == 2)
            {
                rect.Y = rect.Bottom - size.Height;
            }
            rect.Height = size.Height;

            NSColor.Black.Set();
            for (int ox = -1; ox <= 1; ox++)
            {
                for (int oy = -1; oy <= 1; oy++)
                {
                    RectangleF rectString = rect;
                    rectString.Offset(new PointF(ox, oy));
                    nsString.DrawString(Invert(rectString), attributesOutline);
                }
            }
            nsString.DrawString(Invert(rect), attributesText);
        }
Example #30
0
        public SizeF MeasureString(Font font, string text)
        {
            UIGraphics.PushContext(this.context);
            var str  = new NSString(text);
            var size = str.StringSize(font.ControlObject as UIFont);

            UIGraphics.PopContext();
            return(new SizeF(size.Width, size.Height));
        }
 private float TextHeight(RectangleF bounds)
 {
     SizeF size;
     using (NSString str = new NSString (this.Subject))
     {
         size = str.StringSize (subjectFont, new SizeF (bounds.Width - 20, 1000), UILineBreakMode.WordWrap);
     }
     return size.Height;
 }
        static internal SizeF GetSizeForText(UIView tv, string text)
        {
            //return tv.StringSize(text, font, new SizeF(tv.Bounds.Width * .7f - 10 - 22, 99999));

            NSString s    = new NSString(text);
            var      size = s.StringSize(font, new CGSize(tv.Bounds.Width * .7f - 10 - 22, 99999));

            return(new SizeF((float)size.Width, (float)size.Height));
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // container view must have a black background so that the ticks
            // before the task displays don't cause a flash
            View.BackgroundColor   = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.BackgroundColor);
            View.Layer.AnchorPoint = CGPoint.Empty;
            View.Layer.Position    = CGPoint.Empty;

            // First setup the SpringboardReveal button, which rests in the upper left
            // of the MainNavigationUI. (We must do it here because the ContainerViewController's
            // NavBar is the active one.)
            NSString buttonLabel = new NSString(PrivatePrimaryNavBarConfig.RevealButton_Text);

            SpringboardRevealButton      = new UIButton(UIButtonType.System);
            SpringboardRevealButton.Font = Rock.Mobile.PlatformSpecific.iOS.Graphics.FontManager.GetFont(PrivateControlStylingConfig.Icon_Font_Secondary, PrivatePrimaryNavBarConfig.RevealButton_Size);
            SpringboardRevealButton.SetTitle(buttonLabel.ToString( ), UIControlState.Normal);

            // determine its dimensions
            CGSize buttonSize = buttonLabel.StringSize(SpringboardRevealButton.Font);

            SpringboardRevealButton.Bounds = new CGRect(0, 0, buttonSize.Width, buttonSize.Height);

            // set its callback
            SpringboardRevealButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                (ParentViewController as MainUINavigationController).SpringboardRevealButtonTouchUp( );
            };
            this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(SpringboardRevealButton), false);
            //

            // set the title image for the bar if there's no safe area defined. (A safe area is like, say, the notch for iPhone X)
            nfloat safeAreaTopInset = 0;

            // Make sure they're on iOS 11 before checking for insets. This is only needed for iPhone X anyways, which shipped with iOS 11.
            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                safeAreaTopInset = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Top;
            }

            if (safeAreaTopInset == 0)
            {
                string  imagePath  = NSBundle.MainBundle.BundlePath + "/" + PrivatePrimaryNavBarConfig.LogoFile_iOS;
                UIImage titleImage = new UIImage(imagePath);
                this.NavigationItem.TitleView = new UIImageView(titleImage);
                this.NavigationItem.TitleView.SizeToFit( );

                nfloat delta = (NavigationController.NavigationBar.Bounds.Height - titleImage.Size.Height) / 2;
                NavigationController.NavigationBar.SetTitleVerticalPositionAdjustment(-delta, UIBarMetrics.Default);
            }

            // Now create the sub-navigation, which includes
            // the NavToolbar used to let the user navigate
            CreateSubNavigationController( );
        }
Example #34
0
        protected virtual void UpdateFont()
        {
            if (initialSize == CGSize.Empty)
            {
                NSString testString = new NSString("Tj");
                initialSize = testString.StringSize(Control.Font);
            }

            Control.Font = Element.ToUIFont();
        }
Example #35
0
        public static float MonoStringLength(this string s, UIFont font)
        {
            if (string.IsNullOrEmpty(s))
                return 0f;

            using (var str = new NSString (s))
            {
                return str.StringSize(font).Width;
            }
        }
Example #36
0
        public static float MonoStringHeight(this string s, UIFont font, float maxWidth)
        {
            if (string.IsNullOrEmpty(s))
                return 0f;

            using (var str = new NSString (s))
            {
                return str.StringSize(font, new SizeF(maxWidth, 1000), UILineBreakMode.WordWrap).Height;
            }
        }
Example #37
0
        public static CGSize SizeForText(float width, string text, UIFont font)
        {
            CGSize size;

            using (NSString str = new NSString(text))
            {
                size = str.StringSize(font, width, UILineBreakMode.WordWrap);
            }
            return(size);
        }
Example #38
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews ();

            var text = new NSString (VerseContent.Text);
            var maxSize = new SizeF (278, 70);
            var currentSize = text.StringSize (FontConstants.SourceSansProRegular (15), maxSize);

            VerseReference.Frame = new RectangleF (22, 9, 278, 20);
            VerseContent.Frame = new RectangleF (24, 30, 278, currentSize.Height);
        }
Example #39
0
		public static void SetLabelHeight4Text (this UILabel source, float width)
		{
			float height = 0f;
			using (var nss = new  NSString (source.Text)) {
				height = nss.StringSize (source.Font, new SizeF (width, 1000.0f), 
			                      UILineBreakMode.WordWrap).Height;
			}
			
			source.Lines = 0;
			source.Frame = new RectangleF (source.Frame.X, source.Frame.Y, width, height);
		}
Example #40
0
		public static float GetHeight4Text (this UILabel source, float width)
		{
			if (string.IsNullOrEmpty (source.Text)) {
				return 0;
			}
			using (var nss = new NSString(source.Text)) {
				float height = nss.StringSize (source.Font, new SizeF (width, 1000.0f), 
			                      UILineBreakMode.WordWrap).Height;
				return height;
			}
			
		}
Example #41
0
		static UIImage Render (string value)
		{
			NSString text = new NSString (string.IsNullOrEmpty (value) ? " " : value);
			UIFont font = UIFont.SystemFontOfSize (20);
			SizeF size = text.StringSize (font);
			UIGraphics.BeginImageContextWithOptions (size, false, 0.0f);
			UIColor.Red.SetColor ();
			text.DrawString (new PointF (0, 0), font);
			UIImage image = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();
			
			return image;
		}
		public override void Draw (RectangleF rect)
		{
			base.Draw (rect);
			var st = new NSString(Text);
			var sz = st.StringSize (Font);

			CGContext context = UIGraphics.GetCurrentContext();
			context.SetFillColor (AppDelegate.ColorTextLink.CGColor); 
			context.SetLineWidth(0.5f);
			context.MoveTo(0,sz.Height+2);
			context.AddLineToPoint(sz.Width,sz.Height+2);
			context.StrokePath();  
		}
Example #43
0
        public static float GetCellHeight(RectangleF bounds, Tweet tweet)
        {
            bounds.Height = 999;

            // Keep the same as LayoutSubviews
            bounds.X = 0;
            bounds.Width -= 5;

            using (var nss = new NSString (tweet.Text))
            {
                var dim = nss.StringSize (UIFont.SystemFontOfSize(15), bounds.Size, UILineBreakMode.WordWrap);
                return Math.Max (dim.Height + 5 + + 14 + 2*4, 20);
            }
        }
Example #44
0
		public static float GetCellHeight (RectangleF bounds, string caption)
		{
			bounds.Height = 999;
			
			// Keep the same as LayoutSubviews
			bounds.X = TEXT_LEFT_START;
			bounds.Width -= TEXT_LEFT_START + TEXT_HEIGHT_PADDING;
			if (!string.IsNullOrEmpty (caption)) {
				using (var nss = new NSString (caption)) {
					var dim = nss.StringSize (TextFont, bounds.Size, UILineBreakMode.WordWrap);
					return Math.Max (dim.Height + TEXE_YOFFSET + 2 * TEXT_HEIGHT_PADDING, MIN_HEIGHT);
				}
			}
			return MIN_HEIGHT;
		}
Example #45
0
			public override float GetHeight (UITableView tableView, NSIndexPath indexPath)
			{
				if (string.IsNullOrEmpty (Caption)) {
					return 44.0f;
				} else {
					NSString s = new NSString (this.Caption);

					float height = s.StringSize (
						UIFont.SystemFontOfSize (12.0f), 
						new System.Drawing.SizeF (280.0f, 5000.0f), 
						UILineBreakMode.WordWrap
						).Height;

					return height;
				}
			}
Example #46
0
        public static UIImage ImageFromFont(UIFont font, char character, UIColor fillColor)
        {
            var s = new NSString("" + character);
            var stringSize = s.StringSize(font);
            var maxSize = (nfloat)Math.Max(stringSize.Height, stringSize.Width);
            var size = new CGSize(maxSize, maxSize);

            UIGraphics.BeginImageContextWithOptions(size, false, 0f);
            fillColor.SetFill();

            var drawPoint = new CGPoint((size.Width / 2f) - (stringSize.Width / 2f),
                                (size.Height / 2f) - (stringSize.Height / 2f));
            s.DrawString(drawPoint, font);

            var img = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();
            return img;
        }
Example #47
0
 private void AddTextBlock(string which)
 {
     var text = GetText(which);
     var nsText = new NSString(text);
     var font = UIFont.FromName("Helvetica", 13);
     var size = nsText.StringSize(font, new SizeF(300, 100000), UILineBreakMode.WordWrap);
     var frame = new RectangleF(10, _currentTop, 300, size.Height);
     var view = new UILabel(frame);
     view.BackgroundColor = UIColor.Black;
     view.AutoresizingMask = UIViewAutoresizing.None;
     view.AdjustsFontSizeToFitWidth = false;
     view.TextColor = UIColor.White;
     view.Font = font;
     view.LineBreakMode = UILineBreakMode.WordWrap;
     view.Text = GetText(which);
     view.Lines = 0;
     AddView(view);
 }
Example #48
0
        /// <summary>
        /// Gets the maximum font size that will fit the given string within the desired size area.
        /// </summary>
        /// <returns>The max font size.</returns>
        /// <param name="source">Source.</param>
        /// <param name="font">Font.</param>
        /// <param name="sizeRestriction">Size restriction.</param>
        public static float GetMaxFontSize(this string source, UIFont font, SizeF sizeRestriction)
        {
            // The expected StringSize method doesn't return a useful value for me, so here's a hack.
            // NSString.StringSize(font, 0f, ref maximumFontSize, textWidthRestriction, lineBreakMode);
            // This is only accurate within a 0.1f value.

            float maxFontSize = font.PointSize;
            SizeF latest = SizeF.Empty;
            using (NSString nssDescriptionWithoutHtml = new NSString(source.ToString())) {
                while (latest.Width < sizeRestriction.Width && latest.Height < sizeRestriction.Height) {
                    latest = nssDescriptionWithoutHtml.StringSize(font.WithSize(maxFontSize), sizeRestriction.Width, UILineBreakMode.Clip);
                    if (latest.Width < sizeRestriction.Width && latest.Height < sizeRestriction.Height) {
                        maxFontSize += 0.1f;
                    }
                }
            }
            return maxFontSize;
        }
Example #49
0
		static NSImage Render (string value)
		{
			NSImage image = null;

			NSApplication.SharedApplication.InvokeOnMainThread (() =>
			{
				NSString text = new NSString (string.IsNullOrEmpty (value) ? " " : value);
				NSFont font = NSFont.FromFontName ("Arial", 20);
				var fontDictionary = NSDictionary.FromObjectsAndKeys (new NSObject[] { font, NSColor.Red }, new NSObject[] { NSStringAttributeKey.Font, NSStringAttributeKey.ForegroundColor });
				CGSize size = text.StringSize (fontDictionary);

				image = new NSImage (new CGSize (size));

				image.LockFocus ();
				text.DrawString (new CGPoint (0, 0), fontDictionary);
				image.UnlockFocus ();
			});

			return image;
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // Perform any additional setup after loading the view, typically from a nib.
            RectangleF screenRect = UIScreen.MainScreen.Bounds;
            float screenWidth = screenRect.Size.Width;
            float screenHeight = screenRect.Size.Height;
            UILabel label=new UILabel(new RectangleF(0,0,100,20));
            string s="Hola Mundo";
            NSString nsString=new NSString(s);
            SizeF stringSize=nsString.StringSize(label.Font);
            //label.Text=s;
            UIGraphics.GetCurrentContext();
            //CGContext
            //CGContextGetTextWidthAndHeight
            label=new UILabel(new RectangleF(screenWidth/2-stringSize.Width/2,screenHeight/2-stringSize.Height/2,stringSize.Width,stringSize.Height));
            label.Text=s;
            this.View.AddSubview(label);
        }
Example #51
0
        public Size GetCharData(char c,out  UInt32[] cdata)
        {
            NSString str =new NSString(c.ToString());
            var size=str.StringSize(font);
            UIGraphics.BeginImageContextWithOptions(size,false,1.0f);
            UIGraphics.GetCurrentContext().SetFillColor(1.0f,1.0f,1.0f,1.0f);
            str.DrawString(new System.Drawing.PointF(0,0),font);
            UIImage img =UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();

            //
            int width=(int)size.Width;
            int height=(int)size.Height;
            cdata=new UInt32[width*height];
            var gdata=new byte[width*height*4];
            var colorSpace = CGColorSpace.CreateDeviceRGB();
            var gbmp = new CGBitmapContext(gdata, width, height,
                                       8, width * 4, colorSpace, CGBitmapFlags.PremultipliedLast);
            //gbmp.ClearRect(new RectangleF(0,0,width,height));
            gbmp.DrawImage(new System.Drawing.RectangleF(0,0,width,height),img.CGImage);
            gbmp.Dispose();
            colorSpace.Dispose();
            unsafe
            {
                fixed(byte* srcb = gdata)
                    fixed (UInt32* dest=cdata)
                {
                    UInt32* src=(UInt32*)srcb;
                    for(int y=0;y<height;y++)
                    {
                        for(int x=0;x<width;x++)
                        {
                            dest[y*width+x]=src[y*width+x];
                        }
                    }
                }
            }

            return new Size(width,height);
        }
Example #52
0
        public void Init(Recipe recipe, int step)
        {
            if (recipe == null)
                throw new ArgumentNullException ("recipe");

            if (step < 0 || step >= recipe.PreparationSteps.Length)
                throw new ArgumentException ("step");

            var ns = new NSString (recipe.PreparationSteps [step]);
            var stepSize = ns.StringSize (UIFont.SystemFontOfSize(14), new CGSize (220, 1000));

            StepLabel.Text = recipe.PreparationSteps [step];
            StepLabel.Lines = 0;

            var stepFrame = StepLabel.Frame;
            stepFrame.Height = stepSize.Height;
            StepLabel.Frame = stepFrame;

            step++;
            CountLabel.Text = "Step " + step.ToString ();
            BulletLabel.Text = step.ToString ();
        }
		public override OxySize MeasureText (string text, string fontFamily, double fontSize, double fontWeight)
		{
			//This method needs work not 100% around calculating height.
			if(text == null)
			{
				return OxySize.Empty;
			}

			fontFamily = GetDefaultFont(fontFamily);

			//var currentPosition = gctx.TextPosition;

			gctx.SelectFont(fontFamily, (float)fontSize, CGTextEncoding.MacRoman);

			UIFont tfont = UIFont.FromName (fontFamily,(float)fontSize);
			
			NSString nsstr = new NSString(text);
			SizeF sz = nsstr.StringSize(tfont);

			return new OxySize(sz.Width, fontSize);
		}
		public void DrawTextWithUTF8Fonts (CGContext mBmpContext, string text, float x, float y, string font_family, double text_size)
		{
			/*
			The problem is that CoreGraphics APIs for CGContext do not support rendering UTF8 code, and then ShowTextAtPoint() is limited to the text encoding in MacRoman.
			The fix is to use the UIKit function DrawString() instead.
			 */

			UIGraphics.PushContext (mBmpContext);
			mBmpContext.SetRGBFillColor(1f,1f,1f,1f);

			UIFont tfont = UIFont.FromName (font_family,(float)text_size);

			NSString nsstr = new NSString(text);
			SizeF sz = nsstr.StringSize(tfont);
			RectangleF rect = new RectangleF(x,y,sz.Width,sz.Height);
			nsstr.DrawString( rect, tfont);


			UIGraphics.PopContext ();
		}
		public override void DrawText (ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, HorizontalTextAlign halign, VerticalTextAlign valign, OxySize? maxSize)
		{


			//This method needs work not 100% around vertical alignment.
			if(string.IsNullOrEmpty(text))
			{
				return;
			}

			fontFamily = GetDefaultFont(fontFamily);

			if (fontWeight >= 700)
            {
                //fs = FontStyle.Bold;
            }

			//var textSize = MeasureText(text, fontFamily, fontSize, fontWeight);

			if (maxSize != null)
            {
//                if (size.Width > maxSize.Value.Width)
//                {
//                    size.Width = (float)maxSize.Value.Width;
//                }
//
//                if (size.Height > maxSize.Value.Height)
//                {
//                    size.Height = (float)maxSize.Value.Height;
//                }
            }

			gctx.SaveState();

			gctx.SelectFont(fontFamily, (float)fontSize, CGTextEncoding.MacRoman);
			ToColor(fill).SetFill();

			gctx.SetTextDrawingMode(CGTextDrawingMode.Fill);

			var tfont = UIFont.FromName (fontFamily,(float)fontSize);
			NSString nsstr = new NSString(text);
			SizeF sz = nsstr.StringSize(tfont);

			float y = (float)(p.Y);
			float x = (float)(p.X);

			switch(halign)
			{
			case HorizontalTextAlign.Left:
				x = (float)(p.X);
				break;
			case HorizontalTextAlign.Right:
				x = (float)(p.X - sz.Width);
				break;
			case HorizontalTextAlign.Center:
				x = (float)(p.X - (sz.Width / 2));
				break;
			}

			switch(valign)
			{
			case VerticalTextAlign.Bottom:
				y -= (float)fontSize;
				break;
			case VerticalTextAlign.Top:
//				y += (float)fontSize;
				break;
			case VerticalTextAlign.Middle:
				y -= (float)(fontSize / 2);
				break;
			}


			RectangleF rect = new RectangleF(x,y,sz.Width,sz.Height);
			nsstr.DrawString( rect, tfont);

			gctx.RestoreState();
			//Console.WriteLine("X:{0:###} Y:{1:###} HA:{2}:{3:###} VA:{4}:{5:###} TW:{6:###} - {7}", p.X, p.Y, halign, x, valign, y, textSize.Width, text);
		}
Example #56
0
        public override void Draw(RectangleF rect)
        {
            countString = BadgeNumber;
            var ns = new NSString(countString);
            numberSize = ns.StringSize (font);

            Width = Convert.ToInt32(numberSize.Width + 16);

            var bounds = new RectangleF(0, 0, numberSize.Width + 16, 18);

            var context = UIGraphics.GetCurrentContext();

            float radius = bounds.Size.Height / 2.0f;

            context.SaveState();

            if (Parent.Highlighted || Parent.Selected)
            {
                UIColor col;

                if (BadgeColorHighlighted != null)
                    col = BadgeColorHighlighted;
                else
                    col = UIColor.FromRGBA (1.0f, 1.0f, 1.0f, 1.000f);

                context.SetFillColorWithColor (col.CGColor);
            }
            else
            {
                UIColor col;
                if (BadgeColor != null)
                    col = BadgeColor;
                else
                    col = UIColor.FromRGBA(0.530f, 0.600f, 0.738f, 1.000f);

                context.SetFillColorWithColor (col.CGColor);
            }

            context.BeginPath();
            float a = Convert.ToSingle(Math.PI / 2f);
            float b = Convert.ToSingle(3f * Math.PI / 2f);
            context.AddArc(radius, radius, radius, a, b, false);
            context.AddArc(bounds.Size.Width - radius, radius, radius, b, a, false);
            context.ClosePath();
            context.FillPath();
            context.RestoreState();

            bounds.X = (bounds.Size.Width - numberSize.Width) / 2 + 0.5f;

            context.SetBlendMode(CGBlendMode.Clear);

            DrawString(countString, bounds, font);
        }
Example #57
0
        private void LayoutSubviewsImpl(string badgeNum, TDBadgeView badge, UIColor badgeColor, UIColor badgeColorHighlighted, bool isSecondBadge = false)
        {
            if (!string.IsNullOrEmpty(badgeNum))
            {
                //force badges to hide on edit.
                if (Editing)
                    badge.Hidden = true;
                else
                    badge.Hidden = false;

                var ns = new NSString(badgeNum);
                SizeF badgeSize = ns.StringSize(UIFont.BoldSystemFontOfSize(14));

                RectangleF badgeFrame;

                float additionalOffset = 0;
                if (isSecondBadge) {
                    float firstBadgeWidth = new NSString(Settings.BadgeNumber).StringSize (UIFont.BoldSystemFontOfSize(14)).Width;
                    additionalOffset = firstBadgeWidth + 16 + 4;
                }

                badgeFrame = new RectangleF(ContentView.Frame.Size.Width - (badgeSize.Width+16) - 10 - additionalOffset
                                            , Convert.ToSingle(Math.Round((ContentView.Frame.Size.Height - 18) /2))
                                            , badgeSize.Width + 16f
                                            , 18f);

                badge.Frame = badgeFrame;
                badge.BadgeNumber = badgeNum;
                badge.Parent = this;

                if (TextLabel.Frame.X + TextLabel.Frame.Size.Width >= badgeFrame.X)
                {
                    float badgeWidth = Convert.ToSingle(TextLabel.Frame.Size.Width - badgeFrame.Size.Width - 10.0);

                    TextLabel.Frame = new RectangleF(TextLabel.Frame.X
                                                          , TextLabel.Frame.Y
                                                          , badgeWidth
                                                          , TextLabel.Frame.Size.Height);
                }

                if ((DetailTextLabel.Frame.X + DetailTextLabel.Frame.Size.Width) >= badgeFrame.X)
                {
                    float badgeWidth = Convert.ToSingle(DetailTextLabel.Frame.Size.Width - badgeFrame.Size.Width - 10);
                    DetailTextLabel.Frame = new RectangleF(DetailTextLabel.Frame.X
                                                           , DetailTextLabel.Frame.Y
                                                           , badgeWidth
                                                           , DetailTextLabel.Frame.Size.Height);
                }

                //set badge hightlighed colours or use defaults
                if (badgeColorHighlighted != null)
                    badge.BadgeColorHighlighted = badgeColorHighlighted;
                else
                    badge.BadgeColorHighlighted = UIColor.FromRGBA(1.0f, 1.0f, 1.0f, 1.000f);

                if (badgeColor != null)
                    badge.BadgeColor = badgeColor;
                else
                    badge.BadgeColor = UIColor.FromRGBA(0.530f, 0.600f, 0.738f, 1.000f);
            }
            else
            {
                badge.Hidden = true;
            }
        }
Example #58
0
		public override void Draw (RectangleF rect)
		{
			// If we have a partialTweet, we do not have this information yet.
			if (user == null)
				return;
			
			blocks.Clear();
			
			UIColor txtColor = UIColor.FromRGB(239, 239, 239);
			txtColor.SetColor();			
			
			using (var nss = new NSString (user.Name))
			{
				var dim = nss.StringSize (userFont);
				var placement = new RectangleF (30 + 2 * 26, 2, dim.Width, dim.Height);
				
				var userBlock = new Block()
	            {
					Value = user.Name,
					Bounds = placement,
					Font = userFont, 
					TextColor = txtColor,
				};
				
				blocks.Add(userBlock);
				
				DrawString (user.Name, placement, userFont, UILineBreakMode.TailTruncation);
			};
			
			UIColor relColor = UIColor.LightGray;
			string relString = "";			
			
			if (relation == (int)Relation.UserFollowsYou)
			{
				relColor = UIColor.Red;
				relString = "admirer";
			}
			if (relation == (int)Relation.YouFollowUser)
				relString = "charmer";
			if (relation == (int)Relation.MutualFollowing)
				relString = "friend";
			
			if (relString != "")
			{
				relColor.SetColor();
				using (var nss = new NSString (relString))
				{
					var font = UIFont.FromName("Helvetica", 9);
					var dim = nss.StringSize(font);					
					var placement = new RectangleF (30 + 2 * 26, 4 + userSize, dim.Width, dim.Height);
					
					var userBlock = new Block()
		            {
						Value = relString,
						Bounds = placement,
						Font = font, 
						TextColor = relColor,
					};
					
					blocks.Add(userBlock);
					
					DrawString (relString, placement, font, UILineBreakMode.TailTruncation);
				};				
				
			}
			
			var imgBlock = new Block()
			{ 
				 Value = "profile",
				 Bounds = profileImgFrame,
				 Type = BlockType.Image,
			};
			blocks.Add(imgBlock);			
		}
Example #59
0
 void DrawStringCenteredInRectangle(string str, CGRect rect)
 {
     NSString drawLetter = new NSString(str);
     CGSize strSize = drawLetter.StringSize(mTextAttributes);
     CGPoint strOrigin = new CGPoint();
     strOrigin.X = rect.Location.X + (rect.Size.Width - strSize.Width)/2;
     strOrigin.Y = rect.Location.Y + (rect.Size.Height - strSize.Height)/2;
     if (LetterShadow) {
         NSShadow shadow = new NSShadow();
         shadow.ShadowBlurRadius = 8.0f;
         shadow.ShadowOffset = new CGSize(5.0f, 5.0f);
         shadow.ShadowColor = NSColor.Gray;
         shadow.Set();
     }
     drawLetter.DrawString(strOrigin, mTextAttributes);
 }
		private static float CellHeight (Tweet tweet)
		{
			var text = new NSString(tweet.Title);
			var restrictTo = new SizeF(AppDelegate.IsPad ? BodyWidthIpad : BodyWidthIphone, 999999);
			return text.StringSize(MainBodyFont, restrictTo).Height + MagicAdjustment;
		}