Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowed column with numeric width value to stretch #1595

Merged
merged 3 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ - (UIView* )render:(UIView<ACRIContentHoldingView> *)viewGroup
NSMutableArray *constraints = [[NSMutableArray alloc] init];

ACOBaseCardElement *acoColumn = [[ACOBaseCardElement alloc] init];
auto firstColumn = columns.begin();
for(std::shared_ptr<Column> column:columns)
{
[ACRSeparator renderSeparation:column forSuperview:columnSetView withHostConfig:config];
if(*firstColumn != column) {
[ACRSeparator renderSeparation:column forSuperview:columnSetView withHostConfig:config];
}
[acoColumn setElem:column];
curView = (ACRColumnView *)[columRenderer render:columnSetView rootView:rootView inputs:inputs baseCardElement:acoColumn hostConfig:acoConfig];

Expand All @@ -76,44 +79,34 @@ - (UIView* )render:(UIView<ACRIContentHoldingView> *)viewGroup
relativeColumnWidth = std::stof(column->GetWidth());
if(prevRelColumnWidth)
multiplier = relativeColumnWidth / prevRelColumnWidth;

if(prevView && prevRelColumnWidth)
{

[constraints addObject:
[NSLayoutConstraint constraintWithItem:curView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:prevView
attribute:NSLayoutAttributeWidth
multiplier:multiplier
constant:0]];
prevRelColumnWidth = relativeColumnWidth;
}

if(curView.hasStretchableView){
[columnSetView setAlignmentForColumnStretch];
}

prevView = curView;
prevRelColumnWidth = relativeColumnWidth;
}
catch(...){
multiplier = 1;
relativeColumnWidth = 1;
NSLog(@"unexpected column width property is given");
}
}
if(prevView && prevRelColumnWidth)
{

[constraints addObject:
[NSLayoutConstraint constraintWithItem:curView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:prevView
attribute:NSLayoutAttributeWidth
multiplier:multiplier
constant:0]];
prevRelColumnWidth = relativeColumnWidth;
}
else if(!prevView)
{
[constraints addObject:
[NSLayoutConstraint constraintWithItem:curView
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:columnSetView
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant:0]];
}

if( curView.hasStretchableView ){
[columnSetView setAlignmentForColumnStretch];
}

prevView = curView;
prevRelColumnWidth = relativeColumnWidth;
}

if([constraints count]) [columnSetView addConstraints:constraints];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ - (void)config:(nullable NSDictionary<NSString *, id> *)attributes

- (void)addArrangedSubview:(UIView *)view
{
// if columnWidth is set to stretch, allows to fill the available space
if([self.columnWidth isEqualToString:@"stretch"]){
[view setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[view setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
} // if auto, maintain content size whenever possible
else if([self.columnWidth isEqualToString:@"auto"]){
// if auto, maintain content size whenever possible
if([self.columnWidth isEqualToString:@"auto"]){
[view setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
[view setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
// if columnWidth is set to stretch or number, allow column to fill the available space
} else {
[view setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[view setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}

[self.stackView addArrangedSubview:view];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ + (UIView *)render:(UIView<ACRIContentHoldingView> *)view

UIView *prevStretchableElem = nil, *curStretchableElem = nil;

auto firstelem = elems.begin();
for(const auto &elem:elems)
{
[ACRSeparator renderSeparation:elem forSuperview:view withHostConfig:[config getHostConfig]];
if(*firstelem != elem){
[ACRSeparator renderSeparation:elem forSuperview:view withHostConfig:[config getHostConfig]];
}

ACRBaseCardElementRenderer *renderer =
[reg getRenderer:[NSNumber numberWithInt:(int)elem->GetElementType()]];
Expand Down