More work. I can't figure out where these phantom constraints come from.

This commit is contained in:
Pietro Gagliardi 2016-05-12 17:09:24 -04:00
parent 897674d20f
commit 257c182f2b
3 changed files with 91 additions and 3 deletions

View File

@ -105,3 +105,81 @@ void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int mar
if (c->bottomConstraint != nil) if (c->bottomConstraint != nil)
[c->bottomConstraint setConstant:margin]; [c->bottomConstraint setConstant:margin];
} }
// from https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithScrollViews.html#//apple_ref/doc/uid/TP40010853-CH24-SW1
// note: if the xcode-specific label is set to Content View, the view actually becomes the *document* view
// TODO are these instructions wrong? if we have the bottom we can't scroll vertically, and if we have spacing we can't scroll regardless
void scrollViewConstraintsEstablish(struct scrollViewConstraints *c, NSScrollView *sv, NSString *desc)
{
NSView *cv, *dv;
scrollViewConstraintsRemove(c, sv);
cv = [sv contentView];
dv = [sv documentView];
c->documentLeading = mkConstraint(dv, NSLayoutAttributeLeading,
NSLayoutRelationEqual,
sv, NSLayoutAttributeLeading,
1, 0,
[desc stringByAppendingString:@"document leading constraint"]);
[sv addConstraint:c->documentLeading];
[c->documentLeading retain];
c->documentTop = mkConstraint(dv, NSLayoutAttributeTop,
NSLayoutRelationEqual,
sv, NSLayoutAttributeTop,
1, 0,
[desc stringByAppendingString:@"document top constraint"]);
[sv addConstraint:c->documentTop];
[c->documentTop retain];
c->documentTrailing = mkConstraint(dv, NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
sv, NSLayoutAttributeTrailing,
1, 0,
[desc stringByAppendingString:@"document trailing constraint"]);
[sv addConstraint:c->documentTrailing];
[c->documentTrailing retain];
c->documentBottom = mkConstraint(dv, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
sv, NSLayoutAttributeBottom,
1, 0,
[desc stringByAppendingString:@"document bottom constraint"]);
[sv addConstraint:c->documentBottom];
[c->documentBottom retain];
}
void scrollViewConstraintsRemove(struct scrollViewConstraints *c, NSScrollView *sv)
{
if (c->documentLeading != nil) {
[sv removeConstraint:c->documentLeading];
[c->documentLeading release];
c->documentLeading = nil;
}
if (c->documentTop != nil) {
[sv removeConstraint:c->documentTop];
[c->documentTop release];
c->documentTop = nil;
}
if (c->documentTrailing != nil) {
[sv removeConstraint:c->documentTrailing];
[c->documentTrailing release];
c->documentTrailing = nil;
}
if (c->documentBottom != nil) {
[sv removeConstraint:c->documentBottom];
[c->documentBottom release];
c->documentBottom = nil;
}
if (c->documentWidth != nil) {
[sv removeConstraint:c->documentWidth];
[c->documentWidth release];
c->documentWidth = nil;
}
if (c->documentHeight != nil) {
[sv removeConstraint:c->documentHeight];
[c->documentHeight release];
c->documentHeight = nil;
}
}

View File

@ -7,10 +7,12 @@ struct uiMultilineEntry {
NSTextView *tv; NSTextView *tv;
void (*onChanged)(uiMultilineEntry *, void *); void (*onChanged)(uiMultilineEntry *, void *);
void *onChangedData; void *onChangedData;
struct scrollViewConstraints constraints;
}; };
// TODO events // TODO events
// TODO destroy
uiDarwinControlAllDefaults(uiMultilineEntry, sv) uiDarwinControlAllDefaults(uiMultilineEntry, sv)
static void defaultOnChanged(uiMultilineEntry *e, void *data) static void defaultOnChanged(uiMultilineEntry *e, void *data)
@ -119,11 +121,9 @@ uiMultilineEntry *uiNewMultilineEntry(void)
// let's just set it to the standard control font anyway, just to be safe // let's just set it to the standard control font anyway, just to be safe
[e->tv setFont:font]; [e->tv setFont:font];
//TODO [e->tv setTranslatesAutoresizingMaskIntoConstraints:NO];
[e->sv setDocumentView:e->tv]; [e->sv setDocumentView:e->tv];
[e->tv setTranslatesAutoresizingMaskIntoConstraints:NO]; [e->tv setTranslatesAutoresizingMaskIntoConstraints:NO];
// we don't need to save the NSMutableArray scrollViewConstraintsEstablish(&(e->constraints), e->sv, @"uiMultilineEntry");
//TODO [layoutScrollViewContents(e->sv, YES, NO, @"uiMultilineEntry") release];
//TODO:void printinfo(NSScrollView *sv, NSTextView *tv); //TODO:void printinfo(NSScrollView *sv, NSTextView *tv);
//printinfo(e->sv, e->tv); //printinfo(e->sv, e->tv);

View File

@ -66,6 +66,16 @@ struct singleChildConstraints {
extern void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *contentView, NSView *childView, BOOL hugsTrailing, BOOL hugsBottom, int margined, NSString *desc); extern void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *contentView, NSView *childView, BOOL hugsTrailing, BOOL hugsBottom, int margined, NSString *desc);
extern void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv); extern void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv);
extern void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int margined); extern void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int margined);
struct scrollViewConstraints {
NSLayoutConstraint *documentLeading;
NSLayoutConstraint *documentTop;
NSLayoutConstraint *documentTrailing;
NSLayoutConstraint *documentBottom;
NSLayoutConstraint *documentWidth;
NSLayoutConstraint *documentHeight;
};
extern void scrollViewConstraintsEstablish(struct scrollViewConstraints *c, NSScrollView *sv, NSString *desc);
extern void scrollViewConstraintsRemove(struct scrollViewConstraints *c, NSScrollView *sv);
// map.m // map.m
extern struct mapTable *newMap(void); extern struct mapTable *newMap(void);