Removed auto layout from scrollviews. Need to do the same to text views too.
This commit is contained in:
parent
0ef01e1685
commit
ddd0e82c90
|
@ -1,15 +1,11 @@
|
||||||
// 27 may 2016
|
// 27 may 2016
|
||||||
#include "uipriv_darwin.h"
|
#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 {
|
struct scrollViewData {
|
||||||
NSLayoutConstraint *documentLeading;
|
|
||||||
NSLayoutConstraint *documentTop;
|
|
||||||
BOOL hscroll;
|
BOOL hscroll;
|
||||||
NSLayoutConstraint *documentTrailing;
|
|
||||||
BOOL vscroll;
|
BOOL vscroll;
|
||||||
NSLayoutConstraint *documentBottom;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout)
|
NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout)
|
||||||
|
@ -41,7 +37,6 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa
|
||||||
[sv setVerticalScrollElasticity:NSScrollElasticityAutomatic];
|
[sv setVerticalScrollElasticity:NSScrollElasticityAutomatic];
|
||||||
[sv setAllowsMagnification:NO];
|
[sv setAllowsMagnification:NO];
|
||||||
|
|
||||||
[p->DocumentView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
|
||||||
[sv setDocumentView:p->DocumentView];
|
[sv setDocumentView:p->DocumentView];
|
||||||
d = uiNew(struct scrollViewData);
|
d = uiNew(struct scrollViewData);
|
||||||
scrollViewSetScrolling(sv, d, p->HScroll, p->VScroll);
|
scrollViewSetScrolling(sv, d, p->HScroll, p->VScroll);
|
||||||
|
@ -50,85 +45,16 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa
|
||||||
return sv;
|
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
|
// 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)
|
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;
|
d->hscroll = hscroll;
|
||||||
[sv setHasHorizontalScroller:d->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;
|
d->vscroll = vscroll;
|
||||||
[sv setHasVerticalScroller:d->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)
|
void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d)
|
||||||
{
|
{
|
||||||
scrollViewConstraintsRemove(sv, d);
|
|
||||||
uiFree(d);
|
uiFree(d);
|
||||||
}
|
}
|
||||||
|
|
|
@ -322,16 +322,5 @@ uiTable *uiNewTable(uiTableModel *model)
|
||||||
p.VScroll = YES;
|
p.VScroll = YES;
|
||||||
t->sv = mkScrollView(&p, &(t->d));
|
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;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue