FLEXMacros.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // FLEXMacros.h
  3. // FLEX
  4. //
  5. // Created by Tanner on 3/12/20.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #ifndef FLEXMacros_h
  9. #define FLEXMacros_h
  10. #define flex_keywordify class NSObject;
  11. #define ctor flex_keywordify __attribute__((constructor)) void __flex_ctor_##__LINE__()
  12. #define dtor flex_keywordify __attribute__((destructor)) void __flex_dtor_##__LINE__()
  13. // A macro to check if we are running in a test environment
  14. #define FLEX_IS_TESTING() (NSClassFromString(@"XCTest") != nil)
  15. /// Whether we want the majority of constructors to run upon load or not.
  16. extern BOOL FLEXConstructorsShouldRun(void);
  17. /// A macro to return from the current procedure if we don't want to run constructors
  18. #define FLEX_EXIT_IF_NO_CTORS() if (!FLEXConstructorsShouldRun()) return;
  19. /// Rounds down to the nearest "point" coordinate
  20. NS_INLINE CGFloat FLEXFloor(CGFloat x) {
  21. return floor(UIScreen.mainScreen.scale * (x)) / UIScreen.mainScreen.scale;
  22. }
  23. /// Returns the given number of points in pixels
  24. NS_INLINE CGFloat FLEXPointsToPixels(CGFloat points) {
  25. return points / UIScreen.mainScreen.scale;
  26. }
  27. /// Creates a CGRect with all members rounded down to the nearest "point" coordinate
  28. NS_INLINE CGRect FLEXRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) {
  29. return CGRectMake(FLEXFloor(x), FLEXFloor(y), FLEXFloor(width), FLEXFloor(height));
  30. }
  31. /// Adjusts the origin of an existing rect
  32. NS_INLINE CGRect FLEXRectSetOrigin(CGRect r, CGPoint origin) {
  33. r.origin = origin; return r;
  34. }
  35. /// Adjusts the size of an existing rect
  36. NS_INLINE CGRect FLEXRectSetSize(CGRect r, CGSize size) {
  37. r.size = size; return r;
  38. }
  39. /// Adjusts the origin.x of an existing rect
  40. NS_INLINE CGRect FLEXRectSetX(CGRect r, CGFloat x) {
  41. r.origin.x = x; return r;
  42. }
  43. /// Adjusts the origin.y of an existing rect
  44. NS_INLINE CGRect FLEXRectSetY(CGRect r, CGFloat y) {
  45. r.origin.y = y ; return r;
  46. }
  47. /// Adjusts the size.width of an existing rect
  48. NS_INLINE CGRect FLEXRectSetWidth(CGRect r, CGFloat width) {
  49. r.size.width = width; return r;
  50. }
  51. /// Adjusts the size.height of an existing rect
  52. NS_INLINE CGRect FLEXRectSetHeight(CGRect r, CGFloat height) {
  53. r.size.height = height; return r;
  54. }
  55. #ifdef __IPHONE_13_0
  56. #define FLEX_AT_LEAST_IOS13_SDK (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0)
  57. #else
  58. #define FLEX_AT_LEAST_IOS13_SDK NO
  59. #endif
  60. #define FLEXPluralString(count, plural, singular) [NSString \
  61. stringWithFormat:@"%@ %@", @(count), (count == 1 ? singular : plural) \
  62. ]
  63. #define FLEXPluralFormatString(count, pluralFormat, singularFormat) [NSString \
  64. stringWithFormat:(count == 1 ? singularFormat : pluralFormat), @(count) \
  65. ]
  66. #define flex_dispatch_after(nSeconds, onQueue, block) \
  67. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, \
  68. (int64_t)(nSeconds * NSEC_PER_SEC)), onQueue, block)
  69. #define DLog(format, ...) CFShow((__bridge CFStringRef)[NSString stringWithFormat:format, ## __VA_ARGS__]);
  70. #define LOG_SELF NSLog(@"[FLEXLog] %@ %@", self, NSStringFromSelector(_cmd))
  71. #define FXLog(format, ...) NSLog(@"[FLEXLog] %@",[NSString stringWithFormat:format, ## __VA_ARGS__]);
  72. #define DLOG_SELF DLog(@"%@ %@", self, NSStringFromSelector(_cmd))
  73. #endif /* FLEXMacros_h */