Implement horizontal and vertical alignments for stack layout

This commit is contained in:
Huy Nguyen
2015-11-20 17:50:05 +02:00
parent 50a52e7112
commit 0077c3eec6
11 changed files with 235 additions and 8 deletions

View File

@@ -25,7 +25,7 @@
@implementation ASStackLayoutSpec
{
ASDN::RecursiveMutex _propertyLock;
ASDN::RecursiveMutex _propertyLock;
}
- (instancetype)init
@@ -58,8 +58,10 @@
return nil;
}
_direction = direction;
_alignItems = alignItems;
_spacing = spacing;
_horizontalAlignment = ASHorizontalAlignmentNone;
_verticalAlignment = ASVerticalAlignmentNone;
_alignItems = alignItems;
_justifyContent = justifyContent;
[self setChildren:children];
@@ -69,18 +71,44 @@
- (void)setDirection:(ASStackLayoutDirection)direction
{
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
_direction = direction;
if (_direction != direction) {
_direction = direction;
[self resolveHorizontalAlignment];
[self resolveVerticalAlignment];
}
}
- (void)setHorizontalAlignment:(ASHorizontalAlignment)horizontalAlignment
{
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
if (_horizontalAlignment != horizontalAlignment) {
_horizontalAlignment = horizontalAlignment;
[self resolveHorizontalAlignment];
}
}
- (void)setVerticalAlignment:(ASVerticalAlignment)verticalAlignment
{
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
if (_verticalAlignment != verticalAlignment) {
_verticalAlignment = verticalAlignment;
[self resolveVerticalAlignment];
}
}
- (void)setAlignItems:(ASStackLayoutAlignItems)alignItems
{
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
ASDisplayNodeAssert(_horizontalAlignment == ASHorizontalAlignmentNone, @"Cannot set this property directly because horizontalAlignment is being used");
ASDisplayNodeAssert(_verticalAlignment == ASVerticalAlignmentNone, @"Cannot set this property directly because verticalAlignment is being used");
_alignItems = alignItems;
}
- (void)setJustifyContent:(ASStackLayoutJustifyContent)justifyContent
{
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
ASDisplayNodeAssert(_horizontalAlignment == ASHorizontalAlignmentNone, @"Cannot set this property directly because horizontalAlignment is being used");
ASDisplayNodeAssert(_verticalAlignment == ASVerticalAlignmentNone, @"Cannot set this property directly because verticalAlignment is being used");
_justifyContent = justifyContent;
}
@@ -149,6 +177,24 @@
sublayouts:sublayouts];
}
- (void)resolveHorizontalAlignment
{
if (_direction == ASStackLayoutDirectionHorizontal) {
_justifyContent = justifyContent(_horizontalAlignment, _justifyContent);
} else {
_alignItems = alignment(_horizontalAlignment, _alignItems);
}
}
- (void)resolveVerticalAlignment
{
if (_direction == ASStackLayoutDirectionHorizontal) {
_alignItems = alignment(_verticalAlignment, _alignItems);
} else {
_justifyContent = justifyContent(_verticalAlignment, _justifyContent);
}
}
@end
@implementation ASStackLayoutSpec (Debugging)