From 6c6843dac6383753ebd2e739be8223314e9006d7 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 22 May 2016 14:37:02 -0400 Subject: [PATCH] Fixed non-wrapping uiMultlineEntries. --- README.md | 1 + darwin/autolayout.m | 39 ++++++++++++++++++++------------------- darwin/multilineentry.m | 10 +++++++++- darwin/uipriv_darwin.h | 2 +- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 0f602090..9fe5da4a 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ This README is being written.
** Removed `uiControlVerifyDestroy()`; that is now part of `uiFreeControl()` itself. ** Added `uiPi`, a constant for π. This is provided for C and C++ programmers, where there is no standard named constant for π; bindings authors shouldn't need to worry about this. ** Fixed uiMultilineEntry not properly having line breaks on Windows. +** Added `uiNewNonWrappingMultilineEntry()`, which creates a uiMultilineEntry that scrolls horizontally instead of wrapping lines. (This is not documented as being changeable after the fact on Windows, hence it's a creation-time choice.) ## Runtime Requirements diff --git a/darwin/autolayout.m b/darwin/autolayout.m index 19bb26ad..81530e75 100644 --- a/darwin/autolayout.m +++ b/darwin/autolayout.m @@ -150,9 +150,8 @@ void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int mar [c->bottomConstraintEqual setConstant:margin]; } -// from http://blog.bjhomer.com/2014/08/nsscrollview-and-autolayout.html because (as pointed out there) Apple's official guide is really only for iOS -// TODO this doesn't quite work with NSTextView; it *mostly* works -void scrollViewConstraintsEstablish(struct scrollViewConstraints *c, NSScrollView *sv, NSString *desc) +// 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 scrollViewConstraintsEstablish(struct scrollViewConstraints *c, NSScrollView *sv, BOOL hscroll, BOOL vscroll, NSString *desc) { NSView *cv, *dv; @@ -176,23 +175,25 @@ void scrollViewConstraintsEstablish(struct scrollViewConstraints *c, NSScrollVie [sv addConstraint:c->documentTop]; [c->documentTop retain]; - c->documentTrailing = mkConstraint(dv, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - cv, NSLayoutAttributeTrailing, - 1, 0, - [desc stringByAppendingString:@"document trailing constraint"]); - [sv addConstraint:c->documentTrailing]; - [c->documentTrailing retain]; + if (!hscroll) { + c->documentTrailing = mkConstraint(dv, NSLayoutAttributeTrailing, + NSLayoutRelationEqual, + cv, NSLayoutAttributeTrailing, + 1, 0, + [desc stringByAppendingString:@"document trailing constraint"]); + [sv addConstraint:c->documentTrailing]; + [c->documentTrailing retain]; + } -#if 0 - c->documentBottom = mkConstraint(dv, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - sv, NSLayoutAttributeBottom, - 1, 0, - [desc stringByAppendingString:@"document bottom constraint"]); - [sv addConstraint:c->documentBottom]; - [c->documentBottom retain]; -#endif + if (!vscroll) { + 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) diff --git a/darwin/multilineentry.m b/darwin/multilineentry.m index 7b248385..34611071 100644 --- a/darwin/multilineentry.m +++ b/darwin/multilineentry.m @@ -1,6 +1,8 @@ // 8 december 2015 #import "uipriv_darwin.h" +// TODO you actually have to click on parts with a line in them in order to start editing; clicking below the last line doesn't give focus + // NSTextView has no intrinsic content size by default, which wreaks havoc on a pure-Auto Layout system // we'll have to take over to get it to work // see also http://stackoverflow.com/questions/24210153/nstextview-not-properly-resizing-with-auto-layout and http://stackoverflow.com/questions/11237622/using-autolayout-with-expanding-nstextviews @@ -149,6 +151,12 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll) disableAutocorrect(e->tv); // this option is complex; just set it to the Interface Builder default [[e->tv layoutManager] setAllowsNonContiguousLayout:YES]; + if (hscroll) { + // TODO this is a giant mess + [e->tv setHorizontallyResizable:YES]; + [[e->tv textContainer] setWidthTracksTextView:NO]; + [[e->tv textContainer] setContainerSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)]; + } // don't use uiDarwinSetControlFont() directly; we have to do a little extra work to set the font font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]; [e->tv setTypingAttributes:[NSDictionary @@ -160,7 +168,7 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll) [e->sv setDocumentView:e->tv]; [e->tv setTranslatesAutoresizingMaskIntoConstraints:NO]; - scrollViewConstraintsEstablish(&(e->constraints), e->sv, @"uiMultilineEntry"); + scrollViewConstraintsEstablish(&(e->constraints), e->sv, hscroll, YES, @"uiMultilineEntry"); // needed to allow horizontal shrinking // TODO what about vertical text? [e->tv setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal]; diff --git a/darwin/uipriv_darwin.h b/darwin/uipriv_darwin.h index 2afded8f..4a8b1bdd 100644 --- a/darwin/uipriv_darwin.h +++ b/darwin/uipriv_darwin.h @@ -80,7 +80,7 @@ struct scrollViewConstraints { NSLayoutConstraint *documentWidth; NSLayoutConstraint *documentHeight; }; -extern void scrollViewConstraintsEstablish(struct scrollViewConstraints *c, NSScrollView *sv, NSString *desc); +extern void scrollViewConstraintsEstablish(struct scrollViewConstraints *c, NSScrollView *sv, BOOL hscroll, BOOL vscroll, NSString *desc); extern void scrollViewConstraintsRemove(struct scrollViewConstraints *c, NSScrollView *sv); // map.m