mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
[Layout] Add style property to ASLayoutable (#2261)
* Add style property to ASLayoutable * Add styles property to further layout specs * Adjust some examples * Add `loadStyle` to create the style object in a ASLayoutable * Revert "Add `loadStyle` to create the style object in a ASLayoutable" This reverts commit 2b7240f2c7dc993e38cadf290cfdf08482dd70c7. * Revert "Adjust some examples" This reverts commit 3254ae0a321e75db3ecfa80adee9d96bde93a33d. * Revert "Add styles property to further layout specs" This reverts commit c779dcb876ead27122c1af1300146a6ad36912cb. * Rename ASLayoutableStyleDeclaration to ASLayoutableStyle * Add styleClass class property for extensibility support of the ASLayoutable style object * flexShrink should not be YES by default
This commit is contained in:
committed by
GitHub
parent
a9857f9963
commit
75dca556e6
@@ -18,9 +18,9 @@ static CGFloat baselineForItem(const ASStackLayoutSpecStyle &style,
|
||||
__weak id<ASLayoutable> child = layout.layoutable;
|
||||
switch (style.alignItems) {
|
||||
case ASStackLayoutAlignItemsBaselineFirst:
|
||||
return child.ascender;
|
||||
return child.style.ascender;
|
||||
case ASStackLayoutAlignItemsBaselineLast:
|
||||
return layout.size.height + child.descender;
|
||||
return layout.size.height + child.style.descender;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ static CGFloat baselineOffset(const ASStackLayoutSpecStyle &style,
|
||||
__weak id<ASLayoutable> child = l.layoutable;
|
||||
switch (style.alignItems) {
|
||||
case ASStackLayoutAlignItemsBaselineFirst:
|
||||
return maxAscender - child.ascender;
|
||||
return maxAscender - child.style.ascender;
|
||||
case ASStackLayoutAlignItemsBaselineLast:
|
||||
return maxBaseline - baselineForItem(style, l);
|
||||
|
||||
@@ -89,9 +89,9 @@ ASStackBaselinePositionedLayout ASStackBaselinePositionedLayout::compute(const A
|
||||
our layoutSpec to have it so that it can be baseline aligned with another text node or baseline layout spec.
|
||||
*/
|
||||
const auto ascenderIt = std::max_element(positionedLayout.sublayouts.begin(), positionedLayout.sublayouts.end(), [&](const ASLayout *a, const ASLayout *b){
|
||||
return a.layoutable.ascender < b.layoutable.ascender;
|
||||
return a.layoutable.style.ascender < b.layoutable.style.ascender;
|
||||
});
|
||||
const CGFloat maxAscender = ascenderIt == positionedLayout.sublayouts.end() ? 0 : (*ascenderIt).layoutable.ascender;
|
||||
const CGFloat maxAscender = ascenderIt == positionedLayout.sublayouts.end() ? 0 : (*ascenderIt).layoutable.style.ascender;
|
||||
|
||||
/*
|
||||
Step 3: Take each child and update its layout position based on the baseline offset.
|
||||
@@ -109,7 +109,7 @@ ASStackBaselinePositionedLayout ASStackBaselinePositionedLayout::compute(const A
|
||||
BOOL first = YES;
|
||||
stackedChildren = AS::map(positionedLayout.sublayouts, [&](ASLayout *l) -> ASLayout *{
|
||||
__weak id<ASLayoutable> child = l.layoutable;
|
||||
p = p + directionPoint(style.direction, child.spacingBefore, 0);
|
||||
p = p + directionPoint(style.direction, child.style.spacingBefore, 0);
|
||||
if (first) {
|
||||
// if this is the first item use the previously computed start point
|
||||
p = l.position;
|
||||
@@ -126,9 +126,9 @@ ASStackBaselinePositionedLayout ASStackBaselinePositionedLayout::compute(const A
|
||||
// node from baselines and not bounding boxes.
|
||||
CGFloat spacingAfterBaseline = 0;
|
||||
if (style.direction == ASStackLayoutDirectionVertical) {
|
||||
spacingAfterBaseline = child.descender;
|
||||
spacingAfterBaseline = child.style.descender;
|
||||
}
|
||||
p = p + directionPoint(style.direction, stackDimension(style.direction, l.size) + child.spacingAfter + spacingAfterBaseline, 0);
|
||||
p = p + directionPoint(style.direction, stackDimension(style.direction, l.size) + child.style.spacingAfter + spacingAfterBaseline, 0);
|
||||
|
||||
return l;
|
||||
});
|
||||
@@ -161,7 +161,7 @@ ASStackBaselinePositionedLayout ASStackBaselinePositionedLayout::compute(const A
|
||||
const auto descenderIt = std::max_element(stackedChildren.begin(), stackedChildren.end(), [&](const ASLayout *a, const ASLayout *b){
|
||||
return a.position.y + a.size.height < b.position.y + b.size.height;
|
||||
});
|
||||
const CGFloat minDescender = descenderIt == stackedChildren.end() ? 0 : (*descenderIt).layoutable.descender;
|
||||
const CGFloat minDescender = descenderIt == stackedChildren.end() ? 0 : (*descenderIt).layoutable.style.descender;
|
||||
|
||||
return {stackedChildren, crossSize, maxAscender, minDescender};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user