public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions) { // Two disjoint rects var r1 = new CGRect (50, 50, 10, 10); var r2 = new CGRect (100, 100, 10, 10); // This condradicts with Apple's doc – https://developer.apple.com/reference/coregraphics/cgrectnull // The null rectangle. This is the rectangle returned when, for example, you intersect two disjoint rectangles. // Note that the null rectangle is not the same as the zero rectangle. // For example, the union of a rectangle with the null rectangle is the original rectangle (that is, the null rectangle contributes nothing). var tmp = r1; tmp.Intersect (r2); // this is mutable method Console.WriteLine (tmp.IsNull ()); // Expected true, but result is false tmp = CGRectIntersection (r1, r2); Console.WriteLine (tmp.IsNull ()); // Expected true, actual true // This should be CGRectNull var rectNull = new CGRect (nfloat.PositiveInfinity, nfloat.PositiveInfinity, 0, 0); Console.WriteLine (rectNull.IsNull ()); // Expected true, actual true // CGRectEmpty and CGRectNull are different var union1 = r1.UnionWith (CGRect.Empty); // new rect {0, 0, 60, 60} Console.WriteLine (union1); var union2 = r1.UnionWith (rectNull); // r1 Console.WriteLine (union2); return true; }
CGRect AddPointsOfType(PointType type, UITouch[] touches, Line line, CGRect rect) { var accumulatedRect = CGRect.Empty; for (int i = 0; i < touches.Length; i++) { var touch = touches [i]; bool isStylus = touch.Type == UITouchType.Stylus; // The visualization displays non-`.Stylus` touches differently. if (!isStylus) { type = type.Add(PointType.Finger); } if (isTouchUpdatingEnabled && (touch.EstimatedProperties != 0)) { type = type.Add(PointType.NeedsUpdate); } bool isLast = i == touches.Length - 1; if (type.Has(PointType.Coalesced) && isLast) { type = type.Remove(PointType.Coalesced); type = type.Add(PointType.Standard); } var touchRect = line.AddPointOfType(type, touch); accumulatedRect = accumulatedRect.UnionWith(touchRect); CommitLine(line); } return(rect.UnionWith(accumulatedRect)); }
public bool UpdateWithTouch(UITouch touch, out CGRect rect) { rect = CGRectNull(); var estimationUpdateIndex = touch.EstimationUpdateIndex; var point = pointsWaitingForUpdatesByEstimationIndex[estimationUpdateIndex]; if (point != null) { rect = UpdateRectForExistingPoint(point); var didUpdate = point.UpdateWithTouch(touch); if (didUpdate) { rect = rect.UnionWith(UpdateRectForExistingPoint(point)); } if (point.EstimatedPropertiesExpectingUpdates == 0) { pointsWaitingForUpdatesByEstimationIndex.Remove(estimationUpdateIndex); } return(didUpdate); } return(false); }
CGRect AddPointsOfType(PointType type, UITouch[] touches, Line line, CGRect rect) { var accumulatedRect = CGRect.Empty; for (int i = 0; i < touches.Length; i++) { var touch = touches [i]; bool isStylus = touch.Type == UITouchType.Stylus; // The visualization displays non-`.Stylus` touches differently. if (!isStylus) { type = PointType.Finger; } if (isTouchUpdatingEnabled && (touch.EstimatedProperties != 0)) { type = PointType.NeedsUpdate; } bool isLast = i == touches.Length - 1; if (type == PointType.Coalesced && isLast) { type = PointType.Standard; } var force = (isStylus || touch.Force > 0) ? touch.Force : 1f; var touchRect = line.AddPointAtLocation(touch.LocationInView(this), touch.GetPreciseLocation(this), force, touch.Timestamp, type); accumulatedRect.UnionWith(touchRect); CommitLine(line); } return(rect.UnionWith(accumulatedRect)); }
public void AdjustToContent() { CGRect contentRect = CGRect.Empty; foreach (var view in scrollView.Subviews) { contentRect = contentRect.UnionWith(view.Frame); } scrollView.ContentSize = contentRect.Size; }
public CGRect Cancel() { CGRect updateRect = CGRect.Empty; foreach (var point in Points) { point.PointType = point.PointType.Add <PointType> (PointType.Cancelled); updateRect = updateRect.UnionWith(UpdateRectForLinePoint(point)); } return(updateRect); }
public void AdjustToContent() { CGRect contentRect = CGRect.Empty; if (scrollView.DocumentView is NSView content) { foreach (var view in content.Subviews) { contentRect = contentRect.UnionWith(view.Frame); } content.SetFrameSize(contentRect.Size); } }
static CGRect UpdateRectForLinePoint(LinePoint point, LinePoint previousPoint) { var rect = new CGRect(point.Location, CGSize.Empty); var pointMagnitude = point.Magnitude; if (previousPoint != null) { pointMagnitude = NMath.Max(pointMagnitude, previousPoint.Magnitude); rect = rect.UnionWith(new CGRect(previousPoint.Location, CGSize.Empty)); } // The negative magnitude ensures an outset rectangle. var magnitude = -3 * pointMagnitude - 2; rect = rect.Inset(magnitude, magnitude); return(rect); }
private CGRect CalculateSpinnerBackgroundFrame() { this.LayoutIfNeeded(); CGRect frame = CGRect.Empty; nfloat x = nfloat.MaxValue; nfloat y = nfloat.MaxValue; foreach (UIView view in this.Subviews) { x = (nfloat)Math.Min(view.Frame.X, x); y = (nfloat)Math.Min(view.Frame.Y, y); frame = frame.UnionWith(view.Frame); } return (new CGRect( x - Constants.SpinnerBackgroundPadding, y - Constants.SpinnerBackgroundPadding, frame.Width - x + Constants.SpinnerBackgroundPadding * 2, frame.Height - y + Constants.SpinnerBackgroundPadding * 2)); }
static CGRect UpdateRectForLinePoint(LinePoint point, LinePoint previousPoint) { var rect = new CGRect (point.Location, CGSize.Empty); var pointMagnitude = point.Magnitude; if (previousPoint != null) { pointMagnitude = NMath.Max (pointMagnitude, previousPoint.Magnitude); rect = rect.UnionWith (new CGRect (previousPoint.Location, CGSize.Empty)); } // The negative magnitude ensures an outset rectangle. var magnitude = -3 * pointMagnitude - 2; rect = rect.Inset (magnitude, magnitude); return rect; }
public override void PrepareLayout() { base.PrepareLayout(); var sectionCount = CollectionView.NumberOfSections(); if (sectionCount == 0) { return; } // Reset Cache _cachedAttributes.Clear(); _contentBounds = new CGRect(CGPoint.Empty, CollectionView.Bounds.Size); var itemCount = CollectionView.NumberOfItemsInSection(0); var currentIndex = 0; var itemStyle = DetermineItemStyle(itemCount); var lastFrame = CGRect.Empty; var cvWidth = CollectionView.Bounds.Width; var cvHeight = CollectionView.Bounds.Height; while (currentIndex < itemCount) { CGRect segmentFrame; var segmentRects = new List <CGRect>(); switch (itemStyle) { case MosaicStyle.FullWidth: segmentFrame = new CGRect(0, lastFrame.GetMaxY() + 1, cvWidth, cvHeight); segmentRects.Add(segmentFrame); break; case MosaicStyle.HalfWidth: segmentFrame = new CGRect(0, lastFrame.GetMaxY() + 1, cvWidth, cvHeight / 2); var slices = segmentFrame.DividedIntegral((nfloat)0.5, CGRectEdge.MinXEdge); segmentRects.Add(slices["First"]); segmentRects.Add(slices["Second"]); break; case MosaicStyle.TwoThirdsByOneThird: segmentFrame = new CGRect(0, lastFrame.GetMaxY() + 1, cvWidth, cvHeight / 3); var twoThirdsHorizontalSlices = segmentFrame.DividedIntegral((nfloat)(2.0 / 3.0), CGRectEdge.MinXEdge); var twoThirdsVerticalSlices = segmentFrame.DividedIntegral((nfloat)0.5, CGRectEdge.MinYEdge); segmentRects.Add(twoThirdsHorizontalSlices["First"]); segmentRects.Add(twoThirdsVerticalSlices["First"]); segmentRects.Add(twoThirdsVerticalSlices["Second"]); break; case MosaicStyle.OneThirdByTwoThirds: segmentFrame = new CGRect(0, lastFrame.GetMaxY() + 1, cvWidth, cvHeight / 3); var oneThirdHorizontalSlices = segmentFrame.DividedIntegral((nfloat)(1.0 / 3.0), CGRectEdge.MinXEdge); var oneThirdVerticalSlices = segmentFrame.DividedIntegral((nfloat)0.5, CGRectEdge.MinYEdge); segmentRects.Add(oneThirdVerticalSlices["First"]); segmentRects.Add(oneThirdVerticalSlices["Second"]); segmentRects.Add(oneThirdHorizontalSlices["Second"]); break; } // cache attributes. foreach (var rect in segmentRects) { var indexPath = NSIndexPath.FromRowSection(currentIndex, 0); var attributes = UICollectionViewLayoutAttributes.CreateForCell(indexPath); attributes.Frame = rect; _cachedAttributes.Add(attributes); _contentBounds = _contentBounds.UnionWith(lastFrame); currentIndex++; lastFrame = rect; } // determine style for next segment switch (itemCount - currentIndex) { case 1: itemStyle = MosaicStyle.FullWidth; break; case 2: itemStyle = MosaicStyle.HalfWidth; break; default: switch (itemStyle) { case MosaicStyle.FullWidth: itemStyle = MosaicStyle.HalfWidth; break; case MosaicStyle.HalfWidth: itemStyle = MosaicStyle.TwoThirdsByOneThird; break; case MosaicStyle.TwoThirdsByOneThird: itemStyle = MosaicStyle.OneThirdByTwoThirds; break; case MosaicStyle.OneThirdByTwoThirds: itemStyle = MosaicStyle.HalfWidth; break; } break; } } }
CGRect AddPointsOfType (PointType type, UITouch[] touches, Line line, CGRect rect) { var accumulatedRect = CGRect.Empty; for (int i = 0; i < touches.Length; i++) { var touch = touches [i]; bool isStylus = touch.Type == UITouchType.Stylus; // The visualization displays non-`.Stylus` touches differently. if (!isStylus) type = type.Add (PointType.Finger); if (isTouchUpdatingEnabled && (touch.EstimatedProperties != 0)) type = type.Add (PointType.NeedsUpdate); bool isLast = i == touches.Length - 1; if (type.Has (PointType.Coalesced) && isLast) { type = type.Remove (PointType.Coalesced); type = type.Add (PointType.Standard); } var touchRect = line.AddPointOfType (type, touch); accumulatedRect = accumulatedRect.UnionWith (touchRect); CommitLine (line); } return rect.UnionWith (accumulatedRect); }