Made a more intelligent Table.preferredSize() for Mac OS X.
This commit is contained in:
parent
d30956d625
commit
5ec2c768fa
|
@ -28,7 +28,7 @@ void setSmallControlFont(id control)
|
|||
[toNSControl(control) setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
|
||||
}
|
||||
|
||||
// also good for NSTableView (TODO might not do what we want) and NSProgressIndicator
|
||||
// also good for NSProgressIndicator
|
||||
struct xsize controlPreferredSize(id control)
|
||||
{
|
||||
NSControl *c;
|
||||
|
|
|
@ -84,6 +84,7 @@ extern id newTable(void);
|
|||
extern void tableAppendColumn(id, char *);
|
||||
extern void tableUpdate(id);
|
||||
extern void tableMakeDataSource(id, void *);
|
||||
extern struct xsize tablePreferredSize(id);
|
||||
|
||||
/* control_darwin.m */
|
||||
extern void parent(id, id);
|
||||
|
|
|
@ -76,7 +76,8 @@ func (t *table) allocate(x int, y int, width int, height int, d *sizing) []*allo
|
|||
}
|
||||
|
||||
func (t *table) preferredSize(d *sizing) (width, height int) {
|
||||
return basepreferredSize(t, d)
|
||||
s := C.tablePreferredSize(t._id)
|
||||
return int(s.width), int(s.height)
|
||||
}
|
||||
|
||||
func (t *table) commitResize(c *allocation, d *sizing) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue