moved baseline alignment to a layout spec.

This commit is contained in:
ricky cancro
2015-08-20 10:38:54 -07:00
committed by rcancro
parent 9036ab8e7d
commit 2d6ddfe32e
7 changed files with 243 additions and 144 deletions

View File

@@ -1,35 +1,48 @@
//
// ASStackTextLayoutSpec.h
// AsyncDisplayKit
//
// Created by ricky cancro on 8/19/15.
// Copyright (c) 2015 Facebook. All rights reserved.
//
/*
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#import <AsyncDisplayKit/ASStackLayoutSpec.h>
/** Orientation of children along cross axis */
typedef NS_ENUM(NSUInteger, ASStackTextLayoutBaselineAlignment) {
ASStackTextLayoutBaselineAlignmentNone,
/** Children align along the first baseline of the stack. Only available for horizontal stack nodes */
ASStackTextLayoutBaselineAlignmentFirst,
/** Children align along the last baseline of the stack. Only available for horizontal stack nodes */
ASStackTextLayoutBaselineAlignmentLast,
/** No baseline alignment. This is only valid for a vertical stack */
ASStackTextLayoutBaselineAlignmentNone,
/** Align all children to the first baseline. This is only valid for a horizontal stack */
ASStackTextLayoutBaselineAlignmentFirst,
/** Align all children to the last baseline. This is useful when a text node wraps and you want to align
to the bottom baseline. This is only valid for a horizontal stack */
ASStackTextLayoutBaselineAlignmentLast,
};
typedef struct {
/** Specifies the direction children are stacked in. */
ASStackLayoutSpecStyle stackLayoutStyle;
ASStackTextLayoutBaselineAlignment baselineAlignment;
/** Describes how the stack will be laid out */
ASStackLayoutSpecStyle stackLayoutStyle;
/** The type of baseline alignment */
ASStackTextLayoutBaselineAlignment baselineAlignment;
} ASStackTextLayoutSpecStyle;
@interface ASStackTextLayoutSpec : ASLayoutSpec
/**
A specialized version of a stack layout that aligns its children on a baseline. This spec only works with
ASStackTextLayoutable children.
If the spec is created with a horizontal direction, the children will be laid on a common baseline.
If the spec is created with a vertical direction, a child's vertical spacing will be measured from its
baseline instead of from the child's bounding box.
*/
@interface ASStackTextLayoutSpec : ASLayoutSpec <ASStackTextLayoutable>
/**
@param style Specifies how children are laid out.
@param children ASLayoutable children to be positioned.
@param children ASTextLayoutable children to be positioned.
*/
+ (instancetype)newWithStyle:(ASStackTextLayoutSpecStyle)style children:(NSArray *)children;