FLEXMacros.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // FLEXMacros.h
  3. // FLEX
  4. //
  5. // Created by Tanner on 3/12/20.
  6. // Copyright © 2020 Flipboard. All rights reserved.
  7. //
  8. #ifndef FLEXMacros_h
  9. #define FLEXMacros_h
  10. // Used to prevent loading of pre-registered shortcuts and runtime categories in a test environment
  11. #define FLEX_EXIT_IF_TESTING() if (NSClassFromString(@"XCTest")) return;
  12. /// Rounds down to the nearest "point" coordinate
  13. NS_INLINE CGFloat FLEXFloor(CGFloat x) {
  14. return floor(UIScreen.mainScreen.scale * (x)) / UIScreen.mainScreen.scale;
  15. }
  16. /// Returns the given number of points in pixels
  17. NS_INLINE CGFloat FLEXPointsToPixels(CGFloat points) {
  18. return points / UIScreen.mainScreen.scale;
  19. }
  20. /// Creates a CGRect with all members rounded down to the nearest "point" coordinate
  21. NS_INLINE CGRect FLEXRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) {
  22. return CGRectMake(FLEXFloor(x), FLEXFloor(y), FLEXFloor(width), FLEXFloor(height));
  23. }
  24. /// Adjusts the origin of an existing rect
  25. NS_INLINE CGRect FLEXRectSetOrigin(CGRect r, CGPoint origin) {
  26. r.origin = origin; return r;
  27. }
  28. /// Adjusts the size of an existing rect
  29. NS_INLINE CGRect FLEXRectSetSize(CGRect r, CGSize size) {
  30. r.size = size; return r;
  31. }
  32. /// Adjusts the origin.x of an existing rect
  33. NS_INLINE CGRect FLEXRectSetX(CGRect r, CGFloat x) {
  34. r.origin.x = x; return r;
  35. }
  36. /// Adjusts the origin.y of an existing rect
  37. NS_INLINE CGRect FLEXRectSetY(CGRect r, CGFloat y) {
  38. r.origin.y = y ; return r;
  39. }
  40. /// Adjusts the size.width of an existing rect
  41. NS_INLINE CGRect FLEXRectSetWidth(CGRect r, CGFloat width) {
  42. r.size.width = width; return r;
  43. }
  44. /// Adjusts the size.height of an existing rect
  45. NS_INLINE CGRect FLEXRectSetHeight(CGRect r, CGFloat height) {
  46. r.size.height = height; return r;
  47. }
  48. #ifdef __IPHONE_13_0
  49. #define FLEX_AT_LEAST_IOS13_SDK (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0)
  50. #else
  51. #define FLEX_AT_LEAST_IOS13_SDK NO
  52. #endif
  53. #define FLEXPluralString(count, plural, singular) [NSString \
  54. stringWithFormat:@"%@ %@", @(count), (count == 1 ? singular : plural) \
  55. ]
  56. #define FLEXPluralFormatString(count, pluralFormat, singularFormat) [NSString \
  57. stringWithFormat:(count == 1 ? singularFormat : pluralFormat), @(count) \
  58. ]
  59. #endif /* FLEXMacros_h */