More fixes, this time to uiMultilineEntry. Almost there!

This commit is contained in:
Pietro Gagliardi 2016-05-12 21:24:12 -04:00
parent b1680aa8e2
commit 533a9b150e
1 changed files with 40 additions and 2 deletions

View File

@ -1,10 +1,48 @@
// 8 december 2015 // 8 december 2015
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
// 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
@interface intrinsicSizeTextView : NSTextView
@end
@implementation intrinsicSizeTextView
// TODO does this prevent shrinking horizontally?
- (NSSize)intrinsicContentSize
{
NSTextContainer *textContainer;
NSLayoutManager *layoutManager;
NSRect rect;
textContainer = [self textContainer];
layoutManager = [self layoutManager];
[layoutManager ensureLayoutForTextContainer:textContainer];
rect = [layoutManager usedRectForTextContainer:textContainer];
return rect.size;
}
- (void)didChangeText
{
[super didChangeText];
[self invalidateIntrinsicContentSize];
}
// TODO this doesn't call the above?
// TODO this also isn't perfect; play around with cpp-multithread
- (void)setString:(NSString *)str
{
[super setString:str];
[self didChangeText];
}
@end
struct uiMultilineEntry { struct uiMultilineEntry {
uiDarwinControl c; uiDarwinControl c;
NSScrollView *sv; NSScrollView *sv;
NSTextView *tv; intrinsicSizeTextView *tv;
void (*onChanged)(uiMultilineEntry *, void *); void (*onChanged)(uiMultilineEntry *, void *);
void *onChangedData; void *onChangedData;
struct scrollViewConstraints constraints; struct scrollViewConstraints constraints;
@ -78,7 +116,7 @@ uiMultilineEntry *uiNewMultilineEntry(void)
[e->sv setAutohidesScrollers:YES]; [e->sv setAutohidesScrollers:YES];
[e->sv setBorderType:NSBezelBorder]; [e->sv setBorderType:NSBezelBorder];
e->tv = [[NSTextView alloc] initWithFrame:NSZeroRect]; e->tv = [[intrinsicSizeTextView alloc] initWithFrame:NSZeroRect];
// verified against Interface Builder, except for rich text options // verified against Interface Builder, except for rich text options
[e->tv setAllowsDocumentBackgroundColorChange:NO]; [e->tv setAllowsDocumentBackgroundColorChange:NO];
[e->tv setBackgroundColor:[NSColor textBackgroundColor]]; [e->tv setBackgroundColor:[NSColor textBackgroundColor]];