From b4c2185c590cf850a6f95c28fef9191ec745c066 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 22 Jul 2021 10:56:55 +0200 Subject: [PATCH] [AppKit/UIKit] Share the implementation of some enums between AppKit and UIKit. (#12164) * [AppKit/UIKit] Merge the definitions of NSDirectionalRectEdge. * [AppKit/UIKit] Merge the definitions of NSControlCharacterAction. The enum values weren't the same between AppKit and UIKit, but I picked the AppKit ones since they looked better, added those to every platform, and deprecated the other ones where they existed. Except on Mac Catalyst, where I removed instead of deprecating, since we don't need to consider backwards compatibility. * [AppKit/UIKit] Merge the definitions of NSGlyphProperty. * [AppKit/UIKit] Merge the definitions of NSLayoutAttribute and NSLayoutFormatOptions. * [AppKit/UIKit] Merge the definitions of NSLayoutRelation. * [AppKit/UIKit] Merge the definitions of NSLineBreakStrategy. * [AppKit/UIKit] Merge the definitions of NSRectAlignment. --- src/AppKit/Enums.cs | 86 -------------------- src/UIKit/UIEnums.cs | 135 -------------------------------- src/appkit.cs | 27 ------- src/xkit.cs | 182 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+), 248 deletions(-) diff --git a/src/AppKit/Enums.cs b/src/AppKit/Enums.cs index ed69547ac6ca..7e50c82ffa6c 100644 --- a/src/AppKit/Enums.cs +++ b/src/AppKit/Enums.cs @@ -2421,58 +2421,6 @@ public enum NSEventGestureAxis : long { None, Horizontal, Vertical } - [Native] - public enum NSLayoutRelation : long { - LessThanOrEqual = -1, - Equal = 0, - GreaterThanOrEqual = 1 - } - - [Native] - public enum NSLayoutAttribute : long { - NoAttribute = 0, - Left = 1, - Right, - Top, - Bottom, - Leading, - Trailing, - Width, - Height, - CenterX, - CenterY, - Baseline, - [Mac (10,11)] LastBaseline = Baseline, - [Mac (10,11)] FirstBaseline, - } - - [Flags] - [Native] - public enum NSLayoutFormatOptions : ulong { - None = 0, - - AlignAllLeft = (1 << (int)NSLayoutAttribute.Left), - AlignAllRight = (1 << (int)NSLayoutAttribute.Right), - AlignAllTop = (1 << (int)NSLayoutAttribute.Top), - AlignAllBottom = (1 << (int)NSLayoutAttribute.Bottom), - AlignAllLeading = (1 << (int)NSLayoutAttribute.Leading), - AlignAllTrailing = (1 << (int)NSLayoutAttribute.Trailing), - AlignAllCenterX = (1 << (int)NSLayoutAttribute.CenterX), - AlignAllCenterY = (1 << (int)NSLayoutAttribute.CenterY), - AlignAllBaseline = (1 << (int)NSLayoutAttribute.Baseline), - [Mac (10,11)] AlignAllLastBaseline = (int)AlignAllBaseline, - [Mac (10,11)] AlignAllFirstBaseline = (1 << (int)NSLayoutAttribute.FirstBaseline), - AlignmentMask = 0xFFFF, - - /* choose only one of these three - */ - DirectionLeadingToTrailing = 0 << 16, // default - DirectionLeftToRight = 1 << 16, - DirectionRightToLeft = 2 << 16, - - DirectionMask = 0x3 << 16, - } - [Native] public enum NSLayoutConstraintOrientation : long { Horizontal, Vertical @@ -2766,29 +2714,6 @@ public enum NSSpringLoadingOptions : ulong NoHover = 1 << 3 } - [Mac (10,11)] - [Native] - public enum NSGlyphProperty : long - { - Null = (1 << 0), - ControlCharacter = (1 << 1), - Elastic = (1 << 2), - NonBaseCharacter = (1 << 3) - } - - [Flags] - [Mac (10,11)] - [Native] - public enum NSControlCharacterAction : long - { - ZeroAdvancement = (1 << 0), - Whitespace = (1 << 1), - HorizontalTab = (1 << 2), - LineBreak = (1 << 3), - ParagraphBreak = (1 << 4), - ContainerBreak = (1 << 5) - } - [Flags] [Mac (10,12)] [Native] @@ -3106,15 +3031,4 @@ public enum NSImageSymbolScale : long Medium = 2, Large = 3, } - - [Mac (11,0)] - [Flags] - [Native] - public enum NSLineBreakStrategy : ulong - { - None = 0x0, - PushOut = 1uL << 0, - HangulWordPriority = 1uL << 1, - Standard = 0xffff, - } } diff --git a/src/UIKit/UIEnums.cs b/src/UIKit/UIEnums.cs index 7a77e5ea8e52..b54108c476a9 100644 --- a/src/UIKit/UIEnums.cs +++ b/src/UIKit/UIEnums.cs @@ -1177,84 +1177,6 @@ public enum UITextGranularity : long { Document } - // NSInteger -> UITextInput.h - [Native] - [NoWatch] - public enum NSLayoutRelation : long { - LessThanOrEqual = -1, - Equal = 0, - GreaterThanOrEqual = 1 - } - - // NSInteger -> NSLayoutConstraint.h - [Native] - [NoWatch] - public enum NSLayoutAttribute : long { - NoAttribute = 0, - Left = 1, - Right, - Top, - Bottom, - Leading, - Trailing, - Width, - Height, - CenterX, - CenterY, - Baseline, - LastBaseline = Baseline, - FirstBaseline, - - [iOS (8,0)] - LeftMargin, - [iOS (8,0)] - RightMargin, - [iOS (8,0)] - TopMargin, - [iOS (8,0)] - BottomMargin, - [iOS (8,0)] - LeadingMargin, - [iOS (8,0)] - TrailingMargin, - [iOS (8,0)] - CenterXWithinMargins, - [iOS (8,0)] - CenterYWithinMargins, - } - - // NSUInteger -> NSLayoutConstraint.h - [Native] - [Flags] - [NoWatch] - public enum NSLayoutFormatOptions : ulong { - AlignAllLeft = (1 << (int) NSLayoutAttribute.Left), - AlignAllRight = (1 << (int) NSLayoutAttribute.Right), - AlignAllTop = (1 << (int) NSLayoutAttribute.Top), - AlignAllBottom = (1 << (int) NSLayoutAttribute.Bottom), - AlignAllLeading = (1 << (int) NSLayoutAttribute.Leading), - AlignAllTrailing = (1 << (int) NSLayoutAttribute.Trailing), - AlignAllCenterX = (1 << (int) NSLayoutAttribute.CenterX), - AlignAllCenterY = (1 << (int) NSLayoutAttribute.CenterY), - AlignAllBaseline = (1 << (int) NSLayoutAttribute.Baseline), - AlignAllLastBaseline = (1 << (int) NSLayoutAttribute.LastBaseline), - AlignAllFirstBaseline = (1 << (int) NSLayoutAttribute.FirstBaseline), - - AlignmentMask = 0xFFFF, - - /* choose only one of these three - */ - DirectionLeadingToTrailing = 0 << 16, // default - DirectionLeftToRight = 1 << 16, - DirectionRightToLeft = 2 << 16, - - SpacingEdgeToEdge = 0 << 19, - SpacingBaselineToBaseline = 1 << 19, - SpacingMask = 1 << 19, - - DirectionMask = 0x3 << 16, - } - // float (and not even a CGFloat) -> NSLayoutConstraint.h // the API were fixed (a long time ago to use `float`) and the enum // values can still be used (and useful) since they will be casted @@ -1496,28 +1418,6 @@ public enum UIPushBehaviorMode : long { Instantaneous } - // NSInteger -> NSLayoutManager.h - [Native] - [NoWatch] - public enum NSGlyphProperty : long { - Null = (1 << 0), - ControlCharacter = (1 << 1), - Elastic = (1 << 2), - NonBaseCharacter = (1 << 3) - } - - // NSInteger -> NSLayoutManager.h - [Native] - [NoWatch] - public enum NSControlCharacterAction : long { - ZeroAdvancementAction = (1 << 0), - WhitespaceAction = (1 << 1), - HorizontalTabAction = (1 << 2), - LineBreakAction = (1 << 3), - ParagraphBreakAction = (1 << 4), - ContainerBreakAction = (1 << 5) - } - // NSInteger -> UITabBar.h [Native] [NoWatch] @@ -2602,31 +2502,6 @@ public enum UICollectionLayoutSectionOrthogonalScrollingBehavior : long { GroupPagingCentered, } - [Flags, Watch (6,0), TV (13,0), iOS (13,0)] - [Native] - public enum NSDirectionalRectEdge : ulong { - None = 0x0, - Top = 1uL << 0, - Leading = 1uL << 1, - Bottom = 1uL << 2, - Trailing = 1uL << 3, - All = Top | Leading | Bottom | Trailing, - } - - [Watch (6,0), TV (13,0), iOS (13,0)] - [Native] - public enum NSRectAlignment : long { - None = 0, - Top, - TopLeading, - Leading, - BottomLeading, - Bottom, - BottomTrailing, - Trailing, - TopTrailing, - } - [TV (13,0), NoWatch, iOS (13,0)] [Native] public enum UIAccessibilityContrast : long { @@ -3158,16 +3033,6 @@ public enum UINavigationItemBackButtonDisplayMode : long { Minimal = 2, } - [Watch (7,0), TV (14,0), iOS (14,0)] - [Flags] - [Native] - public enum NSLineBreakStrategy : ulong { - None = 0x0, - PushOut = 1uL << 0, - HangulWordPriority = 1uL << 1, - Standard = 0xffff, - } - // NSInteger -> UIGuidedAccessRestrictions.h [Native] [NoWatch] diff --git a/src/appkit.cs b/src/appkit.cs index 3d4dc2d4850d..309f113a23da 100644 --- a/src/appkit.cs +++ b/src/appkit.cs @@ -26341,18 +26341,6 @@ public enum NSCollectionLayoutSectionOrthogonalScrollingBehavior : long GroupPagingCentered, } - [Flags, Mac (10,15)] - [Native] - public enum NSDirectionalRectEdge : ulong - { - None = 0x0, - Top = 1uL << 0, - Leading = 1uL << 1, - Bottom = 1uL << 2, - Trailing = 1uL << 3, - All = Top | Leading | Bottom | Trailing, - } - [Mac (10,15)] [Native] public enum NSPickerTouchBarItemControlRepresentation : long @@ -26371,21 +26359,6 @@ public enum NSPickerTouchBarItemSelectionMode : long Momentary = 2, } - [Mac (10,15)] - [Native] - public enum NSRectAlignment : long - { - None = 0, - Top, - TopLeading, - Leading, - BottomLeading, - Bottom, - BottomTrailing, - Trailing, - TopTrailing, - } - [Mac (10,15)] [Native] public enum NSTextInputTraitType : long diff --git a/src/xkit.cs b/src/xkit.cs index eb6babca8608..71f5ab4efd87 100644 --- a/src/xkit.cs +++ b/src/xkit.cs @@ -82,6 +82,188 @@ namespace UIKit { delegate void NSTextLayoutEnumerateEnclosingRects (CGRect rect, ref bool stop); #endif + // NSInteger -> NSLayoutManager.h + [Native] + [Flags] + [NoWatch] + [Mac (10,11)] + [MacCatalyst (13,0)] + public enum NSControlCharacterAction : long { + ZeroAdvancement = (1 << 0), + Whitespace = (1 << 1), + HorizontalTab = (1 << 2), + LineBreak = (1 << 3), + ParagraphBreak = (1 << 4), + ContainerBreak = (1 << 5), + +#if !XAMCORE_4_0 && !__MACCATALYST__ && !MONOMAC + [Obsolete ("Use 'ZeroAdvancement' instead.")] + ZeroAdvancementAction = ZeroAdvancement, + [Obsolete ("Use 'Whitespace' instead.")] + WhitespaceAction = Whitespace, + [Obsolete ("Use 'HorizontalTab' instead.")] + HorizontalTabAction = HorizontalTab, + [Obsolete ("Use 'LineBreak' instead.")] + LineBreakAction = LineBreak, + [Obsolete ("Use 'ParagraphBreak' instead.")] + ParagraphBreakAction = ParagraphBreak, + [Obsolete ("Use 'ContainerBreak' instead.")] + ContainerBreakAction = ContainerBreak, +#endif + } + + [Mac (10,15), Watch (6,0), TV (13,0), iOS (13,0), MacCatalyst (13,0)] + [Flags] + [Native] + public enum NSDirectionalRectEdge : ulong + { + None = 0x0, + Top = 1uL << 0, + Leading = 1uL << 1, + Bottom = 1uL << 2, + Trailing = 1uL << 3, + All = Top | Leading | Bottom | Trailing, + } + + // NSInteger -> NSLayoutManager.h + [NoWatch] + [Mac (10,11)] + [MacCatalyst (13,0)] + [Native] + public enum NSGlyphProperty : long { + Null = (1 << 0), + ControlCharacter = (1 << 1), + Elastic = (1 << 2), + NonBaseCharacter = (1 << 3), + } + + // NSInteger -> NSLayoutConstraint.h + [Native] + [NoWatch] + [MacCatalyst (13,0)] + public enum NSLayoutAttribute : long { + NoAttribute = 0, + Left = 1, + Right, + Top, + Bottom, + Leading, + Trailing, + Width, + Height, + CenterX, + CenterY, + Baseline, + [Mac (10,11)] + LastBaseline = Baseline, + [Mac (10,11)] + FirstBaseline, + + [NoMac] + [iOS (8,0)] + LeftMargin, + [NoMac] + [iOS (8,0)] + RightMargin, + [NoMac] + [iOS (8,0)] + TopMargin, + [NoMac] + [iOS (8,0)] + BottomMargin, + [NoMac] + [iOS (8,0)] + LeadingMargin, + [NoMac] + [iOS (8,0)] + TrailingMargin, + [NoMac] + [iOS (8,0)] + CenterXWithinMargins, + [NoMac] + [iOS (8,0)] + CenterYWithinMargins, + } + + // NSUInteger -> NSLayoutConstraint.h + [Native] + [Flags] + [NoWatch] + [MacCatalyst (13,0)] + public enum NSLayoutFormatOptions : ulong { + None = 0, + + AlignAllLeft = (1 << (int) NSLayoutAttribute.Left), + AlignAllRight = (1 << (int) NSLayoutAttribute.Right), + AlignAllTop = (1 << (int) NSLayoutAttribute.Top), + AlignAllBottom = (1 << (int) NSLayoutAttribute.Bottom), + AlignAllLeading = (1 << (int) NSLayoutAttribute.Leading), + AlignAllTrailing = (1 << (int) NSLayoutAttribute.Trailing), + AlignAllCenterX = (1 << (int) NSLayoutAttribute.CenterX), + AlignAllCenterY = (1 << (int) NSLayoutAttribute.CenterY), + AlignAllBaseline = (1 << (int) NSLayoutAttribute.Baseline), + [Mac (10,11)] + AlignAllLastBaseline = (1 << (int) NSLayoutAttribute.LastBaseline), + [Mac (10,11)] + AlignAllFirstBaseline = (1 << (int) NSLayoutAttribute.FirstBaseline), + + AlignmentMask = 0xFFFF, + + /* choose only one of these three + */ + DirectionLeadingToTrailing = 0 << 16, // default + DirectionLeftToRight = 1 << 16, + DirectionRightToLeft = 2 << 16, + + [NoMac] + SpacingEdgeToEdge = 0 << 19, + [NoMac] + SpacingBaselineToBaseline = 1 << 19, + [NoMac] + SpacingMask = 1 << 19, + + DirectionMask = 0x3 << 16, + } + + // NSInteger -> UITextInput.h + [Native] + [NoWatch] + [MacCatalyst (13,0)] + public enum NSLayoutRelation : long { + LessThanOrEqual = -1, + Equal = 0, + GreaterThanOrEqual = 1, + } + + [Watch (7,0), TV (14,0), iOS (14,0)] + [Mac (11,0)] + [MacCatalyst (13,0)] + [Flags] + [Native] + public enum NSLineBreakStrategy : ulong { + None = 0x0, + PushOut = 1uL << 0, + HangulWordPriority = 1uL << 1, + Standard = 0xffff, + } + + [Watch (6,0), TV (13,0), iOS (13,0)] + [Mac (10,15)] + [MacCatalyst (13,0)] + [Native] + public enum NSRectAlignment : long + { + None = 0, + Top, + TopLeading, + Leading, + BottomLeading, + Bottom, + BottomTrailing, + Trailing, + TopTrailing, + } + [NoWatch] // Header is not present in watchOS SDK. [iOS (7,0)] [DesignatedDefaultCtor]