iOS:DoricLayout add weight support
This commit is contained in:
parent
abbe0ba377
commit
91787fb0af
@ -188,7 +188,7 @@ - (void)measureStackContent:(CGSize)targetSize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)measureVLayoutContent:(CGSize)targetSize {
|
- (void)measureVLayoutContent:(CGSize)targetSize {
|
||||||
CGFloat contentWidth = 0, contentHeight = 0;
|
CGFloat contentWidth = 0, contentHeight = 0, contentWeight = 0;
|
||||||
BOOL had = NO;
|
BOOL had = NO;
|
||||||
for (__kindof UIView *subview in self.view.subviews) {
|
for (__kindof UIView *subview in self.view.subviews) {
|
||||||
DoricLayout *layout = subview.doricLayout;
|
DoricLayout *layout = subview.doricLayout;
|
||||||
@ -199,12 +199,31 @@ - (void)measureVLayoutContent:(CGSize)targetSize {
|
|||||||
[layout measure:CGSizeMake(targetSize.width, targetSize.height - contentHeight)];
|
[layout measure:CGSizeMake(targetSize.width, targetSize.height - contentHeight)];
|
||||||
contentWidth = MAX(contentWidth, layout.takenWidth);
|
contentWidth = MAX(contentWidth, layout.takenWidth);
|
||||||
contentHeight += layout.takenHeight + self.spacing;
|
contentHeight += layout.takenHeight + self.spacing;
|
||||||
|
contentWeight += layout.weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (had) {
|
if (had) {
|
||||||
contentHeight -= self.spacing;
|
contentHeight -= self.spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contentWeight > 0) {
|
||||||
|
CGFloat remaining = targetSize.height - contentHeight;
|
||||||
|
contentWidth = 0;
|
||||||
|
for (__kindof UIView *subview in self.view.subviews) {
|
||||||
|
DoricLayout *layout = subview.doricLayout;
|
||||||
|
if (layout.disabled) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
layout.measuredHeight += remaining / contentWeight * layout.weight;
|
||||||
|
//Need Remeasure
|
||||||
|
[layout measureContent:CGSizeMake(
|
||||||
|
layout.measuredWidth - layout.paddingLeft - layout.paddingRight,
|
||||||
|
layout.measuredHeight - layout.paddingTop - layout.paddingBottom)];
|
||||||
|
contentWidth = MAX(contentWidth, layout.takenWidth);
|
||||||
|
}
|
||||||
|
contentHeight = targetSize.height;
|
||||||
|
}
|
||||||
|
|
||||||
if (self.widthSpec == DoricLayoutFit) {
|
if (self.widthSpec == DoricLayoutFit) {
|
||||||
self.measuredWidth = contentWidth + self.paddingLeft + self.paddingRight;
|
self.measuredWidth = contentWidth + self.paddingLeft + self.paddingRight;
|
||||||
}
|
}
|
||||||
@ -219,7 +238,7 @@ - (void)measureVLayoutContent:(CGSize)targetSize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)measureHLayoutContent:(CGSize)targetSize {
|
- (void)measureHLayoutContent:(CGSize)targetSize {
|
||||||
CGFloat contentWidth = 0, contentHeight = 0;
|
CGFloat contentWidth = 0, contentHeight = 0, contentWeight = 0;;
|
||||||
BOOL had = NO;
|
BOOL had = NO;
|
||||||
for (__kindof UIView *subview in self.view.subviews) {
|
for (__kindof UIView *subview in self.view.subviews) {
|
||||||
DoricLayout *layout = subview.doricLayout;
|
DoricLayout *layout = subview.doricLayout;
|
||||||
@ -230,11 +249,31 @@ - (void)measureHLayoutContent:(CGSize)targetSize {
|
|||||||
[layout measure:CGSizeMake(targetSize.width - contentWidth, targetSize.height)];
|
[layout measure:CGSizeMake(targetSize.width - contentWidth, targetSize.height)];
|
||||||
contentWidth += layout.takenWidth + self.spacing;
|
contentWidth += layout.takenWidth + self.spacing;
|
||||||
contentHeight = MAX(contentHeight, layout.takenHeight);
|
contentHeight = MAX(contentHeight, layout.takenHeight);
|
||||||
|
contentWeight += layout.weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (had) {
|
if (had) {
|
||||||
contentWidth -= self.spacing;
|
contentWidth -= self.spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contentWeight > 0) {
|
||||||
|
CGFloat remaining = targetSize.width - contentWidth;
|
||||||
|
contentHeight = 0;
|
||||||
|
for (__kindof UIView *subview in self.view.subviews) {
|
||||||
|
DoricLayout *layout = subview.doricLayout;
|
||||||
|
if (layout.disabled) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
layout.measuredWidth += remaining / contentWeight * layout.weight;
|
||||||
|
//Need Remeasure
|
||||||
|
[layout measureContent:CGSizeMake(
|
||||||
|
layout.measuredWidth - layout.paddingLeft - layout.paddingRight,
|
||||||
|
layout.measuredHeight - layout.paddingTop - layout.paddingBottom)];
|
||||||
|
contentHeight = MAX(contentHeight, layout.takenHeight);
|
||||||
|
}
|
||||||
|
contentWidth = targetSize.width;
|
||||||
|
}
|
||||||
|
|
||||||
if (self.widthSpec == DoricLayoutFit) {
|
if (self.widthSpec == DoricLayoutFit) {
|
||||||
self.measuredWidth = contentWidth + self.paddingLeft + self.paddingRight;
|
self.measuredWidth = contentWidth + self.paddingLeft + self.paddingRight;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user