Fixes to baseline stack alignment

1) Set the ascender/descender of an ASTextNode when the attributeString is set. Previously ascender/descender were only being computed in `setValuesFromLayoutable` and only when the attribute string was not nil. May make sense to remove the computation from `setValuesFromLayoutable` entirely.
2) Remove ability to allow different children of a stack spec to aling to different baselines. This wasn't working before and I'm not convinced it is possible to do properly/useful enough to invest the time.
3) Have all stack spec run `ASStackBaselinePositionedLayout::compute` to compute the stack's ascender and descender. Even if the stack isn't aligning its children to a baseline, the stack itself may be a child of another stack that IS aligning to a baseline.
This commit is contained in:
ricky cancro
2015-10-06 21:41:39 -07:00
parent e41f7c59c4
commit 89a216b90d
5 changed files with 56 additions and 42 deletions

View File

@@ -101,7 +101,6 @@
std::vector<id<ASLayoutable>> stackChildren = std::vector<id<ASLayoutable>>();
for (id<ASLayoutable> child in self.children) {
stackChildren.push_back(child);
needsBaselinePass |= child.alignSelf == ASStackLayoutAlignSelfBaselineFirst || child.alignSelf == ASStackLayoutAlignSelfBaselineLast;
}
const auto unpositionedLayout = ASStackUnpositionedLayout::compute(stackChildren, style, constrainedSize);
@@ -109,12 +108,21 @@
CGSize finalSize = CGSizeZero;
NSArray *sublayouts = nil;
if (needsBaselinePass) {
const auto baselinePositionedLayout = ASStackBaselinePositionedLayout::compute(positionedLayout, style, constrainedSize);
// regardless of whether or not this stack aligns to baseline, we should let ASStackBaselinePositionedLayout::compute find the max ascender
// and min descender in case this spec is a child in another spec that wants to align to a baseline.
const auto baselinePositionedLayout = ASStackBaselinePositionedLayout::compute(positionedLayout, style, constrainedSize);
if (self.direction == ASStackLayoutDirectionVertical) {
ASDN::MutexLocker l(_propertyLock);
self.ascender = [[self.children firstObject] ascender];
self.descender = [[self.children lastObject] descender];
} else {
ASDN::MutexLocker l(_propertyLock);
self.ascender = baselinePositionedLayout.ascender;
self.descender = baselinePositionedLayout.descender;
}
if (needsBaselinePass) {
finalSize = directionSize(style.direction, unpositionedLayout.stackDimensionSum, baselinePositionedLayout.crossSize);
sublayouts = [NSArray arrayWithObjects:&baselinePositionedLayout.sublayouts[0] count:baselinePositionedLayout.sublayouts.size()];
} else {