2019-12-04 13:29:26 +08:00
|
|
|
/*
|
|
|
|
* Copyright [2019] [Doric.Pub]
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
//
|
|
|
|
// Created by pengfei.zhou on 2019/10/23.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "DoricLayouts.h"
|
|
|
|
#import <objc/runtime.h>
|
|
|
|
#import "UIView+Doric.h"
|
|
|
|
|
|
|
|
static const void *kLayoutConfig = &kLayoutConfig;
|
|
|
|
|
|
|
|
@implementation UIView (DoricLayoutConfig)
|
|
|
|
@dynamic layoutConfig;
|
|
|
|
|
|
|
|
- (void)setLayoutConfig:(DoricLayoutConfig *)layoutConfig {
|
|
|
|
objc_setAssociatedObject(self, kLayoutConfig, layoutConfig, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (DoricLayoutConfig *)layoutConfig {
|
|
|
|
return objc_getAssociatedObject(self, kLayoutConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2019-12-04 19:02:15 +08:00
|
|
|
static const void *kLayoutPadding = &kLayoutPadding;
|
|
|
|
|
|
|
|
@implementation UIView (DoricPadding)
|
|
|
|
@dynamic padding;
|
|
|
|
|
|
|
|
- (void)setPadding:(DoricPadding)padding {
|
|
|
|
objc_setAssociatedObject(self, kLayoutPadding, [NSValue value:&padding withObjCType:@encode(DoricPadding)], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (DoricPadding)padding {
|
|
|
|
DoricPadding value;
|
|
|
|
value.left = value.right = value.top = value.bottom = 0;
|
|
|
|
[objc_getAssociatedObject(self, kLayoutPadding) getValue:&value];
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2019-12-04 13:29:26 +08:00
|
|
|
static const void *kTagString = &kTagString;
|
|
|
|
|
|
|
|
@implementation UIView (DoricTag)
|
|
|
|
|
|
|
|
- (void)setTagString:(NSString *)tagString {
|
|
|
|
objc_setAssociatedObject(self, kTagString, tagString, OBJC_ASSOCIATION_COPY_NONATOMIC);
|
|
|
|
self.tag = [tagString hash];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tagString {
|
|
|
|
return objc_getAssociatedObject(self, kTagString);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (UIView *)viewWithTagString:(NSString *)tagString {
|
|
|
|
// notice the potential hash collision
|
|
|
|
return [self viewWithTag:[tagString hash]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation UIView (DoricLayouts)
|
|
|
|
/**
|
|
|
|
* Measure self's size
|
|
|
|
* */
|
|
|
|
- (CGSize)measureSize:(CGSize)targetSize {
|
|
|
|
CGFloat width = self.width;
|
|
|
|
CGFloat height = self.height;
|
|
|
|
|
|
|
|
DoricLayoutConfig *config = self.layoutConfig;
|
|
|
|
if (!config) {
|
|
|
|
config = [DoricLayoutConfig new];
|
|
|
|
}
|
|
|
|
if (config.widthSpec == DoricLayoutAtMost
|
|
|
|
|| config.widthSpec == DoricLayoutWrapContent) {
|
|
|
|
width = targetSize.width - config.margin.left - config.margin.right;
|
|
|
|
}
|
|
|
|
if (config.heightSpec == DoricLayoutAtMost
|
|
|
|
|| config.heightSpec == DoricLayoutWrapContent) {
|
|
|
|
height = targetSize.height - config.margin.top - config.margin.bottom;
|
|
|
|
}
|
2019-12-04 19:02:15 +08:00
|
|
|
DoricPadding padding = self.padding;
|
|
|
|
CGSize contentSize = [self sizeThatFits:CGSizeMake(
|
|
|
|
width - padding.left - padding.right,
|
|
|
|
height - padding.top - padding.bottom)];
|
2019-12-04 13:29:26 +08:00
|
|
|
if (config.widthSpec == DoricLayoutWrapContent) {
|
2019-12-04 19:02:15 +08:00
|
|
|
width = contentSize.width + padding.left + padding.right;
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
|
|
|
if (config.heightSpec == DoricLayoutWrapContent) {
|
2020-03-02 14:48:31 +08:00
|
|
|
height = contentSize.height + padding.top + padding.bottom;
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
|
|
|
return CGSizeMake(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* layout self and subviews
|
|
|
|
* */
|
|
|
|
- (void)layoutSelf:(CGSize)targetSize {
|
|
|
|
self.width = targetSize.width;
|
|
|
|
self.height = targetSize.height;
|
|
|
|
for (UIView *view in self.subviews) {
|
|
|
|
[view layoutSelf:[view measureSize:targetSize]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)doricLayoutSubviews {
|
|
|
|
if ([self.superview requestFromSubview:self]) {
|
|
|
|
[self.superview doricLayoutSubviews];
|
|
|
|
} else {
|
2020-03-13 17:45:03 +08:00
|
|
|
CGSize size = [self measureSize:CGSizeMake(self.superview.width, self.superview.height)];
|
|
|
|
[self layoutSelf:size];
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)requestFromSubview:(UIView *)subview {
|
|
|
|
if (self.layoutConfig
|
|
|
|
&& self.layoutConfig.widthSpec != DoricLayoutExact
|
|
|
|
&& self.layoutConfig.heightSpec != DoricLayoutExact) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
DoricMargin DoricMarginMake(CGFloat left, CGFloat top, CGFloat right, CGFloat bottom) {
|
|
|
|
DoricMargin margin;
|
|
|
|
margin.left = left;
|
|
|
|
margin.top = top;
|
|
|
|
margin.right = right;
|
|
|
|
margin.bottom = bottom;
|
|
|
|
return margin;
|
|
|
|
}
|
|
|
|
|
|
|
|
@implementation DoricLayoutConfig
|
|
|
|
- (instancetype)init {
|
|
|
|
if (self = [super init]) {
|
|
|
|
_widthSpec = DoricLayoutExact;
|
|
|
|
_heightSpec = DoricLayoutExact;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithWidth:(DoricLayoutSpec)width height:(DoricLayoutSpec)height {
|
|
|
|
if (self = [super init]) {
|
|
|
|
_widthSpec = width;
|
|
|
|
_heightSpec = height;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithWidth:(DoricLayoutSpec)width height:(DoricLayoutSpec)height margin:(DoricMargin)margin {
|
|
|
|
if (self = [super init]) {
|
|
|
|
_widthSpec = width;
|
|
|
|
_heightSpec = height;
|
|
|
|
_margin = margin;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@interface DoricLayoutContainer ()
|
|
|
|
@property(nonatomic, assign) CGFloat contentWidth;
|
|
|
|
@property(nonatomic, assign) CGFloat contentHeight;
|
|
|
|
@property(nonatomic, assign) NSUInteger contentWeight;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DoricLayoutContainer
|
|
|
|
- (void)setNeedsLayout {
|
|
|
|
[super setNeedsLayout];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSubviews {
|
|
|
|
[super layoutSubviews];
|
|
|
|
[self doricLayoutSubviews];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@interface DoricStackView ()
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DoricStackView
|
|
|
|
|
|
|
|
- (CGSize)sizeThatFits:(CGSize)size {
|
|
|
|
CGFloat contentWidth = 0;
|
|
|
|
CGFloat contentHeight = 0;
|
|
|
|
for (UIView *child in self.subviews) {
|
|
|
|
if (child.isHidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DoricLayoutConfig *childConfig = child.layoutConfig;
|
|
|
|
if (!childConfig) {
|
|
|
|
childConfig = [DoricLayoutConfig new];
|
|
|
|
}
|
|
|
|
CGSize childSize;
|
|
|
|
if (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|
|
|
|
childSize = [child measureSize:CGSizeMake(size.width, size.height)];
|
|
|
|
} else {
|
|
|
|
childSize = child.bounds.size;
|
|
|
|
}
|
|
|
|
contentWidth = MAX(contentWidth, childSize.width + childConfig.margin.left + childConfig.margin.right);
|
|
|
|
contentHeight = MAX(contentHeight, childSize.height + childConfig.margin.top + childConfig.margin.bottom);
|
|
|
|
}
|
|
|
|
self.contentWidth = contentWidth;
|
|
|
|
self.contentHeight = contentHeight;
|
|
|
|
return CGSizeMake(contentWidth, contentHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSelf:(CGSize)targetSize {
|
|
|
|
self.width = targetSize.width;
|
|
|
|
self.height = targetSize.height;
|
2019-12-04 19:02:15 +08:00
|
|
|
DoricPadding padding = self.padding;
|
|
|
|
|
2019-12-04 13:29:26 +08:00
|
|
|
for (UIView *child in self.subviews) {
|
|
|
|
if (child.isHidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DoricLayoutConfig *childConfig = child.layoutConfig;
|
|
|
|
if (!childConfig) {
|
|
|
|
childConfig = [DoricLayoutConfig new];
|
|
|
|
}
|
2019-12-04 19:02:15 +08:00
|
|
|
CGSize size = [child measureSize:CGSizeMake(
|
|
|
|
targetSize.width - padding.left - padding.right,
|
|
|
|
targetSize.height - padding.top - padding.bottom)];
|
2019-12-04 13:29:26 +08:00
|
|
|
[child layoutSelf:size];
|
|
|
|
DoricGravity gravity = childConfig.alignment;
|
|
|
|
if ((gravity & LEFT) == LEFT) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.left = padding.left;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((gravity & RIGHT) == RIGHT) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.right = targetSize.width - padding.right;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((gravity & CENTER_X) == CENTER_X) {
|
2019-12-10 14:15:32 +08:00
|
|
|
child.centerX = targetSize.width / 2;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else {
|
|
|
|
if (childConfig.margin.left) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.left = childConfig.margin.left + padding.left;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if (childConfig.margin.right) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.right = targetSize.width - childConfig.margin.right - padding.right;
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((gravity & TOP) == TOP) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.top = padding.top;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((gravity & BOTTOM) == BOTTOM) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.bottom = targetSize.height - padding.bottom;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((gravity & CENTER_Y) == CENTER_Y) {
|
2019-12-10 14:15:32 +08:00
|
|
|
child.centerY = targetSize.height / 2;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else {
|
|
|
|
if (childConfig.margin.top) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.top = childConfig.margin.top + padding.top;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if (childConfig.margin.bottom) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.bottom = targetSize.height - childConfig.margin.bottom - padding.bottom;
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DoricLinearView
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DoricVLayoutView
|
|
|
|
|
|
|
|
- (CGSize)sizeThatFits:(CGSize)size {
|
|
|
|
CGFloat contentWidth = 0;
|
|
|
|
CGFloat contentHeight = 0;
|
|
|
|
NSUInteger contentWeight = 0;
|
|
|
|
for (UIView *child in self.subviews) {
|
|
|
|
if (child.isHidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DoricLayoutConfig *childConfig = child.layoutConfig;
|
|
|
|
if (!childConfig) {
|
|
|
|
childConfig = [DoricLayoutConfig new];
|
|
|
|
}
|
|
|
|
CGSize childSize;
|
|
|
|
if (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|
|
|
|
childSize = [child measureSize:CGSizeMake(size.width, size.height - contentHeight)];
|
|
|
|
} else {
|
|
|
|
childSize = child.bounds.size;
|
|
|
|
}
|
|
|
|
contentWidth = MAX(contentWidth, childSize.width + childConfig.margin.left + childConfig.margin.right);
|
|
|
|
contentHeight += childSize.height + self.space + childConfig.margin.top + childConfig.margin.bottom;
|
|
|
|
contentWeight += childConfig.weight;
|
|
|
|
}
|
|
|
|
contentHeight -= self.space;
|
|
|
|
self.contentWidth = contentWidth;
|
|
|
|
self.contentHeight = contentHeight;
|
|
|
|
self.contentWeight = contentWeight;
|
|
|
|
if (contentWeight) {
|
|
|
|
contentHeight = size.height;
|
|
|
|
}
|
|
|
|
return CGSizeMake(contentWidth, contentHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSelf:(CGSize)targetSize {
|
|
|
|
self.width = targetSize.width;
|
|
|
|
self.height = targetSize.height;
|
2019-12-04 19:02:15 +08:00
|
|
|
DoricPadding padding = self.padding;
|
|
|
|
CGFloat yStart = padding.top;
|
2019-12-04 13:29:26 +08:00
|
|
|
if ((self.gravity & TOP) == TOP) {
|
2019-12-04 19:02:15 +08:00
|
|
|
yStart = padding.top;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((self.gravity & BOTTOM) == BOTTOM) {
|
2019-12-04 19:02:15 +08:00
|
|
|
yStart = targetSize.height - self.contentHeight - padding.bottom;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((self.gravity & CENTER_Y) == CENTER_Y) {
|
2019-12-10 14:15:32 +08:00
|
|
|
yStart = (targetSize.height - self.contentHeight - padding.top - padding.bottom) / 2 + padding.top;
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
2019-12-04 19:02:15 +08:00
|
|
|
CGFloat remain = targetSize.height - self.contentHeight - padding.top - padding.bottom;
|
2019-12-04 13:29:26 +08:00
|
|
|
for (UIView *child in self.subviews) {
|
|
|
|
if (child.isHidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DoricLayoutConfig *childConfig = child.layoutConfig;
|
|
|
|
if (!childConfig) {
|
|
|
|
childConfig = [DoricLayoutConfig new];
|
|
|
|
}
|
|
|
|
|
2019-12-04 19:02:15 +08:00
|
|
|
CGSize size = [child measureSize:CGSizeMake(
|
|
|
|
targetSize.width - padding.left - padding.right,
|
|
|
|
targetSize.height - yStart - padding.bottom)];
|
2019-12-04 13:29:26 +08:00
|
|
|
if (childConfig.weight) {
|
|
|
|
size.height += remain / self.contentWeight * childConfig.weight;
|
|
|
|
}
|
|
|
|
[child layoutSelf:size];
|
|
|
|
DoricGravity gravity = childConfig.alignment | self.gravity;
|
|
|
|
if ((gravity & LEFT) == LEFT) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.left = padding.left;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((gravity & RIGHT) == RIGHT) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.right = self.width - padding.right;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((gravity & CENTER_X) == CENTER_X) {
|
2019-12-10 14:15:32 +08:00
|
|
|
child.centerX = targetSize.width / 2;
|
2019-12-04 19:02:15 +08:00
|
|
|
} else if (childConfig.margin.left) {
|
|
|
|
child.left = childConfig.margin.left + padding.left;
|
|
|
|
} else if (childConfig.margin.right) {
|
|
|
|
child.right = targetSize.width - childConfig.margin.right - padding.right;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.left = padding.left;
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
|
|
|
if (childConfig.margin.top) {
|
|
|
|
yStart += childConfig.margin.top;
|
|
|
|
}
|
|
|
|
child.top = yStart;
|
|
|
|
yStart = child.bottom + self.space;
|
|
|
|
if (childConfig.margin.bottom) {
|
|
|
|
yStart += childConfig.margin.bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DoricHLayoutView
|
|
|
|
- (CGSize)sizeThatFits:(CGSize)size {
|
|
|
|
CGFloat contentWidth = 0;
|
|
|
|
CGFloat contentHeight = 0;
|
|
|
|
NSUInteger contentWeight = 0;
|
|
|
|
for (UIView *child in self.subviews) {
|
|
|
|
if (child.isHidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DoricLayoutConfig *childConfig = child.layoutConfig;
|
|
|
|
if (!childConfig) {
|
|
|
|
childConfig = [DoricLayoutConfig new];
|
|
|
|
}
|
|
|
|
CGSize childSize;
|
|
|
|
if (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|
|
|
|
childSize = [child measureSize:CGSizeMake(size.width - contentWidth, size.height)];
|
|
|
|
} else {
|
|
|
|
childSize = child.bounds.size;
|
|
|
|
}
|
|
|
|
contentWidth += childSize.width + self.space + childConfig.margin.left + childConfig.margin.right;
|
|
|
|
contentHeight = MAX(contentHeight, childSize.height + childConfig.margin.top + childConfig.margin.bottom);
|
|
|
|
contentWeight += childConfig.weight;
|
|
|
|
}
|
2020-03-02 14:33:08 +08:00
|
|
|
if (self.subviews.count > 0) {
|
|
|
|
contentWidth -= self.space;
|
|
|
|
}
|
2019-12-04 13:29:26 +08:00
|
|
|
self.contentWidth = contentWidth;
|
|
|
|
self.contentHeight = contentHeight;
|
|
|
|
self.contentWeight = contentWeight;
|
|
|
|
if (contentWeight) {
|
|
|
|
contentWidth = size.width;
|
|
|
|
}
|
|
|
|
return CGSizeMake(contentWidth, contentHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSelf:(CGSize)targetSize {
|
|
|
|
self.width = targetSize.width;
|
|
|
|
self.height = targetSize.height;
|
2019-12-04 19:02:15 +08:00
|
|
|
DoricPadding padding = self.padding;
|
|
|
|
CGFloat xStart = padding.left;
|
|
|
|
if ((self.gravity & LEFT) == LEFT) {
|
|
|
|
xStart = padding.left;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((self.gravity & RIGHT) == RIGHT) {
|
2019-12-04 19:02:15 +08:00
|
|
|
xStart = targetSize.width - self.contentWidth - padding.right;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((self.gravity & CENTER_X) == CENTER_X) {
|
2019-12-10 14:15:32 +08:00
|
|
|
xStart = (targetSize.width - self.contentWidth - padding.left - padding.right) / 2 + padding.left;
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
2019-12-04 19:02:15 +08:00
|
|
|
CGFloat remain = targetSize.width - self.contentWidth - padding.left - padding.right;
|
2019-12-04 13:29:26 +08:00
|
|
|
for (UIView *child in self.subviews) {
|
|
|
|
if (child.isHidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DoricLayoutConfig *childConfig = child.layoutConfig;
|
|
|
|
if (!childConfig) {
|
|
|
|
childConfig = [DoricLayoutConfig new];
|
|
|
|
}
|
2019-12-14 15:04:34 +08:00
|
|
|
|
2019-12-04 19:02:15 +08:00
|
|
|
CGSize size = [child measureSize:CGSizeMake(
|
|
|
|
targetSize.width - xStart - padding.right,
|
|
|
|
targetSize.height - padding.top - padding.bottom)];
|
2019-12-04 13:29:26 +08:00
|
|
|
if (childConfig.weight) {
|
|
|
|
size.width += remain / self.contentWeight * childConfig.weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
[child layoutSelf:size];
|
|
|
|
|
|
|
|
DoricGravity gravity = childConfig.alignment | self.gravity;
|
|
|
|
if ((gravity & TOP) == TOP) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.top = padding.top;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((gravity & BOTTOM) == BOTTOM) {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.bottom = targetSize.height - padding.bottom;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else if ((gravity & CENTER_Y) == CENTER_Y) {
|
2019-12-10 14:15:32 +08:00
|
|
|
child.centerY = targetSize.height / 2;
|
2019-12-04 19:02:15 +08:00
|
|
|
} else if (childConfig.margin.top) {
|
|
|
|
child.top = childConfig.margin.top + padding.top;
|
|
|
|
} else if (childConfig.margin.bottom) {
|
|
|
|
child.bottom = targetSize.height - childConfig.margin.bottom - padding.bottom;
|
2019-12-04 13:29:26 +08:00
|
|
|
} else {
|
2019-12-04 19:02:15 +08:00
|
|
|
child.top = padding.top;
|
2019-12-04 13:29:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (childConfig.margin.left) {
|
|
|
|
xStart += childConfig.margin.left;
|
|
|
|
}
|
|
|
|
child.left = xStart;
|
|
|
|
xStart = child.right + self.space;
|
|
|
|
if (childConfig.margin.right) {
|
|
|
|
xStart += childConfig.margin.right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|