mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-06-18 20:06:19 +08:00
Added baseline spacing for vertical stack views.
This commit is contained in:
@@ -356,8 +356,8 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
}
|
||||
});
|
||||
|
||||
self.ascender = [[attributedString attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL] ascender];
|
||||
self.descender = [[attributedString attribute:NSFontAttributeName atIndex:attributedString.length - 1 effectiveRange:NULL] descender];
|
||||
self.ascender = round([[attributedString attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL] ascender] * [UIScreen mainScreen].scale)/[UIScreen mainScreen].scale;
|
||||
self.descender = round([[attributedString attribute:NSFontAttributeName atIndex:attributedString.length - 1 effectiveRange:NULL] descender] * [UIScreen mainScreen].scale)/[UIScreen mainScreen].scale;
|
||||
}
|
||||
|
||||
#pragma mark - Text Layout
|
||||
|
||||
@@ -62,6 +62,10 @@ typedef struct {
|
||||
ASStackLayoutJustifyContent justifyContent;
|
||||
/** Orientation of children along cross axis */
|
||||
ASStackLayoutAlignItems alignItems;
|
||||
/**
|
||||
If YES the vertical spacing between two views is measured from the last baseline of the
|
||||
top view to the top of the bottom view*/
|
||||
BOOL baselineRelativeArrangement;
|
||||
} ASStackLayoutSpecStyle;
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,11 +20,13 @@
|
||||
#import "ASStackLayoutSpecUtilities.h"
|
||||
#import "ASStackPositionedLayout.h"
|
||||
#import "ASStackUnpositionedLayout.h"
|
||||
#import "ASThread.h"
|
||||
|
||||
@implementation ASStackLayoutSpec
|
||||
{
|
||||
ASStackLayoutSpecStyle _style;
|
||||
std::vector<id<ASLayoutable>> _children;
|
||||
ASDN::RecursiveMutex _propertyLock;
|
||||
}
|
||||
|
||||
+ (instancetype)newWithStyle:(ASStackLayoutSpecStyle)style children:(NSArray *)children
|
||||
@@ -51,6 +53,11 @@
|
||||
const auto positionedLayout = ASStackPositionedLayout::compute(unpositionedLayout, _style, constrainedSize);
|
||||
const CGSize finalSize = directionSize(_style.direction, unpositionedLayout.stackDimensionSum, positionedLayout.crossSize);
|
||||
NSArray *sublayouts = [NSArray arrayWithObjects:&positionedLayout.sublayouts[0] count:positionedLayout.sublayouts.size()];
|
||||
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
self.ascender = positionedLayout.ascender;
|
||||
self.descender = positionedLayout.desender;
|
||||
|
||||
return [ASLayout newWithLayoutableObject:self
|
||||
size:ASSizeRangeClamp(constrainedSize, finalSize)
|
||||
sublayouts:sublayouts];
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
struct ASStackPositionedLayout {
|
||||
const std::vector<ASLayout *> sublayouts;
|
||||
const CGFloat crossSize;
|
||||
const CGFloat ascender;
|
||||
const CGFloat desender;
|
||||
|
||||
/** Given an unpositioned layout, computes the positions each child should be placed at. */
|
||||
static ASStackPositionedLayout compute(const ASStackUnpositionedLayout &unpositionedLayout,
|
||||
|
||||
@@ -77,10 +77,12 @@ static ASStackPositionedLayout stackedLayout(const ASStackLayoutSpecStyle &style
|
||||
}
|
||||
first = NO;
|
||||
l.layout.position = p + directionPoint(style.direction, 0, crossOffset(style, l, crossSize, maxBaseLine));
|
||||
p = p + directionPoint(style.direction, stackDimension(style.direction, l.layout.size) + l.child.spacingAfter, 0);
|
||||
|
||||
CGFloat spacingAfterBaseline = (style.direction == ASStackLayoutDirectionVertical && style.baselineRelativeArrangement) ? l.child.descender : 0;;
|
||||
p = p + directionPoint(style.direction, stackDimension(style.direction, l.layout.size) + l.child.spacingAfter + spacingAfterBaseline, 0);
|
||||
return l.layout;
|
||||
});
|
||||
return {stackedChildren, crossSize};
|
||||
return {stackedChildren, crossSize, maxBaseLine, maxBaseLine == 0 ? 0 : crossSize - maxBaseLine};
|
||||
}
|
||||
|
||||
ASStackPositionedLayout ASStackPositionedLayout::compute(const ASStackUnpositionedLayout &unpositionedLayout,
|
||||
|
||||
Reference in New Issue
Block a user