Files
MapLibreParticleLab/platform/darwin/src/MLNAttributedExpression.h
mwilsnd 20d9e1028c Platform flattening overhaul (#1393)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
2023-07-26 17:50:34 +02:00

88 lines
3.6 KiB
Objective-C

#import "MLNFoundation.h"
NS_ASSUME_NONNULL_BEGIN
/** Options for `MLNAttributedExpression.attributes`. */
typedef NSString * MLNAttributedExpressionKey NS_TYPED_ENUM;
/** The font name string array expression used to format the text. */
FOUNDATION_EXTERN MLN_EXPORT MLNAttributedExpressionKey const MLNFontNamesAttribute;
/** The font scale number expression relative to `MLNSymbolStyleLayer.textFontSize` used to format the text. */
FOUNDATION_EXTERN MLN_EXPORT MLNAttributedExpressionKey const MLNFontScaleAttribute;
/** The font color expression used to format the text. */
FOUNDATION_EXTERN MLN_EXPORT MLNAttributedExpressionKey const MLNFontColorAttribute;
/**
An `MLNAttributedExpression` object associates text formatting attibutes (such as font size or
font names) to an `NSExpression`.
### Example
```swift
let redColor = UIColor.red
let expression = NSExpression(forConstantValue: "Foo")
let attributes: [MLNAttributedExpressionKey: NSExpression] = [.fontNamesAttribute : NSExpression(forConstantValue: ["DIN Offc Pro Italic",
"Arial Unicode MS Regular"]),
.fontScaleAttribute: NSExpression(forConstantValue: 1.2),
.fontColorAttribute: NSExpression(forConstantValue: redColor)]
let attributedExpression = MLNAttributedExpression(expression, attributes:attributes)
```
*/
MLN_EXPORT
@interface MLNAttributedExpression : NSObject
/**
The expression content of the receiver as `NSExpression`.
*/
@property (strong, nonatomic) NSExpression *expression;
#if TARGET_OS_IPHONE
/**
The formatting attributes dictionary.
Key | Value Type
--- | ---
`MLNFontNamesAttribute` | An `NSExpression` evaluating to an `NSString` array.
`MLNFontScaleAttribute` | An `NSExpression` evaluating to an `NSNumber` value.
`MLNFontColorAttribute` | An `NSExpression` evaluating to an `UIColor`.
*/
@property (strong, nonatomic, readonly) NSDictionary<MLNAttributedExpressionKey, NSExpression *> *attributes;
#else
/**
The formatting attributes dictionary.
Key | Value Type
--- | ---
`MLNFontNamesAttribute` | An `NSExpression` evaluating to an `NSString` array.
`MLNFontScaleAttribute` | An `NSExpression` evaluating to an `NSNumber` value.
`MLNFontColorAttribute` | An `NSExpression` evaluating to an `NSColor` on macos.
*/
@property (strong, nonatomic, readonly) NSDictionary<MLNAttributedExpressionKey, NSExpression *> *attributes;
#endif
/**
Returns an `MLNAttributedExpression` object initialized with an expression and no attribute information.
*/
- (instancetype)initWithExpression:(NSExpression *)expression;
/**
Returns an `MLNAttributedExpression` object initialized with an expression and text format attributes.
*/
- (instancetype)initWithExpression:(NSExpression *)expression attributes:(nonnull NSDictionary <MLNAttributedExpressionKey, NSExpression *> *)attrs;
/**
Creates an `MLNAttributedExpression` object initialized with an expression and the format attributes for font names and font size.
*/
+ (instancetype)attributedExpression:(NSExpression *)expression fontNames:(nullable NSArray<NSString*> *)fontNames fontScale:(nullable NSNumber *)fontScale;
/**
Creates an `MLNAttributedExpression` object initialized with an expression and the format attributes dictionary.
*/
+ (instancetype)attributedExpression:(NSExpression *)expression attributes:(nonnull NSDictionary <MLNAttributedExpressionKey, NSExpression *> *)attrs;
@end
NS_ASSUME_NONNULL_END