Example #1
0
        public void TestFrameAndOriginPlacement()
        {
            var containerSize = new SizeF(320, 50);

            var container = new NativeView(new CGRect(0, 0, containerSize.Width, containerSize.Height));

            container.Yoga().IsEnabled     = true;
            container.Yoga().FlexDirection = YogaFlexDirection.Row;

            for (int i = 0; i < 3; i++)
            {
                var subview = new NativeView();
                subview.Yoga().IsEnabled = true;
                subview.Yoga().FlexGrow  = 1;
                container.AddSubview(subview);
            }
            container.Yoga().ApplyLayout();

            Assert.False(CGRect.Intersect(container.Subviews[0].Frame, container.Subviews[1].Frame) == CGRect.Empty);
            Assert.False(CGRect.Intersect(container.Subviews[1].Frame, container.Subviews[2].Frame) == CGRect.Empty);
            Assert.False(CGRect.Intersect(container.Subviews[0].Frame, container.Subviews[2].Frame) == CGRect.Empty);

            float totalWidth = 0;

            foreach (var view in container.Subviews)
            {
                totalWidth += (float)view.Bounds.Size.Width;
            }

            Assert.AreEqual(containerSize.Width, totalWidth, $"The container's width is {containerSize.Width}, the subviews take up {totalWidth}");
        }
Example #2
0
		public void DrawRect(CGRect aRect, bool selected)
		{
			NSGraphics.RectClip (aRect);
			
			aRect.Intersect (Frame);
			
			Color.Set ();
			NSGraphics.RectFill (aRect);
			
		    if (selected) {
		        NSColor.Black.Set ();
		        NSGraphics.FrameRectWithWidth (Frame, 4.0f);
		    }
			
			if (IsLocked){
				float xSize = (Frame.Width > 10.0f) ? 5.0f : 3.0f;
				
				NSBezierPath path = new NSBezierPath ();
				
				NSColor.Black.Set ();
				path.LineWidth = 3.0f;
				path.MoveTo (new CGPoint (MidX (Frame) - xSize, MidY (Frame) - xSize));
				path.LineTo (new CGPoint (MidX (Frame) + xSize, MidY (Frame) + xSize));
				path.MoveTo (new CGPoint (MidX (Frame) - xSize, MidY (Frame) + xSize));
				path.LineTo (new CGPoint (MidX (Frame) + xSize, MidY (Frame) - xSize));
				path.Stroke ();
				
			}
	
		}
Example #3
0
        public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
        {
            var attributes = new List <UICollectionViewLayoutAttributes>();

            foreach (var attr in calculatedAttributes)
            {
                CGRect intersection = CGRect.Intersect(attr.Frame, rect);

                if (intersection != CGRect.Empty)
                {
                    attributes.Add(attr);
                }
            }

            return(attributes.ToArray());
        }
Example #4
0
        private void OnKeyboardWillShow(object sender, UIKeyboardEventArgs args)
        {
            if (ScrollView != null)
            {
                var orientation = UIApplication.SharedApplication.StatusBarOrientation;

                var kbRect = args.FrameEnd;
                if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight)
                {
                    var origKeySize = kbRect.Size;
                    kbRect.Height = origKeySize.Width;
                    kbRect.Width  = origKeySize.Height;
                }

                UIEdgeInsets contentInsets;
                CGRect       translatedView = ScrollView.ConvertRectFromView(kbRect, UIApplication.SharedApplication.Delegate.GetWindow());
                CGRect       intersection   = CGRect.Intersect(ScrollView.Bounds, translatedView);
                contentInsets = new UIEdgeInsets(0.0f, 0.0f, intersection.Height, 0.0f);

                ScrollView.ContentInset          = contentInsets;
                ScrollView.ScrollIndicatorInsets = contentInsets;
            }
        }
        public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndexPath indexPath)
        {
            var currentItemAttributes = base.LayoutAttributesForItem(indexPath).Copy() as UICollectionViewLayoutAttributes;
            var sectionInset          = EvaluatedSectionInsetForItem(indexPath.Section);

            bool   isFirstItemInSection = indexPath.Item == 0;
            nfloat layoutWidth          = CollectionView.Frame.Width - sectionInset.Left - sectionInset.Right;

            if (isFirstItemInSection)
            {
                currentItemAttributes.LeftAlignFrame(sectionInset);
                return(currentItemAttributes);
            }

            var    previousIndexPath       = NSIndexPath.FromItemSection(indexPath.Item - 1, indexPath.Section);
            CGRect previousFrame           = LayoutAttributesForItem(previousIndexPath).Frame;
            nfloat previousFrameRightPoint = previousFrame.X + previousFrame.Width;
            CGRect currentFrame            = currentItemAttributes.Frame;
            CGRect strecthedCurrentFrame   = new CGRect(sectionInset.Left, currentFrame.Y, layoutWidth, currentFrame.Height);

            // if the current frame, once left aligned to the left and strectched to the full collection view
            //  width intersects the previous frame then they are on the same line
            bool isFirstItemInRow = CGRect.Intersect(previousFrame, strecthedCurrentFrame) == CGRect.Empty;

            if (isFirstItemInRow)
            {
                // make sure the first item on a line is left aligned
                currentItemAttributes.LeftAlignFrame(sectionInset);
                return(currentItemAttributes);
            }

            CGRect frame = currentItemAttributes.Frame;

            frame.X = previousFrameRightPoint + EvaluatedMinimumInteritemSpacing(indexPath.Section);
            currentItemAttributes.Frame = frame;
            return(currentItemAttributes);
        }
Example #6
0
        internal void UpdateInsets()
        {
            if (this.lastKeyboardRect.IsEmpty || this.fetchWindow() == null)
            {
                return;
            }
            NSView firstResponder = UIViewExtensions.FindFirstResponder(this.targetView);
            CGRect frame          = this.targetView.Frame;
            CGSize size           = frame.Size;
            // ISSUE: reference to a compiler-generated method
            CGRect cgRect = CGRect.Intersect(this.targetView.Superview.ConvertRectFromView(this.lastKeyboardRect, (NSView)null), this.targetView.Frame);

            this.setInsetAction(new UIEdgeInsets((nfloat)0, (nfloat)0, cgRect.Height, (nfloat)0));
            if (!(firstResponder is UITextView) || this.setContentOffset == null)
            {
                return;
            }
            nfloat nfloat = size.Height - cgRect.Height;
            NSView uiView = firstResponder;

            frame = uiView.Frame;
            CGPoint location  = frame.Location;
            NSView  superview = this.targetView.Superview;
            // ISSUE: reference to a compiler-generated method
            nfloat y1 = uiView.ConvertPointToView(location, superview).Y;

            frame = firstResponder.Frame;
            nfloat height = frame.Height;
            nfloat y2     = y1 + height - nfloat;

            if (!(y2 > (nfloat)0))
            {
                return;
            }
            this.setContentOffset(new CGPoint((nfloat)0, y2));
        }
        public override void Draw(CGRect rect)
        {
            using (var context = UIGraphics.GetCurrentContext ()) {

                // get the scale from the context by getting the current transform matrix, then asking for
                // its "a" component, which is one of the two scale components. We could also ask for "d".
                // This assumes (safely) that the view is being scaled equally in both dimensions.
                var scale = context.GetCTM ().xx;
                CATiledLayer tiledLayer = (CATiledLayer)this.Layer;
                var tileSize = tiledLayer.TileSize;

                // Even at scales lower than 100%, we are drawing into a rect in the coordinate system of the full
                // image. One tile at 50% covers the width (in original image coordinates) of two tiles at 100%.
                // So at 50% we need to stretch our tiles to double the width and height; at 25% we need to stretch
                // them to quadruple the width and height; and so on.
                // (Note that this means that we are drawing very blurry images as the scale gets low. At 12.5%,
                // our lowest scale, we are stretching about 6 small tiles to fill the entire original image area.
                // But this is okay, because the big blurry image we're drawing here will be scaled way down before
                // it is displayed.)
                tileSize.Width /= scale;
                tileSize.Height /= scale;

                // calculate the rows and columns of tiles that intersect the rect we have been asked to draw
                int firstCol = (int)Math.Floor (rect.GetMinX () / tileSize.Width);
                int lastCol = (int)Math.Floor ((rect.GetMaxX () - 1) / tileSize.Width);
                int firstRow = (int)Math.Floor (rect.GetMinY () / tileSize.Height);
                int lastRow = (int)Math.Floor ((rect.GetMaxY () - 1) / tileSize.Height);

                for (int row = firstRow; row <= lastRow; row++) {
                    for (int col = firstCol; col <= lastCol; col++) {

                        UIImage tile = TileForScale ((float)scale, row, col);
                        var tileRect = new CGRect (tileSize.Width * col, tileSize.Height * row, tileSize.Width, tileSize.Height);
                        // if the tile would stick outside of our bounds, we need to truncate it so as to avoid
                        // stretching out the partial tiles at the right and bottom edges
                        tileRect.Intersect (this.Bounds);
                        tile.Draw (tileRect);
                    }
                }
            }
        }