Fixed non-wrapping uiMultlineEntries.

This commit is contained in:
Pietro Gagliardi 2016-05-22 14:37:02 -04:00
parent 07cd03452d
commit 6c6843dac6
4 changed files with 31 additions and 21 deletions

View File

@ -18,6 +18,7 @@ This README is being written.<br>
** 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

View File

@ -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)

View File

@ -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];

View File

@ -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