diff --git a/darwin/scrollview.m b/darwin/scrollview.m index 5767e00f..ec24cbd5 100644 --- a/darwin/scrollview.m +++ b/darwin/scrollview.m @@ -1,15 +1,11 @@ // 27 may 2016 #include "uipriv_darwin.h" -// TODO scrolled drawing test may have a random size outside the area size +// see http://stackoverflow.com/questions/37979445/how-do-i-properly-set-up-a-scrolling-nstableview-using-auto-layout-what-ive-tr for why we don't use auto layout struct scrollViewData { - NSLayoutConstraint *documentLeading; - NSLayoutConstraint *documentTop; BOOL hscroll; - NSLayoutConstraint *documentTrailing; BOOL vscroll; - NSLayoutConstraint *documentBottom; }; NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout) @@ -41,7 +37,6 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa [sv setVerticalScrollElasticity:NSScrollElasticityAutomatic]; [sv setAllowsMagnification:NO]; - [p->DocumentView setTranslatesAutoresizingMaskIntoConstraints:NO]; [sv setDocumentView:p->DocumentView]; d = uiNew(struct scrollViewData); scrollViewSetScrolling(sv, d, p->HScroll, p->VScroll); @@ -50,85 +45,16 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa return sv; } -static void scrollViewConstraintsRemove(NSScrollView *sv, struct scrollViewData *d) -{ - if (d->documentLeading != nil) { - [sv removeConstraint:d->documentLeading]; - [d->documentLeading release]; - d->documentLeading = nil; - } - if (d->documentTop != nil) { - [sv removeConstraint:d->documentTop]; - [d->documentTop release]; - d->documentTop = nil; - } - if (d->documentTrailing != nil) { - [sv removeConstraint:d->documentTrailing]; - [d->documentTrailing release]; - d->documentTrailing = nil; - } - if (d->documentBottom != nil) { - [sv removeConstraint:d->documentBottom]; - [d->documentBottom release]; - d->documentBottom = nil; - } -} - // based on http://blog.bjhomer.com/2014/08/nsscrollview-and-autolayout.html because (as pointed out there) Apple's official guide is really only for iOS void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hscroll, BOOL vscroll) { - NSView *cv, *dv; - NSLayoutRelation rel; - - scrollViewConstraintsRemove(sv, d); - cv = [sv contentView]; - dv = [sv documentView]; - - d->documentLeading = mkConstraint(dv, NSLayoutAttributeLeading, - NSLayoutRelationEqual, - cv, NSLayoutAttributeLeading, - 1, 0, - @"NSScrollView document leading constraint"); - [sv addConstraint:d->documentLeading]; - [d->documentLeading retain]; - - d->documentTop = mkConstraint(dv, NSLayoutAttributeTop, - NSLayoutRelationEqual, - cv, NSLayoutAttributeTop, - 1, 0, - @"NSScrollView document top constraint"); - [sv addConstraint:d->documentTop]; - [d->documentTop retain]; - d->hscroll = hscroll; [sv setHasHorizontalScroller:d->hscroll]; - rel = NSLayoutRelationGreaterThanOrEqual; - if (!d->hscroll) - rel = NSLayoutRelationEqual; - d->documentTrailing = mkConstraint(dv, NSLayoutAttributeTrailing, - rel, - cv, NSLayoutAttributeTrailing, - 1, 0, - @"NSScrollView document trailing constraint"); - [sv addConstraint:d->documentTrailing]; - [d->documentTrailing retain]; - d->vscroll = vscroll; [sv setHasVerticalScroller:d->vscroll]; - rel = NSLayoutRelationGreaterThanOrEqual; - if (!d->vscroll) - rel = NSLayoutRelationEqual; - d->documentBottom = mkConstraint(dv, NSLayoutAttributeBottom, - rel, - cv, NSLayoutAttributeBottom, - 1, 0, - @"NSScrollView document bottom constraint"); - [sv addConstraint:d->documentBottom]; - [d->documentBottom retain]; } void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d) { - scrollViewConstraintsRemove(sv, d); uiFree(d); } diff --git a/darwin/table.m b/darwin/table.m index 862e0bd9..c46f4249 100644 --- a/darwin/table.m +++ b/darwin/table.m @@ -322,16 +322,5 @@ uiTable *uiNewTable(uiTableModel *model) p.VScroll = YES; t->sv = mkScrollView(&p, &(t->d)); - dispatch_after( - dispatch_time(DISPATCH_TIME_NOW,3*NSEC_PER_SEC), - dispatch_get_main_queue(), - ^{ - for(NSView *v in t->sv.subviews){ - NSLog(@"%@ %p %@", [v class], v, NSStringFromRect([v frame])); - for(NSView *v2 in v.subviews) - NSLog(@" %@ %p %@", [v2 class], v2, NSStringFromRect([v2 frame])); - } - }); - return t; }