Esempio n. 1
0
            nfloat CalculateHeightFor(ChatDetayDTO msg, UITableView tableView)
            {
                var Boll = msg.text.Split('#');

                if (Boll.Length <= 1)//Resim
                {
                    int index = -1;
                    if (ME.id == msg.receiverId) //GelenMesaj
                    {
                        index = 0;
                    }
                    else
                    {
                        index = 1;
                    }
                    BubbleCell cell = sizingCells[index];
                    if (cell == null)
                    {
                        cell = sizingCells[index] = (BubbleCell)tableView.DequeueReusableCell(GetReuseId(msg));
                    }

                    cell.Message = msg;

                    cell.SetNeedsLayout();
                    cell.LayoutIfNeeded();
                    CGSize size = cell.ContentView.SystemLayoutSizeFittingSize(UIView.UILayoutFittingCompressedSize);

                    return(NMath.Ceiling(size.Height) + 1);
                }
                else
                {
                    return(NMath.Ceiling(200f) + 1);
                }
            }
Esempio n. 2
0
        private nfloat CalculateHeight(UITableViewCell cell)
        {
            cell.SetNeedsLayout();
            cell.LayoutIfNeeded();

            var size = cell.ContentView.Frame.Size;

            return(NMath.Ceiling(size.Height) + 1);
        }
        public CGSize PopUpSizeForString(string str)
        {
            attributedString.MutableString.SetString(new NSString(str));
            nfloat w, h;

            w = NMath.Ceiling(attributedString.Size.Width * WidthPaddingFactor);
            h = NMath.Ceiling(attributedString.Size.Height * HeightPaddingFactor + ArrowLength);
            return(new CGSize(w, h));
        }
Esempio n. 4
0
        public static float GetLineHeight(this CTFont font)
        {
            // https://stackoverflow.com/questions/5511830/how-does-line-spacing-work-in-core-text-and-why-is-it-different-from-nslayoutm
            //var ascent = (double)font.AscentMetric;
            //var descent = (double)font.DescentMetric;
            //var leading = (double)font.LeadingMetric;
            //leading = leading < 0 ? 0.0 : Math.Floor(leading + 0.5);
            //var lineHeight = Math.Floor(ascent + 0.5) + Math.Floor(descent + 0.5) + leading;
            //var ascenderDelta = leading > 0 ? 0.0 : Math.Floor(0.2 * lineHeight + 0.5);
            //return (float)(lineHeight + ascenderDelta);

            return((float)NMath.Ceiling(font.AscentMetric + font.DescentMetric + font.LeadingMetric + 1));
        }
        internal MeasureStringCache.Entry CreateMeasureStringCacheEntryCore(string text, Font font, SizeF area, StringFormat format)
        {
            var c = new MeasureStringCache.Entry(text, font, area, format);

            if (String.IsNullOrEmpty(text))
            {
                return(c);
            }

            var atts = buildAttributedString(text, font, format);

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                area = new SizeF(area.Height, area.Width);
            }

            float lineHeight = font.nativeFont.GetLineHeight();
            var   lines      = CreateLines(font, atts, area, format, lineHeight);

            foreach (var line in lines)
            {
                if (line != null)
                {
                    var lineWidth = (StringFormatFlags.FitBlackBox & format.FormatFlags) != 0
                                                ? line.GetBounds(CTLineBoundsOptions.UseOpticalBounds).Width
                                                : line.GetTypographicBounds(out _, out _, out _);
                    if ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
                    {
                        lineWidth += line.TrailingWhitespaceWidth;
                    }
                    c.measure.Width     = Math.Max(c.measure.Width, (float)NMath.Ceiling((float)lineWidth));
                    c.charactersFitted += (int)line.StringRange.Length;
                    line.Dispose();
                }
                c.measure.Height += lineHeight;
                c.linesFilled++;
            }

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                c.measure = new SizeF(c.measure.Height, c.measure.Width);
            }

            return(c);
        }
Esempio n. 6
0
        nfloat CalculateHeightFor(Message msg, UITableView tableView)
        {
            var        index = (int)msg.Type;
            BubbleCell cell  = sizingCells [index];

            if (cell == null)
            {
                cell = sizingCells [index] = (BubbleCell)tableView.DequeueReusableCell(GetReuseId(msg.Type));
            }

            cell.Message = msg;

            cell.SetNeedsLayout();
            cell.LayoutIfNeeded();
            CGSize size = cell.ContentView.SystemLayoutSizeFittingSize(UIView.UILayoutFittingCompressedSize);

            return(NMath.Ceiling(size.Height) + 1);
        }
        internal MeasureStringCache.Entry CreateMeasureStringCacheEntry(string text, Font font, SizeF area, StringFormat format)
        {
            var c = new MeasureStringCache.Entry(text, font, area, format);

            if (String.IsNullOrEmpty(text))
            {
                return(c);
            }

            var atts = buildAttributedString(text, font, format);

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                area = new SizeF(area.Height, area.Width);
            }
            float lineHeight = (float)NMath.Ceiling(font.nativeFont.AscentMetric + font.nativeFont.DescentMetric + font.nativeFont.LeadingMetric + 1);
            var   lines      = CreateLines(font, atts, area, format, lineHeight);

            foreach (var line in lines)
            {
                if (line != null)
                {
                    nfloat ascent, descent, leading;
                    var    lineWidth = line.GetTypographicBounds(out ascent, out descent, out leading);
                    if ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
                    {
                        lineWidth += line.TrailingWhitespaceWidth;
                    }

                    c.measure.Width     = Math.Max(c.measure.Width, (float)NMath.Ceiling((float)lineWidth));
                    c.charactersFitted += (int)line.StringRange.Length;
                    line.Dispose();
                }
                c.measure.Height += lineHeight;
                c.linesFilled++;
            }
            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                c.measure = new SizeF(c.measure.Height, c.measure.Width);
            }
            return(c);
        }
Esempio n. 8
0
        protected static nfloat GetWidthForString(NSFont font, string text, int sizeDelta = 0)
        {
            NSFont modified = null;
            nfloat width;

            if (sizeDelta != 0)
            {
                modified = NSFont.FromDescription(font.FontDescriptor, font.PointSize + sizeDelta);
            }

            using (var str = new NSAttributedString(text, font: modified ?? font))
                width = str.Size.Width;

            modified?.Dispose();

            width = NMath.Ceiling(width);

            // Note: All code-paths that use sizeDelta == 0 are for NSTextField labels and the only code-path
            // that uses sizeDelta != 0 is for the Show More label in an NSButton.
            if (sizeDelta == 0)
            {
                // Note: In order to match NSTextField.Frame.Width after calling TextField.SizeToFit(), add 4px.
                width += 4;

                // Note: NSTextField also seems to need an extra 8px to actually fit the entire text w/o clipping.
                width += 8;
            }
            else
            {
                // Oddly enough, NSButton padding around the label is also +12px (matched after button.SizeToFit()
                // and checking the resulting button.Frame.Width).
                width += 12;
            }

            return(width);
        }
Esempio n. 9
0
        void RenderReticleImage()
        {
            var imageRadius = NMath.Ceiling(radius * 1.2f);
            var imageSize   = new CGSize(imageRadius * 2f, imageRadius * 2f);

            UIGraphics.BeginImageContextWithOptions(imageSize, false, ContentScaleFactor);

            var ctx = UIGraphics.GetCurrentContext();

            ctx.TranslateCTM(imageRadius, imageRadius);
            ctx.SetLineWidth(2f);

            ctx.SetStrokeColor(reticleColor.CGColor);
            ctx.AddEllipseInRect(new CGRect(-radius, -radius, radius * 2, radius * 2));

            // Draw targeting lines.
            var path      = new CGPath();
            var transform = CGAffineTransform.MakeIdentity();

            for (int i = 0; i < 4; i++)
            {
                path.MoveToPoint(transform, radius * .5f, 0f);
                path.AddLineToPoint(transform, radius * 1.15f, 0);
                transform.Rotate(NMath.PI / 2f);
            }

            ctx.AddPath(path);
            ctx.StrokePath();

            reticleImage = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();

            reticleLayer.Contents      = reticleImage.CGImage;
            reticleLayer.Bounds        = new CGRect(0f, 0f, imageRadius * 2f, imageRadius * 2f);
            reticleLayer.ContentsScale = ContentScaleFactor;
        }
Esempio n. 10
0
 /**
  *
  * Returns: The line spacing, in pixels, of this font.
  *
  * The line spacing of a Font is the vertical distance between the base lines of
  * two consecutive lines of text. Thus, the line spacing includes the blank space
  * between lines along with the height of the character itself.
  *
  * If the Unit property of the font is set to anything other than GraphicsUnit.Pixel,
  * the height (in pixels) is calculated using the vertical resolution of the
  * screen display. For example, suppose the font unit is inches and the font size
  * is 0.3. Also suppose that for the corresponding font family, the em-height
  * is 2048 and the line spacing is 2355. For a screen display that has a vertical
  * resolution of 96 dots per inch, you can calculate the height as follows:
  *
  * 2355*(0.3/2048)*96 = 33.11719
  *
  **/
 float GetNativeheight()
 {
     return((float)NMath.Ceiling(nativeFont.AscentMetric + nativeFont.DescentMetric + nativeFont.LeadingMetric + 1));
 }
Esempio n. 11
0
        public override void ViewDidLoad()
        {
            _title = new UILabel
            {
                Text          = "IP address:",
                TextAlignment = UITextAlignment.Center,
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            _octets     = new UITextField[4];
            _separators = new UILabel[3];

            for (int i = 0; i < _octets.Length; ++i)
            {
                _octets[i] = new UITextField
                {
                    BorderStyle   = UITextBorderStyle.RoundedRect,
                    KeyboardType  = UIKeyboardType.NumberPad,
                    TextAlignment = UITextAlignment.Center,
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
            }

            for (int i = 0; i < _separators.Length; ++i)
            {
                _separators[i] = new UILabel
                {
                    Text = ".",
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
            }

            View.BackgroundColor = UIColor.LightGray;

            nfloat textFieldWidth = NMath.Ceiling(GetStringWidth(new NSString("99999"), _octets[0].Font));

            View.AddSubview(_separators[1]);

            _separators[1].BottomAnchor.ConstraintEqualTo(View.CenterYAnchor).Active  = true;
            _separators[1].CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;

            View.AddSubview(_octets[1]);

            _octets[1].BottomAnchor.ConstraintEqualTo(View.CenterYAnchor).Active           = true;
            _octets[1].RightAnchor.ConstraintEqualTo(_separators[1].LeftAnchor, -4).Active = true;
            _octets[1].WidthAnchor.ConstraintEqualTo(textFieldWidth).Active          = true;
            _octets[1].HeightAnchor.ConstraintEqualTo(_octets[1].WidthAnchor).Active = true;

            View.AddSubview(_octets[2]);

            _octets[2].BottomAnchor.ConstraintEqualTo(View.CenterYAnchor).Active          = true;
            _octets[2].LeftAnchor.ConstraintEqualTo(_separators[1].RightAnchor, 4).Active = true;
            _octets[2].WidthAnchor.ConstraintEqualTo(textFieldWidth).Active          = true;
            _octets[2].HeightAnchor.ConstraintEqualTo(_octets[2].WidthAnchor).Active = true;

            View.AddSubview(_separators[0]);

            _separators[0].BottomAnchor.ConstraintEqualTo(View.CenterYAnchor).Active       = true;
            _separators[0].RightAnchor.ConstraintEqualTo(_octets[1].LeftAnchor, -4).Active = true;

            View.AddSubview(_separators[2]);

            _separators[2].BottomAnchor.ConstraintEqualTo(View.CenterYAnchor).Active      = true;
            _separators[2].LeftAnchor.ConstraintEqualTo(_octets[2].RightAnchor, 4).Active = true;

            View.AddSubview(_octets[0]);

            _octets[0].BottomAnchor.ConstraintEqualTo(View.CenterYAnchor).Active           = true;
            _octets[0].RightAnchor.ConstraintEqualTo(_separators[0].LeftAnchor, -4).Active = true;
            _octets[0].WidthAnchor.ConstraintEqualTo(textFieldWidth).Active          = true;
            _octets[0].HeightAnchor.ConstraintEqualTo(_octets[1].WidthAnchor).Active = true;

            View.AddSubview(_octets[3]);

            _octets[3].BottomAnchor.ConstraintEqualTo(View.CenterYAnchor).Active          = true;
            _octets[3].LeftAnchor.ConstraintEqualTo(_separators[2].RightAnchor, 4).Active = true;
            _octets[3].WidthAnchor.ConstraintEqualTo(textFieldWidth).Active          = true;
            _octets[3].HeightAnchor.ConstraintEqualTo(_octets[2].WidthAnchor).Active = true;

            _cancelButton = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            _cancelButton.SetTitleColor(UIColor.Red, UIControlState.Normal);
            _cancelButton.SetTitle("Cancel", UIControlState.Normal);
            _cancelButton.TouchUpInside += (sender, args) => UserDidCancelSetup();

            View.AddSubview(_cancelButton);

            _cancelButton.LeftAnchor.ConstraintEqualTo(_octets[0].LeftAnchor).Active      = true;
            _cancelButton.TopAnchor.ConstraintEqualTo(_octets[0].BottomAnchor, 32).Active = true;

            _connectButton = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            _connectButton.SetTitle("Connect", UIControlState.Normal);
            _connectButton.TouchUpInside += (sender, args) => UserDidFinishSetup();

            View.AddSubview(_connectButton);

            _connectButton.RightAnchor.ConstraintEqualTo(_octets[3].RightAnchor).Active    = true;
            _connectButton.TopAnchor.ConstraintEqualTo(_octets[3].BottomAnchor, 32).Active = true;

            View.AddSubview(_title);

            _title.Font = UIFont.BoldSystemFontOfSize(_title.Font.PointSize);
            _title.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active       = true;
            _title.BottomAnchor.ConstraintEqualTo(_octets[1].TopAnchor, -32).Active = true;
        }
        internal DrawStringCache.Entry CreateCacheEntry(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
        {
            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }
            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            layoutRectangle.Location = PointF.Empty;
            var c = new DrawStringCache.Entry(s, font, brush, layoutRectangle, format);

            brush.Setup(this, false);             // Stroke
            var attributedString = buildAttributedString(s, font, format, lastBrushColor);

            // Work out the geometry
            c.layoutAvailable = true;
            var insetBounds = layoutRectangle;

            if (insetBounds.Size == SizeF.Empty)
            {
                insetBounds.Width  = float.MaxValue;
                insetBounds.Height = float.MaxValue;
                c.layoutAvailable  = false;
            }

            c.lineHeight     = font.nativeFont.GetLineHeight();
            c.lines          = new List <CTLine>();
            c.verticalMatrix = default(CGAffineTransform);

            // Calculate the lines
            // If we are drawing vertical direction then we need to rotate our context transform by 90 degrees
            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                // Swap out the width and height and calculate the lines
                c.lines        = CreateLines(font, attributedString, new SizeF(insetBounds.Height, insetBounds.Width), format, c.lineHeight);
                c.boundsWidth  = insetBounds.Height;
                c.boundsHeight = insetBounds.Width;
            }
            else
            {
                c.lines        = CreateLines(font, attributedString, insetBounds.Size, format, c.lineHeight);
                c.boundsWidth  = insetBounds.Width;
                c.boundsHeight = insetBounds.Height;
            }

            c.textPosition = new PointF(insetBounds.X + .5f, insetBounds.Y + .5f);
            if (c.layoutAvailable)
            {
                if (format.LineAlignment == StringAlignment.Far)
                {
                    c.textPosition.Y += c.boundsHeight - (c.lines.Count * c.lineHeight);
                }
                else if (format.LineAlignment == StringAlignment.Center)
                {
                    c.textPosition.Y += (c.boundsHeight - (c.lines.Count * c.lineHeight)) / 2;
                }
            }
            else
            {
                // Precalculate maximum width to allow for aligning lines
                if (format.Alignment != StringAlignment.Near)
                {
                    float maxLineWidth = 0;
                    foreach (var line in c.lines)
                    {
                        if (line != null)
                        {
                            var lineWidth = (StringFormatFlags.FitBlackBox & format.FormatFlags) != 0
                                                                ? line.GetBounds(CTLineBoundsOptions.UseOpticalBounds).Width
                                                                : line.GetTypographicBounds(out _, out _, out _);
                            if ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
                            {
                                lineWidth += line.TrailingWhitespaceWidth;
                            }
                            maxLineWidth = Math.Max(maxLineWidth, (float)NMath.Ceiling((float)lineWidth));
                        }
                    }
                    c.boundsWidth = maxLineWidth;
                }
                if (format.LineAlignment == StringAlignment.Far)
                {
                    c.textPosition.Y -= c.lineHeight * c.lines.Count;
                }
                else if (format.LineAlignment == StringAlignment.Center)
                {
                    c.textPosition.Y -= (c.lineHeight * c.lines.Count) / 2;
                }
            }
            return(c);
        }
Esempio n. 13
0
        public static SCNNode SCBoxNode(string title, CGRect frame, NSColor color, float cornerRadius, bool centered)
        {
            NSStringAttributes titleAttributes         = null;
            NSStringAttributes centeredTitleAttributes = null;

            // create and extrude a bezier path to build the box
            var path = NSBezierPath.FromRoundedRect(frame, cornerRadius, cornerRadius);

            path.Flatness = 0.05f;

            var shape = SCNShape.Create(path, 20);

            shape.ChamferRadius = 0.0f;

            var node = SCNNode.Create();

            node.Geometry = shape;

            // create an image and fill with the color and text
            var textureSize = new CGSize();

            textureSize.Width  = NMath.Ceiling(frame.Size.Width * 1.5f);
            textureSize.Height = NMath.Ceiling(frame.Size.Height * 1.5f);

            var texture = new NSImage(textureSize);

            texture.LockFocus();

            var drawFrame = new CGRect(0, 0, textureSize.Width, textureSize.Height);

            nfloat hue, saturation, brightness, alpha;

            (color.UsingColorSpace(NSColorSpace.DeviceRGBColorSpace)).GetHsba(out hue, out saturation, out brightness, out alpha);
            var lightColor = NSColor.FromDeviceHsba(hue, saturation - 0.2f, brightness + 0.3f, alpha);

            lightColor.Set();

            NSGraphics.RectFill(drawFrame);

            NSBezierPath fillpath = null;

            if (cornerRadius == 0 && centered == false)
            {
                //special case for the "labs" slide
                drawFrame.Offset(0, -2);
                fillpath = NSBezierPath.FromRoundedRect(drawFrame, cornerRadius, cornerRadius);
            }
            else
            {
                drawFrame.Inflate(-3, -3);
                fillpath = NSBezierPath.FromRoundedRect(drawFrame, cornerRadius, cornerRadius);
            }

            color.Set();
            fillpath.Fill();

            // draw the title if any
            if (title != null)
            {
                if (titleAttributes == null)
                {
                    var paraphStyle = new NSMutableParagraphStyle();
                    paraphStyle.LineBreakMode     = NSLineBreakMode.ByWordWrapping;
                    paraphStyle.Alignment         = NSTextAlignment.Center;
                    paraphStyle.MinimumLineHeight = 38;
                    paraphStyle.MaximumLineHeight = 38;

                    var font = NSFont.FromFontName("Myriad Set Semibold", 34) != null?NSFont.FromFontName("Myriad Set Semibold", 34) : NSFont.FromFontName("Avenir Medium", 34);

                    var shadow = new NSShadow();
                    shadow.ShadowOffset     = new CGSize(0, -2);
                    shadow.ShadowBlurRadius = 4;
                    shadow.ShadowColor      = NSColor.FromDeviceWhite(0.0f, 0.5f);

                    titleAttributes = new NSStringAttributes {
                        Font            = font,
                        ForegroundColor = NSColor.White,
                        Shadow          = shadow,
                        ParagraphStyle  = paraphStyle
                    };

                    var centeredParaphStyle = (NSMutableParagraphStyle)paraphStyle.MutableCopy();
                    centeredParaphStyle.Alignment = NSTextAlignment.Center;

                    centeredTitleAttributes = new NSStringAttributes {
                        Font            = font,
                        ForegroundColor = NSColor.White,
                        Shadow          = shadow,
                        ParagraphStyle  = paraphStyle
                    };
                }

                var attrString = new NSAttributedString(title, centered ? centeredTitleAttributes : titleAttributes);
                var textSize   = attrString.Size;

                //check if we need two lines to draw the text
                var twoLines = title.Contains("\n");
                if (!twoLines)
                {
                    twoLines = textSize.Width > frame.Size.Width && title.Contains(" ");
                }

                //if so, we need to adjust the size to center vertically
                if (twoLines)
                {
                    textSize.Height += 38;
                }

                if (!centered)
                {
                    drawFrame.Inflate(-15, 0);
                }

                //center vertically
                var dy = (drawFrame.Size.Height - textSize.Height) * 0.5f;
                var drawFrameHeight = drawFrame.Size.Height;
                drawFrame.Size = new CGSize(drawFrame.Size.Width, drawFrame.Size.Height - dy);
                attrString.DrawString(drawFrame);
            }

            texture.UnlockFocus();

            //set the created image as the diffuse texture of our 3D box
            var front = SCNMaterial.Create();

            front.Diffuse.Contents        = texture;
            front.LocksAmbientWithDiffuse = true;

            //use a lighter color for the chamfer and sides
            var sides = SCNMaterial.Create();

            sides.Diffuse.Contents  = lightColor;
            node.Geometry.Materials = new SCNMaterial[] {
                front,
                sides,
                sides,
                sides,
                sides
            };

            return(node);
        }
Esempio n. 14
0
        public virtual void Reload()
        {
            var lc      = 0;
            var rc      = 0;
            var l       = LeftViews.Count * InterimSpace;
            var r       = RightViews.Count * InterimSpace;
            var p       = this.Width() - l - r - ContentEdgeInsets.Left - ContentEdgeInsets.Right;
            var columns = (int)System.NMath.Ceiling(p / GridFactor);

            this.Grid().Begin();
            this.Grid().Views.Clear();
            this.Grid().Axis.Columns = columns;

            foreach (var v in LeftViews)
            {
                if (v is UIButton)
                {
                    (v as UIButton).ContentEdgeInsets = UIEdgeInsets.Zero;
                    (v as UIButton).TitleEdgeInsets   = UIEdgeInsets.Zero;
                }

                v.SetWidth(v.IntrinsicContentSize.Width);
                v.SizeToFit();
                v.Grid().Columns = ((int)NMath.Ceiling(v.Width() / GridFactor)) + 2;

                lc += v.Grid().Columns;

                this.Grid().Views.Add(v);
            }

            this.Grid().Views.Add(ContentView);

            foreach (var v in RightViews)
            {
                if (v is UIButton)
                {
                    (v as UIButton).ContentEdgeInsets = UIEdgeInsets.Zero;
                    (v as UIButton).TitleEdgeInsets   = UIEdgeInsets.Zero;
                }

                v.SetWidth(v.IntrinsicContentSize.Width);
                v.SizeToFit();
                v.Grid().Columns = ((int)NMath.Ceiling(v.Width() / GridFactor)) + 2;

                rc += v.Grid().Columns;

                this.Grid().Views.Add(v);
            }

            ContentView.Grid().Begin();
            ContentView.Grid().Views = CenterViews;

            if (ContentViewAlignment == ContentViewAlignment.Center)
            {
                if (lc < rc)
                {
                    ContentView.Grid().Columns = columns - 2 * rc;
                    ContentView.Grid().Offset.Columns = rc - lc;
                }
                else
                {
                    ContentView.Grid().Columns = columns - 2 * lc;
                    ContentView.Grid().Offset.Columns = 0;
                    if (RightViews[0] != null)
                    {
                        RightViews[0].Grid().Offset.Columns = lc - rc;
                    }
                }
            }
            else
            {
                ContentView.Grid().Columns = columns - lc - rc;
            }

            this.Grid().Commit();
            ContentView.Grid().Commit();
        }
Esempio n. 15
0
        /**
         * Lays out the UINavigationItem.
         * - Parameter item: A UINavigationItem to layout.
         */
        internal void layoutNavigationItem(UINavigationItem item)
        {
            if (WillLayout)
            {
                prepareItem(item);
                prepareTitleView(item);

                var frame = item.TitleView.Frame;
                frame.Location       = CGPoint.Empty;
                frame.Size           = IntrinsicContentSize;
                item.TitleView.Frame = frame;

                var lc      = 0;
                var rc      = 0;
                var l       = ((nfloat)(item.LeftViews().Count) * InterimSpace);
                var r       = ((nfloat)(item.RightViews().Count) * InterimSpace);
                var p       = this.Width() - l - r - ContentEdgeInsets.Left - ContentEdgeInsets.Right;
                var columns = (int)(NMath.Ceiling(p / GridFactor));

                item.TitleView.Grid().Begin();
                item.TitleView.Grid().Views.Clear();
                item.TitleView.Grid().Axis.Columns = columns;

                foreach (var v in item.LeftViews())
                {
                    if (v is UIButton)
                    {
                        ((UIButton)v).ContentEdgeInsets = UIEdgeInsets.Zero;
                        ((UIButton)v).TitleEdgeInsets   = UIEdgeInsets.Zero;
                    }

                    v.SetWidth(v.IntrinsicContentSize.Width);
                    v.SizeToFit();
                    v.Grid().Columns = ((int)NMath.Ceiling(v.Width() / GridFactor)) + 2;

                    lc += v.Grid().Columns;

                    item.TitleView.Grid().Views.Add(v);
                }

                item.TitleView.Grid().Views.Add(item.ContentView());

                foreach (var v in item.RightViews())
                {
                    if (v is UIButton)
                    {
                        ((UIButton)v).ContentEdgeInsets = UIEdgeInsets.Zero;
                        ((UIButton)v).TitleEdgeInsets   = UIEdgeInsets.Zero;
                    }

                    v.SetWidth(v.IntrinsicContentSize.Width);
                    v.SizeToFit();
                    v.Grid().Columns = ((int)NMath.Ceiling(v.Width() / GridFactor)) + 2;

                    rc += v.Grid().Columns;

                    item.TitleView.Grid().Views.Add(v);
                }

                item.ContentView().Grid().Begin();

                if (item.ContentViewAlignment() == ContentViewAlignment.Center)
                {
                    if (lc < rc)
                    {
                        item.ContentView().Grid().Columns = columns - 2 * rc;
                        item.ContentView().Grid().Offset.Columns = rc - lc;
                    }
                    else
                    {
                        item.ContentView().Grid().Columns = columns - 2 * lc;
                        item.ContentView().Grid().Offset.Columns = 0;
                        if (item.RightViews().Count > 0)
                        {
                            item.RightViews()[0].Grid().Offset.Columns = lc - rc;
                        }
                    }
                }
                else
                {
                    item.ContentView().Grid().Columns = columns - lc - rc;
                }

                item.TitleView.Grid().InterimSpace      = InterimSpace;
                item.TitleView.Grid().ContentEdgeInsets = ContentEdgeInsets;
                item.TitleView.Grid().Commit();
                item.ContentView().Grid().Commit();

                // contentView alignment.
                if (!string.IsNullOrEmpty(item.Title()))
                {
                    if (item.Titlelabel().Superview == null)
                    {
                        item.ContentView().AddSubview(item.Titlelabel());
                    }
                    item.Titlelabel().Frame = item.ContentView().Bounds;
                }
                else
                {
                    item.Titlelabel().RemoveFromSuperview();
                }

                if (!string.IsNullOrEmpty(item.Detail()))
                {
                    if (item.DetailLabel().Superview == null)
                    {
                        item.ContentView().AddSubview(item.DetailLabel());
                    }

                    if (item.Titlelabel().Superview == null)
                    {
                        item.DetailLabel().Frame = item.ContentView().Bounds;
                    }
                    else
                    {
                        item.Titlelabel().SizeToFit();
                        item.DetailLabel().SizeToFit();

                        nfloat diff = (item.ContentView().Frame.Height - item.Titlelabel().Frame.Height - item.DetailLabel().Frame.Height) / 2;

                        item.Titlelabel().SetHeight(item.Titlelabel().Height() + diff);
                        item.Titlelabel().SetWidth(item.ContentView().Width());

                        item.DetailLabel().SetHeight(item.DetailLabel().Height() + diff);
                        item.DetailLabel().SetWidth(item.ContentView().Width());
                        item.DetailLabel().SetY(item.Titlelabel().Height());
                    }
                }
                else
                {
                    item.DetailLabel().RemoveFromSuperview();
                }
            }
        }
Esempio n. 16
0
 public static CGSize InflateToIntegral(this CGSize size)
 => new CGSize(NMath.Ceiling(size.Width), NMath.Ceiling(size.Height));