PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/XM_Bike/PureLayout/PureLayoutDefines.h

https://gitlab.com/dingchuandong1/XM_Bick
C Header | 224 lines | 121 code | 21 blank | 82 comment | 5 complexity | 6db365064ac3059f7097d7d22187b030 MD5 | raw file
  1. //
  2. // PureLayoutDefines.h
  3. // https://github.com/smileyborg/PureLayout
  4. //
  5. // Copyright (c) 2014-2015 Tyler Fox
  6. //
  7. // This code is distributed under the terms and conditions of the MIT license.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to
  11. // deal in the Software without restriction, including without limitation the
  12. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  13. // sell copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  25. // IN THE SOFTWARE.
  26. //
  27. #ifndef PureLayoutDefines_h
  28. #define PureLayoutDefines_h
  29. #import <Foundation/Foundation.h>
  30. // Define some preprocessor macros to check for a minimum Base SDK. These are used to prevent compile-time errors in older versions of Xcode.
  31. #define __PureLayout_MinBaseSDK_iOS_8_0 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1)
  32. #define __PureLayout_MinBaseSDK_OSX_10_10 (!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9)
  33. // Define some preprocessor macros to check for a minimum System Version. These are used to prevent runtime crashes on older versions of iOS/OS X.
  34. #define __PureLayout_MinSysVer_iOS_7_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
  35. #define __PureLayout_MinSysVer_iOS_8_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
  36. #define __PureLayout_MinSysVer_OSX_10_9 (!TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4)
  37. // Define some preprocessor macros that allow nullability annotations to be adopted in a backwards-compatible manner.
  38. #if __has_feature(nullability)
  39. # define __PL_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
  40. # define __PL_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
  41. #else
  42. # define __PL_ASSUME_NONNULL_BEGIN
  43. # define __PL_ASSUME_NONNULL_END
  44. #endif
  45. // Define some preprocessor macros that allow generics to be adopted in a backwards-compatible manner.
  46. #if __has_feature(objc_generics)
  47. # define __PL_GENERICS(class, ...) class<__VA_ARGS__>
  48. #else
  49. # define __PL_GENERICS(class, ...) class
  50. #endif
  51. // Using generics with NSArray is so common in PureLayout that it gets a dedicated preprocessor macro for better readability.
  52. #define __NSArray_of(type) __PL_GENERICS(NSArray, type)
  53. // Define generic AL-prefixed macros for the types/constants/etc that have slight naming variations across iOS and OS X, which allows the same code to be platform-independent.
  54. #if TARGET_OS_IPHONE
  55. # import <UIKit/UIKit.h>
  56. # define ALView UIView
  57. # define ALEdgeInsets UIEdgeInsets
  58. # define ALEdgeInsetsZero UIEdgeInsetsZero
  59. # define ALEdgeInsetsMake UIEdgeInsetsMake
  60. # define ALLayoutConstraintAxis UILayoutConstraintAxis
  61. # define ALLayoutConstraintOrientation ALLayoutConstraintAxis
  62. # define ALLayoutConstraintAxisHorizontal UILayoutConstraintAxisHorizontal
  63. # define ALLayoutConstraintAxisVertical UILayoutConstraintAxisVertical
  64. # define ALLayoutConstraintOrientationHorizontal ALLayoutConstraintAxisHorizontal
  65. # define ALLayoutConstraintOrientationVertical ALLayoutConstraintAxisVertical
  66. # define ALLayoutPriority UILayoutPriority
  67. # define ALLayoutPriorityRequired UILayoutPriorityRequired
  68. # define ALLayoutPriorityDefaultHigh UILayoutPriorityDefaultHigh
  69. # define ALLayoutPriorityDefaultLow UILayoutPriorityDefaultLow
  70. # define ALLayoutPriorityFittingSizeLevel UILayoutPriorityFittingSizeLevel
  71. # define ALLayoutPriorityFittingSizeCompression ALLayoutPriorityFittingSizeLevel
  72. #else
  73. # import <Cocoa/Cocoa.h>
  74. # define ALView NSView
  75. # define ALEdgeInsets NSEdgeInsets
  76. # define ALEdgeInsetsZero NSEdgeInsetsMake(0, 0, 0, 0)
  77. # define ALEdgeInsetsMake NSEdgeInsetsMake
  78. # define ALLayoutConstraintOrientation NSLayoutConstraintOrientation
  79. # define ALLayoutConstraintAxis ALLayoutConstraintOrientation
  80. # define ALLayoutConstraintOrientationHorizontal NSLayoutConstraintOrientationHorizontal
  81. # define ALLayoutConstraintOrientationVertical NSLayoutConstraintOrientationVertical
  82. # define ALLayoutConstraintAxisHorizontal ALLayoutConstraintOrientationHorizontal
  83. # define ALLayoutConstraintAxisVertical ALLayoutConstraintOrientationVertical
  84. # define ALLayoutPriority NSLayoutPriority
  85. # define ALLayoutPriorityRequired NSLayoutPriorityRequired
  86. # define ALLayoutPriorityDefaultHigh NSLayoutPriorityDefaultHigh
  87. # define ALLayoutPriorityDefaultLow NSLayoutPriorityDefaultLow
  88. # define ALLayoutPriorityFittingSizeCompression NSLayoutPriorityFittingSizeCompression
  89. # define ALLayoutPriorityFittingSizeLevel ALLayoutPriorityFittingSizeCompression
  90. #endif /* TARGET_OS_IPHONE */
  91. #pragma mark PureLayout Attributes
  92. /** Constants that represent edges of a view. */
  93. typedef NS_ENUM(NSInteger, ALEdge) {
  94. /** The left edge of the view. */
  95. ALEdgeLeft = NSLayoutAttributeLeft,
  96. /** The right edge of the view. */
  97. ALEdgeRight = NSLayoutAttributeRight,
  98. /** The top edge of the view. */
  99. ALEdgeTop = NSLayoutAttributeTop,
  100. /** The bottom edge of the view. */
  101. ALEdgeBottom = NSLayoutAttributeBottom,
  102. /** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */
  103. ALEdgeLeading = NSLayoutAttributeLeading,
  104. /** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */
  105. ALEdgeTrailing = NSLayoutAttributeTrailing
  106. };
  107. /** Constants that represent dimensions of a view. */
  108. typedef NS_ENUM(NSInteger, ALDimension) {
  109. /** The width of the view. */
  110. ALDimensionWidth = NSLayoutAttributeWidth,
  111. /** The height of the view. */
  112. ALDimensionHeight = NSLayoutAttributeHeight
  113. };
  114. /** Constants that represent axes of a view. */
  115. typedef NS_ENUM(NSInteger, ALAxis) {
  116. /** A vertical line equidistant from the view's left and right edges. */
  117. ALAxisVertical = NSLayoutAttributeCenterX,
  118. /** A horizontal line equidistant from the view's top and bottom edges. */
  119. ALAxisHorizontal = NSLayoutAttributeCenterY,
  120. /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */
  121. ALAxisBaseline = NSLayoutAttributeBaseline,
  122. /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */
  123. ALAxisLastBaseline = ALAxisBaseline,
  124. #if __PureLayout_MinBaseSDK_iOS_8_0
  125. /** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */
  126. ALAxisFirstBaseline = NSLayoutAttributeFirstBaseline
  127. #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
  128. };
  129. #if __PureLayout_MinBaseSDK_iOS_8_0
  130. /** Constants that represent layout margins of a view. Available in iOS 8.0 and later. */
  131. typedef NS_ENUM(NSInteger, ALMargin) {
  132. /** The left margin of the view, based on the view's layoutMargins left inset. */
  133. ALMarginLeft = NSLayoutAttributeLeftMargin,
  134. /** The right margin of the view, based on the view's layoutMargins right inset. */
  135. ALMarginRight = NSLayoutAttributeRightMargin,
  136. /** The top margin of the view, based on the view's layoutMargins top inset. */
  137. ALMarginTop = NSLayoutAttributeTopMargin,
  138. /** The bottom margin of the view, based on the view's layoutMargins bottom inset. */
  139. ALMarginBottom = NSLayoutAttributeBottomMargin,
  140. /** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
  141. ALMarginLeading = NSLayoutAttributeLeadingMargin,
  142. /** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
  143. ALMarginTrailing = NSLayoutAttributeTrailingMargin
  144. };
  145. /** Constants that represent axes of the layout margins of a view. Available in iOS 8.0 and later. */
  146. typedef NS_ENUM(NSInteger, ALMarginAxis) {
  147. /** A vertical line equidistant from the view's left and right margins. */
  148. ALMarginAxisVertical = NSLayoutAttributeCenterXWithinMargins,
  149. /** A horizontal line equidistant from the view's top and bottom margins. */
  150. ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins
  151. };
  152. #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
  153. /** An attribute of a view that can be used in auto layout constraints. These constants are identical to the more specific enum types:
  154. ALEdge, ALAxis, ALDimension, ALMargin, ALMarginAxis. It is safe to cast a more specific enum type to the ALAttribute type. */
  155. typedef NS_ENUM(NSInteger, ALAttribute) {
  156. /** The left edge of the view. */
  157. ALAttributeLeft = ALEdgeLeft,
  158. /** The right edge of the view. */
  159. ALAttributeRight = ALEdgeRight,
  160. /** The top edge of the view. */
  161. ALAttributeTop = ALEdgeTop,
  162. /** The bottom edge of the view. */
  163. ALAttributeBottom = ALEdgeBottom,
  164. /** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */
  165. ALAttributeLeading = ALEdgeLeading,
  166. /** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */
  167. ALAttributeTrailing = ALEdgeTrailing,
  168. /** The width of the view. */
  169. ALAttributeWidth = ALDimensionWidth,
  170. /** The height of the view. */
  171. ALAttributeHeight = ALDimensionHeight,
  172. /** A vertical line equidistant from the view's left and right edges. */
  173. ALAttributeVertical = ALAxisVertical,
  174. /** A horizontal line equidistant from the view's top and bottom edges. */
  175. ALAttributeHorizontal = ALAxisHorizontal,
  176. /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */
  177. ALAttributeBaseline = ALAxisBaseline,
  178. /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */
  179. ALAttributeLastBaseline = ALAxisLastBaseline,
  180. #if __PureLayout_MinBaseSDK_iOS_8_0
  181. /** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */
  182. ALAttributeFirstBaseline = ALAxisFirstBaseline,
  183. /** The left margin of the view, based on the view's layoutMargins left inset. */
  184. ALAttributeMarginLeft = ALMarginLeft,
  185. /** The right margin of the view, based on the view's layoutMargins right inset. */
  186. ALAttributeMarginRight = ALMarginRight,
  187. /** The top margin of the view, based on the view's layoutMargins top inset. */
  188. ALAttributeMarginTop = ALMarginTop,
  189. /** The bottom margin of the view, based on the view's layoutMargins bottom inset. */
  190. ALAttributeMarginBottom = ALMarginBottom,
  191. /** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
  192. ALAttributeMarginLeading = ALMarginLeading,
  193. /** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
  194. ALAttributeMarginTrailing = ALMarginTrailing,
  195. /** A vertical line equidistant from the view's left and right margins. */
  196. ALAttributeMarginAxisVertical = ALMarginAxisVertical,
  197. /** A horizontal line equidistant from the view's top and bottom margins. */
  198. ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal
  199. #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
  200. };
  201. /** A block containing method calls to the PureLayout API. Takes no arguments and has no return value. */
  202. typedef void(^ALConstraintsBlock)(void);
  203. #endif /* PureLayoutDefines_h */