# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1662014402 0 # Node ID 455d539ac5555290ba29fcbe68a2e2e8a8bd9fc0 # Parent 5f0483eb39a44632821b883475c2486e590e69d0 iOS: Add initial implementation of DW_CONTAINER_MODE_EXTRA. It mostly works but the layout isn't quite correct, fixes will be coming followed by the implementation of DW_CONTAINER_MODE_MULTI. Add a toggle for DW_CONTAINER_MODE_EXTRA to dwtest on mobile platforms. diff -r 5f0483eb39a4 -r 455d539ac555 dwtest.c --- a/dwtest.c Thu Sep 01 06:38:08 2022 +0000 +++ b/dwtest.c Thu Sep 01 06:40:02 2022 +0000 @@ -2192,6 +2192,11 @@ if(getenv("DW_DARK_MODE")) dw_feature_set(DW_FEATURE_DARK_MODE, DW_DARK_MODE_FULL); +#ifdef DW_MOBILE + /* Enable extra container display on Mobile platforms */ + dw_feature_set(DW_FEATURE_CONTAINER_MODE, DW_CONTAINER_MODE_EXTRA); +#endif + /* Initialize the Dynamic Windows engine */ dw_init(TRUE, argc, argv); diff -r 5f0483eb39a4 -r 455d539ac555 ios/dw.m --- a/ios/dw.m Thu Sep 01 06:38:08 2022 +0000 +++ b/ios/dw.m Thu Sep 01 06:40:02 2022 +0000 @@ -2336,15 +2336,105 @@ @interface DWTableViewCell : UITableViewCell { NSMutableArray *columndata; + UIStackView *stack; } -(void)setColumnData:(NSMutableArray *)input; -(NSMutableArray *)columnData; @end @implementation DWTableViewCell --(void)setColumnData:(NSMutableArray *)input { [columndata release]; columndata = input; [columndata retain]; } +-(void)setColumnData:(NSMutableArray *)input +{ + if(columndata != input) + { + NSMutableArray *olddata = columndata; + columndata = input; + [columndata retain]; + [olddata release]; + } + /* If we have columndata and are not in default mode */ + if(columndata && _dw_container_mode > DW_CONTAINER_MODE_DEFAULT) + { + /* If we don't have a stack, create one */ + if(!stack) + { + stack = [[[UIStackView alloc] init] retain]; + [stack setTranslatesAutoresizingMaskIntoConstraints:NO]; + [stack setSpacing:5.0]; + [[self contentView] addSubview:stack]; + } + /* Extra mode creates a horizontal stack with all the column data */ + if(_dw_container_mode == DW_CONTAINER_MODE_EXTRA) + { + id subviews = [stack arrangedSubviews]; + int index = 0; + + [stack setAxis:UILayoutConstraintAxisHorizontal]; + /* Create the stack using columndata, reusing objects when possible */ + for(id object in columndata) + { + if([object isKindOfClass:[NSString class]]) + { + UILabel *label = nil; + + if(index < [subviews count]) + { + id oldview = [subviews objectAtIndex:index]; + + if([oldview isMemberOfClass:[UILabel class]]) + label = oldview; + else + [stack removeArrangedSubview:oldview]; + } + if(!label) + { + label = [[UILabel alloc] init]; + + [label setTranslatesAutoresizingMaskIntoConstraints:NO]; + [label setTextAlignment:NSTextAlignmentCenter]; + + if(index < [subviews count]) + [stack insertArrangedSubview:label atIndex:index]; + else + [stack addArrangedSubview:label]; + } + [label setText:object]; + index++; + } + else if([object isMemberOfClass:[UIImage class]]) + { + UIImageView *image = nil; + + if(index < [subviews count]) + { + id oldview = [subviews objectAtIndex:index]; + + if([oldview isMemberOfClass:[UIImageView class]]) + image = oldview; + else + [stack removeArrangedSubview:oldview]; + } + if(!image) + { + image = [[UIImageView alloc] initWithImage:object]; + + [image setTranslatesAutoresizingMaskIntoConstraints:NO]; + + if(index < [subviews count]) + [stack insertArrangedSubview:image atIndex:index]; + else + [stack addArrangedSubview:image]; + } + else + [image setImage:object]; + index++; + } + } + } + } +} -(NSMutableArray *)columnData { return columndata; } --(void)dealloc { [columndata release]; [super dealloc]; } +-(void)dealloc { [columndata release]; [super dealloc]; [stack removeFromSuperview]; [stack release]; } @end /* Create a tableview cell for containers using DW_CONTAINER_MODE_* or listboxes */ @@ -7233,16 +7323,14 @@ capacity = column + 1; if(!cd) - { cd = [NSMutableArray arrayWithCapacity:capacity]; - [cell setColumnData:cd]; - } if(cd) { while([cd count] <= column) [cd addObject:[NSNull null]]; [cd replaceObjectAtIndex:column withObject:(text ? text : icon)]; } + [cell setColumnData:cd]; } } else