|
13 | 13 |
|
14 | 14 | @protocol ASLayoutable; |
15 | 15 |
|
| 16 | +/** |
| 17 | + * A store for all of the options defined by ASLayoutSpec subclasses. All implementors of ASLayoutable own a |
| 18 | + * ASLayoutOptions. When certain layoutSpecs need option values, they are read from this class. |
| 19 | + * |
| 20 | + * Unless you wish to create a custom layout spec, ASLayoutOptions can largerly be ignored. Instead you can access |
| 21 | + * the layout option properties exposed in ASLayoutable directly, which will set the values in ASLayoutOptions |
| 22 | + * behind the scenes. |
| 23 | + */ |
16 | 24 | @interface ASLayoutOptions : NSObject <ASStackLayoutable, ASStaticLayoutable, NSCopying> |
17 | 25 |
|
| 26 | +/** |
| 27 | + * Sets the class name for the ASLayoutOptions subclasses that will be created when a node or layoutSpec's options |
| 28 | + * are first accessed. |
| 29 | + * |
| 30 | + * If you create a custom layoutSpec that includes new options, you will want to subclass ASLayoutOptions to add |
| 31 | + * the new layout options for your layoutSpec(s). In order to make sure your subclass is created instead of an |
| 32 | + * instance of ASLayoutOptions, call setDefaultLayoutOptionsClass: early in app launch (applicationDidFinishLaunching:) |
| 33 | + * with your subclass's class. |
| 34 | + * |
| 35 | + * @param defaultLayoutOptionsClass The class of ASLayoutOptions that will be lazily created for a node or layout spec. |
| 36 | + */ |
18 | 37 | + (void)setDefaultLayoutOptionsClass:(Class)defaultLayoutOptionsClass; |
| 38 | + |
| 39 | +/** |
| 40 | + * @return the Class of ASLayoutOptions that will be created for a node or layoutspec. Defaults to [ASLayoutOptions class]; |
| 41 | + */ |
19 | 42 | + (Class)defaultLayoutOptionsClass; |
20 | 43 |
|
| 44 | +#pragma mark - Subclasses should implement these! |
| 45 | +/** |
| 46 | + * Initializes a new ASLayoutOptions using the given layoutable to assign any intrinsic option values. |
| 47 | + * This init function sets a sensible default value for each layout option. If you create a subclass of |
| 48 | + * ASLayoutOptions, your subclass should do the same. |
| 49 | + * |
| 50 | + * @param layoutable The layoutable that will own these options. The layoutable will be used to set any intrinsic |
| 51 | + * layoutOptions. For example, if the layoutable is an ASTextNode the ascender/descender values will get set. |
| 52 | + * |
| 53 | + * @return a new instance of ASLayoutOptions |
| 54 | + */ |
21 | 55 | - (instancetype)initWithLayoutable:(id<ASLayoutable>)layoutable; |
22 | | -- (void)setValuesFromLayoutable:(id<ASLayoutable>)layoutable; |
23 | 56 |
|
24 | | -#pragma mark - Subclasses should implement these! |
25 | | -- (void)propagateOptionsFromLayoutOptions:(ASLayoutOptions *)layoutOptions; |
| 57 | +/** |
| 58 | + * Copies the values of layoutOptions into self. This is useful when placing a layoutable inside of another. Consider |
| 59 | + * an ASTextNode that you want to align to the baseline by putting it in an ASStackLayoutSpec. Before that, you want |
| 60 | + * to inset the ASTextNode by placing it in an ASInsetLayoutSpec. An ASInsetLayoutSpec will not have any information |
| 61 | + * about the ASTextNode's ascender/descender unless we copy over the layout options from ASTextNode to ASInsetLayoutSpec. |
| 62 | + * This is done automatically and should not need to be called directly. It is listed here to make sure that any |
| 63 | + * ASLayoutOptions subclass implements the method. |
| 64 | + * |
| 65 | + * @param layoutOptions The layoutOptions to copy from |
| 66 | + */ |
| 67 | +- (void)copyIntoOptions:(ASLayoutOptions *)layoutOptions; |
26 | 68 |
|
27 | 69 | #pragma mark - ASStackLayoutable |
28 | 70 |
|
|
0 commit comments