Mercurial > dwindows
comparison ios/dw.m @ 2827:455d539ac555
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.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 01 Sep 2022 06:40:02 +0000 |
parents | 69e144d81f19 |
children | c543f7df7867 |
comparison
equal
deleted
inserted
replaced
2826:5f0483eb39a4 | 2827:455d539ac555 |
---|---|
2334 * Enabled via the DW_FEATURE_CONTAINER_MODE feature setting. | 2334 * Enabled via the DW_FEATURE_CONTAINER_MODE feature setting. |
2335 */ | 2335 */ |
2336 @interface DWTableViewCell : UITableViewCell | 2336 @interface DWTableViewCell : UITableViewCell |
2337 { | 2337 { |
2338 NSMutableArray *columndata; | 2338 NSMutableArray *columndata; |
2339 UIStackView *stack; | |
2339 } | 2340 } |
2340 -(void)setColumnData:(NSMutableArray *)input; | 2341 -(void)setColumnData:(NSMutableArray *)input; |
2341 -(NSMutableArray *)columnData; | 2342 -(NSMutableArray *)columnData; |
2342 @end | 2343 @end |
2343 | 2344 |
2344 @implementation DWTableViewCell | 2345 @implementation DWTableViewCell |
2345 -(void)setColumnData:(NSMutableArray *)input { [columndata release]; columndata = input; [columndata retain]; } | 2346 -(void)setColumnData:(NSMutableArray *)input |
2347 { | |
2348 if(columndata != input) | |
2349 { | |
2350 NSMutableArray *olddata = columndata; | |
2351 columndata = input; | |
2352 [columndata retain]; | |
2353 [olddata release]; | |
2354 } | |
2355 /* If we have columndata and are not in default mode */ | |
2356 if(columndata && _dw_container_mode > DW_CONTAINER_MODE_DEFAULT) | |
2357 { | |
2358 /* If we don't have a stack, create one */ | |
2359 if(!stack) | |
2360 { | |
2361 stack = [[[UIStackView alloc] init] retain]; | |
2362 [stack setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
2363 [stack setSpacing:5.0]; | |
2364 [[self contentView] addSubview:stack]; | |
2365 } | |
2366 /* Extra mode creates a horizontal stack with all the column data */ | |
2367 if(_dw_container_mode == DW_CONTAINER_MODE_EXTRA) | |
2368 { | |
2369 id subviews = [stack arrangedSubviews]; | |
2370 int index = 0; | |
2371 | |
2372 [stack setAxis:UILayoutConstraintAxisHorizontal]; | |
2373 /* Create the stack using columndata, reusing objects when possible */ | |
2374 for(id object in columndata) | |
2375 { | |
2376 if([object isKindOfClass:[NSString class]]) | |
2377 { | |
2378 UILabel *label = nil; | |
2379 | |
2380 if(index < [subviews count]) | |
2381 { | |
2382 id oldview = [subviews objectAtIndex:index]; | |
2383 | |
2384 if([oldview isMemberOfClass:[UILabel class]]) | |
2385 label = oldview; | |
2386 else | |
2387 [stack removeArrangedSubview:oldview]; | |
2388 } | |
2389 if(!label) | |
2390 { | |
2391 label = [[UILabel alloc] init]; | |
2392 | |
2393 [label setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
2394 [label setTextAlignment:NSTextAlignmentCenter]; | |
2395 | |
2396 if(index < [subviews count]) | |
2397 [stack insertArrangedSubview:label atIndex:index]; | |
2398 else | |
2399 [stack addArrangedSubview:label]; | |
2400 } | |
2401 [label setText:object]; | |
2402 index++; | |
2403 } | |
2404 else if([object isMemberOfClass:[UIImage class]]) | |
2405 { | |
2406 UIImageView *image = nil; | |
2407 | |
2408 if(index < [subviews count]) | |
2409 { | |
2410 id oldview = [subviews objectAtIndex:index]; | |
2411 | |
2412 if([oldview isMemberOfClass:[UIImageView class]]) | |
2413 image = oldview; | |
2414 else | |
2415 [stack removeArrangedSubview:oldview]; | |
2416 } | |
2417 if(!image) | |
2418 { | |
2419 image = [[UIImageView alloc] initWithImage:object]; | |
2420 | |
2421 [image setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
2422 | |
2423 if(index < [subviews count]) | |
2424 [stack insertArrangedSubview:image atIndex:index]; | |
2425 else | |
2426 [stack addArrangedSubview:image]; | |
2427 } | |
2428 else | |
2429 [image setImage:object]; | |
2430 index++; | |
2431 } | |
2432 } | |
2433 } | |
2434 } | |
2435 } | |
2346 -(NSMutableArray *)columnData { return columndata; } | 2436 -(NSMutableArray *)columnData { return columndata; } |
2347 -(void)dealloc { [columndata release]; [super dealloc]; } | 2437 -(void)dealloc { [columndata release]; [super dealloc]; [stack removeFromSuperview]; [stack release]; } |
2348 @end | 2438 @end |
2349 | 2439 |
2350 /* Create a tableview cell for containers using DW_CONTAINER_MODE_* or listboxes */ | 2440 /* Create a tableview cell for containers using DW_CONTAINER_MODE_* or listboxes */ |
2351 DWTableViewCell *_dw_table_cell_view_new(UIImage *icon, NSString *text, NSMutableArray *columndata) | 2441 DWTableViewCell *_dw_table_cell_view_new(UIImage *icon, NSString *text, NSMutableArray *columndata) |
2352 { | 2442 { |
7231 | 7321 |
7232 if(column >= capacity) | 7322 if(column >= capacity) |
7233 capacity = column + 1; | 7323 capacity = column + 1; |
7234 | 7324 |
7235 if(!cd) | 7325 if(!cd) |
7236 { | |
7237 cd = [NSMutableArray arrayWithCapacity:capacity]; | 7326 cd = [NSMutableArray arrayWithCapacity:capacity]; |
7238 [cell setColumnData:cd]; | |
7239 } | |
7240 if(cd) | 7327 if(cd) |
7241 { | 7328 { |
7242 while([cd count] <= column) | 7329 while([cd count] <= column) |
7243 [cd addObject:[NSNull null]]; | 7330 [cd addObject:[NSNull null]]; |
7244 [cd replaceObjectAtIndex:column withObject:(text ? text : icon)]; | 7331 [cd replaceObjectAtIndex:column withObject:(text ? text : icon)]; |
7245 } | 7332 } |
7333 [cell setColumnData:cd]; | |
7246 } | 7334 } |
7247 } | 7335 } |
7248 else | 7336 else |
7249 { | 7337 { |
7250 NSMutableArray *cd = [NSMutableArray arrayWithCapacity:(capacity > column ? capacity : column + 1)]; | 7338 NSMutableArray *cd = [NSMutableArray arrayWithCapacity:(capacity > column ? capacity : column + 1)]; |