diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-10 15:56:59 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-10 15:56:59 -0400 |
| commit | 5ec2c768face785c502ee6508b5ed5ed0124b307 (patch) | |
| tree | 38de710ac54dad8d82660f4bdad9955edaf896f0 /redo/table_darwin.m | |
| parent | d30956d625cd83fd0c6ade761139d5c6834c1e6c (diff) | |
Made a more intelligent Table.preferredSize() for Mac OS X.
Diffstat (limited to 'redo/table_darwin.m')
| -rw-r--r-- | redo/table_darwin.m | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/redo/table_darwin.m b/redo/table_darwin.m index 9a16082..e679c1d 100644 --- a/redo/table_darwin.m +++ b/redo/table_darwin.m @@ -72,3 +72,34 @@ void tableMakeDataSource(id table, void *gotable) model->gotable = gotable; [toNSTableView(table) setDataSource:model]; } + +// -[NSTableView sizeToFit] does not actually size to fit +// -[NSTableColumn sizeToFit] is just for the header +// -[NSTableColumn sizeToFit] can work for guessing but overrides user settings +// -[[NSTableColumn headerCell] cellSize] does NOT (despite being documented as returning the minimum needed size) +// Let's write our own to prefer: +// - width of the sum of all columns's current widths +// - height of 5 rows (arbitrary count; seems reasonable) + header view height +// Hopefully this is reasonable. +struct xsize tablePreferredSize(id control) +{ + NSTableView *t; + NSArray *columns; + struct xsize s; + NSUInteger i, n; + NSTableColumn *c; + + t = toNSTableView(control); + columns = [t tableColumns]; + n = [columns count]; + s.width = 0; + for (i = 0; i < n; i++) { + CGFloat width; + + c = (NSTableColumn *) [columns objectAtIndex:i]; + s.width += (intptr_t) [c width]; + } + s.height = 5 * (intptr_t) [t rowHeight]; + s.height += (intptr_t) [[t headerView] frame].size.height; + return s; +} |
