Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions docs/api/UIKit/NSLayoutConstraint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,6 @@ var tconstraint1 = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Width,
</remarks>
<related type="externalDocumentation" href="https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html">Apple documentation for <c>NSLayoutConstraint</c></related>
</Docs>
<Docs DocId="M:UIKit.NSLayoutConstraint.FromVisualFormat(System.String,UIKit.NSLayoutFormatOptions,System.Object[])">
<param name="format">Visual format to use to create the constraints.</param>
<param name="formatOptions">options.</param>
<param name="viewsAndMetrics">
<para>Pairs of names and values. The names should be strings (or NSStrings) and the values should be either UIViews, numbers (any C# number or NSNumber) or <see cref="ObjCRuntime.INativeObject" /> instances that are suitable to be passed to the underlying engine. </para>
<para>
</para>
<para> This binds the provided name with the view or binds the name with the number as a metric.</para>
</param>
<summary>Factory method for creating a constraint using Visual Format Language.</summary>
<returns>An array of layout constraints that are suitable to be added to a <see cref="View" /> using <see cref="View.AddConstraints(NSLayoutConstraint[])" /> method.</returns>
<remarks>
<example>
<code lang="csharp lang-csharp"><![CDATA[
NSLayoutConstraint.FromVisualFormat ("|-8-[messageView]-8-|", NSLayoutOptions.None, "messageView", MakeMessageView ());
]]></code>
</example>
</remarks>
</Docs>
<Docs DocId="M:UIKit.NSLayoutConstraint.ActivateConstraints(UIKit.NSLayoutConstraint[])">
<param name="constraints">Constraints to activate.</param>
<summary>Activates all of the constraints passed.</summary>
Expand Down Expand Up @@ -93,32 +74,6 @@ NSLayoutConstraint.ActivateConstraints(blueConstraints);
<para>It is easier to use the <see cref="NSLayoutConstraint.FromVisualFormat(System.String,NSLayoutFormatOptions,System.Object[])" /> overload as it combines support for both metrics and views in a single call.</para>
</remarks>
</Docs>
<Docs DocId="M:UIKit.NSLayoutConstraint.Create(Foundation.NSObject,UIKit.NSLayoutAttribute,UIKit.NSLayoutRelation,Foundation.NSObject,UIKit.NSLayoutAttribute,System.Runtime.InteropServices.NFloat,System.Runtime.InteropServices.NFloat)">
<param name="view1">First view in the constraint.</param>
<param name="attribute1">Attribute for the first view.</param>
<param name="relation">Relationships between the <paramref name="view1" /> and the <paramref name="view2" />.</param>
<param name="view2">
<para>Second view in the constraint.</para>
<para>This parameter can be <see langword="null" />.</para>
<para tool="nullallowed">This parameter can be <see langword="null" />.</para>
</param>
<param name="attribute2">Attribute for the second view.</param>
<param name="multiplier">Multiplier applied to the second attribute.</param>
<param name="constant">Constants to add.</param>
<summary>Factory method for creating a constraint.</summary>
<returns>
<para>New constraint with the specified parameters.</para>
<para>
</para>
</returns>
<remarks>
<para>Creates a constraint relationship between the <paramref name="view1" /> and the <paramref name="view2" /> that satisfies the following linear equation:</para>
<para>
</para>
<para>
<paramref name="attribute1" /> = <paramref name="multiplier" /> x <paramref name="attribute2" /> + <paramref name="constant" /></para>
</remarks>
</Docs>
<Docs DocId="M:UIKit.NSLayoutConstraint.Create(ObjCRuntime.INativeObject,UIKit.NSLayoutAttribute,UIKit.NSLayoutRelation,ObjCRuntime.INativeObject,UIKit.NSLayoutAttribute,System.Runtime.InteropServices.NFloat,System.Runtime.InteropServices.NFloat)">
<param name="view1">First view in the constraint.</param>
<param name="attribute1">Attribute for the first view.</param>
Expand Down
99 changes: 57 additions & 42 deletions src/Foundation/NSLayoutConstraint.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//
// Helper functions to make FromVisualLayout more palattable
// Helper functions to make FromVisualFormat more palatable
//
// Author:
// Miguel de Icaza
//
// Copyright 2014 Xamarin INc
// Copyright 2014 Xamarin Inc
//

#if MONOMAC
Expand All @@ -13,8 +13,7 @@
using View = UIKit.UIView;
#endif

// Disable until we get around to enable + fix any issues.
#nullable disable
#nullable enable

#if MONOMAC
namespace AppKit
Expand All @@ -23,7 +22,7 @@ namespace UIKit
#endif
{
public partial class NSLayoutConstraint {
static NSNumber AsNumber (object o)
static NSNumber? AsNumber (object o)
{
if (o is NSNumber) return (NSNumber) o;
if (o is double) return new NSNumber ((double) o);
Expand All @@ -42,10 +41,26 @@ static NSNumber AsNumber (object o)
return null;
}

/// <include file="../../docs/api/UIKit/NSLayoutConstraint.xml" path="/Documentation/Docs[@DocId='M:UIKit.NSLayoutConstraint.FromVisualFormat(System.String,UIKit.NSLayoutFormatOptions,System.Object[])']/*" />
/// <summary>Factory method for creating a constraint using Visual Format Language.</summary>
/// <param name="format">Visual format to use to create the constraints.</param>
/// <param name="formatOptions">Options for the format.</param>
/// <param name="viewsAndMetrics">
/// <para>Pairs of names and values. The names should be strings (or <see cref="Foundation.NSString" />) and the values should be either <see cref="View" />s, numbers (any C# number or <see cref="Foundation.NSNumber" />) or <see cref="ObjCRuntime.INativeObject" /> instances that are suitable to be passed to the underlying engine.</para>
/// <para>This binds the provided name with the view or binds the name with the number as a metric.</para>
/// </param>
/// <returns>An array of layout constraints that are suitable to be added to a <see cref="View" /> using the <see cref="View.AddConstraints" /> method.</returns>
/// <remarks>
/// <example>
/// <code lang="csharp lang-csharp"><![CDATA[
/// NSLayoutConstraint.FromVisualFormat ("|-8-[messageView]-8-|", NSLayoutFormatOptions.None, "messageView", MakeMessageView ());
/// ]]></code>
/// </example>
/// </remarks>
static public NSLayoutConstraint [] FromVisualFormat (string format, NSLayoutFormatOptions formatOptions, params object [] viewsAndMetrics)
{
NSMutableDictionary views = null, metrics = null;
ArgumentNullException.ThrowIfNull (format);
ArgumentNullException.ThrowIfNull (viewsAndMetrics);
NSMutableDictionary? views = null, metrics = null;
var count = viewsAndMetrics.Length;
if (count != 0) {
if ((count % 2) != 0)
Expand Down Expand Up @@ -102,60 +117,60 @@ static public NSLayoutConstraint [] FromVisualFormat (string format, NSLayoutFor
return FromVisualFormat (format, formatOptions, metrics, views);
}

/// <param name="view1">To be added.</param>
/// <param name="attribute1">To be added.</param>
/// <param name="relation">To be added.</param>
/// <param name="multiplier">To be added.</param>
/// <param name="constant">To be added.</param>
/// <summary>Static factory method for creating a constraint.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
/// <summary>Factory method for creating a constraint.</summary>
/// <param name="view1">The view or object in the constraint.</param>
/// <param name="attribute1">The attribute for the view.</param>
/// <param name="relation">The relationship in the constraint.</param>
/// <param name="multiplier">The multiplier applied to the attribute.</param>
/// <param name="constant">The constant value in the constraint.</param>
/// <returns>A new constraint with the specified parameters.</returns>
/// <remarks>Creates a constraint for a single view with a specified attribute, relation, multiplier, and constant value.</remarks>
public static NSLayoutConstraint Create (NSObject view1, NSLayoutAttribute attribute1, NSLayoutRelation relation, nfloat multiplier, nfloat constant)
{
return NSLayoutConstraint.Create (view1, attribute1, relation, null, NSLayoutAttribute.NoAttribute, multiplier, constant);
}

/// <param name="view1">To be added.</param>
/// <param name="attribute1">To be added.</param>
/// <param name="relation">To be added.</param>
/// <summary>Static factory method to create a constraint based on a <see cref="View" />, an <see cref="NSLayoutAttribute" />, and an <see cref="NSLayoutRelation" />.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
/// <summary>Factory method to create a constraint based on a <see cref="View" />, an <see cref="NSLayoutAttribute" />, and an <see cref="NSLayoutRelation" />.</summary>
/// <param name="view1">The view or object in the constraint.</param>
/// <param name="attribute1">The attribute for the view.</param>
/// <param name="relation">The relationship in the constraint.</param>
/// <returns>A new constraint with the specified parameters and default multiplier (1.0) and constant (0.0).</returns>
/// <remarks>Creates a constraint for a single view with default multiplier and constant values.</remarks>
public static NSLayoutConstraint Create (NSObject view1, NSLayoutAttribute attribute1, NSLayoutRelation relation)
{
return NSLayoutConstraint.Create (view1, attribute1, relation, null, NSLayoutAttribute.NoAttribute, 1.0f, 0f);
}

// This solves the duplicate selector export problem while not breaking the API.
/// <include file="../../docs/api/UIKit/NSLayoutConstraint.xml" path="/Documentation/Docs[@DocId='M:UIKit.NSLayoutConstraint.Create(Foundation.NSObject,UIKit.NSLayoutAttribute,UIKit.NSLayoutRelation,Foundation.NSObject,UIKit.NSLayoutAttribute,System.Runtime.InteropServices.NFloat,System.Runtime.InteropServices.NFloat)']/*" />
/// <summary>Factory method for creating a constraint.</summary>
/// <param name="view1">First view in the constraint.</param>
/// <param name="attribute1">Attribute for the first view.</param>
/// <param name="relation">Relationship between the <paramref name="view1" /> and the <paramref name="view2" />.</param>
/// <param name="view2">Second view in the constraint. This parameter can be <see langword="null" />.</param>
/// <param name="attribute2">Attribute for the second view.</param>
/// <param name="multiplier">Multiplier applied to the second attribute.</param>
/// <param name="constant">Constant to add.</param>
/// <returns>A new constraint with the specified parameters.</returns>
/// <remarks>Creates a constraint relationship between the <paramref name="view1" /> and the <paramref name="view2" /> that satisfies the following linear equation: <paramref name="attribute1" /> = <paramref name="multiplier" /> x <paramref name="attribute2" /> + <paramref name="constant" />.</remarks>
public static NSLayoutConstraint Create (NSObject view1, NSLayoutAttribute attribute1, NSLayoutRelation relation,
NSObject view2, NSLayoutAttribute attribute2, nfloat multiplier, nfloat constant)
NSObject? view2, NSLayoutAttribute attribute2, nfloat multiplier, nfloat constant)
{
return Create ((INativeObject) view1, attribute1, relation, view2, attribute2, multiplier, constant);
}

/// <typeparam name="AnchorType">To be added.</typeparam>
/// <summary>For an anchor-based constraint, returns the first anchor, properly downcast to <c>AnchorType</c>.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("macos")]
public NSLayoutAnchor<AnchorType> FirstAnchor<AnchorType> () where AnchorType : NSObject
/// <summary>For an anchor-based constraint, returns the first anchor, properly downcast to <typeparamref name="AnchorType" />.</summary>
/// <typeparam name="AnchorType">The type of anchor to return.</typeparam>
/// <returns>The first anchor of the constraint, cast to the specified anchor type.</returns>
/// <remarks>This method is useful for retrieving the first anchor when working with anchor-based constraints.</remarks>
public NSLayoutAnchor<AnchorType>? FirstAnchor<AnchorType> () where AnchorType : NSObject
{
return Runtime.GetNSObject<NSLayoutAnchor<AnchorType>> (_FirstAnchor ());
}

/// <typeparam name="AnchorType">To be added.</typeparam>
/// <summary>For an anchor-based constraint, returns the second anchor, properly downcast to <c>AnchorType</c>.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("macos")]
public NSLayoutAnchor<AnchorType> SecondAnchor<AnchorType> () where AnchorType : NSObject
/// <summary>For an anchor-based constraint, returns the second anchor, properly downcast to <typeparamref name="AnchorType" />.</summary>
/// <typeparam name="AnchorType">The type of anchor to return.</typeparam>
/// <returns>The second anchor of the constraint, cast to the specified anchor type.</returns>
/// <remarks>This method is useful for retrieving the second anchor when working with anchor-based constraints.</remarks>
public NSLayoutAnchor<AnchorType>? SecondAnchor<AnchorType> () where AnchorType : NSObject
{
return Runtime.GetNSObject<NSLayoutAnchor<AnchorType>> (_SecondAnchor ());
}
Expand Down
Loading