Skip to content

Instantly share code, notes, and snippets.

@darwin

darwin/tf.mm Secret

Created October 10, 2016 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darwin/2d17b0a74125de9f4c847e5bacfbf941 to your computer and use it in GitHub Desktop.
Save darwin/2d17b0a74125de9f4c847e5bacfbf941 to your computer and use it in GitHub Desktop.
long goodWidthForColumn(TColumnViewPtr self, NSInteger column) {
NSBrowserTableViewPtrOrNil browserTable = [self browserTableViewAtIndex:column];
if (!browserTable) {
AUTO_LOG(@"no browser table => bail out");
return 0;
}
auto numberOfRows = [browserTable numberOfRows];
if (numberOfRows == 0) {
AUTO_LOG(@"column=%ld numberOfRows=%ld => bail out", column, numberOfRows);
return 0;
}
TColumnViewControllerPtr controller = [self controller];
if (!controller) {
AUTO_LOG(@"no controller => bail out");
return 0;
}
auto width = [controller sizeToFitWidthOfColumn:column forRange:NSMakeRange(0, numberOfRows)];
AUTO_LOG(@"column=%ld numberOfRows=%ld width=%f", column, numberOfRows, width);
// ad-hoc 20px addition to really make sure nothing remains shortened, sizeToFitWidthOfColumn probably does not reflect scrollbars
// this can be tricky because width measurement is affected by System Preferences -> General -> scrollbar settings and also by Finder's state,
// for example if you are in a drobox folder, those file badge icons take up some extra space, sizeToFitWidthOfColumn does not account for that
// and Finder (10.11) itself behaves inconsistently (when double-clicking on resizing gripper)
// see support email from Colin Callahan <***redacted***@***.com>
int correction = intAutoWidthCorrection();
if (!correction) {
correction = 20; // default correction
}
width += correction;
width = [PLUGIN $clampWidth:width];
return width;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment