Re: I want NSTextField to grow as text is entered
Re: I want NSTextField to grow as text is entered
- Subject: Re: I want NSTextField to grow as text is entered
- From: Ryan Stevens <email@hidden>
- Date: Tue, 10 May 2005 07:25:38 -0700
http://www.cocoadev.com/index.pl?CCDGrowingTextField
On May 9, 2005, at 1:37 AM, Ian Jackson wrote:
Hi,
I've been looking around for a solution to this problem, and there certainly seem to be people who can make this work, but after gathering together everything I understand about the text architecture, it just doesn't work. So with an NSView in a window, this was my attempt to make the simplest possible application to figure it out.
- (void)drawRect:(NSRect)rect
{
[self setAutoresizesSubviews:YES];
textStorage = [[NSTextStorage alloc] init];
NSLayoutManager *layoutManager;
layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];
[layoutManager release];
NSRect cFrame = [[[self window] contentView] frame];
NSTextContainer *container;
container = [[NSTextContainer alloc] initWithContainerSize:cFrame.size];
[container setWidthTracksTextView:NO];
[layoutManager addTextContainer:container];
[container release];
NSRect tvRect;
tvRect.origin.x = 150;
tvRect.origin.y = 150;
tvRect.size.width = 100;
tvRect.size.height = 100;
NSTextView *theTextView = [[NSTextView alloc] initWithFrame:tvRect textContainer:container];
[theTextView setPostsFrameChangedNotifications:YES];
[theTextView setHorizontallyResizable:YES];
[theTextView setAutoresizingMask:NSViewNotSizable];
[self addSubview:theTextView];
[theTextView release];
}
So this should be a fairly standard implementation of NSTextStorage, NSLayoutManager, etc. What I hope to happen is that as I type in the NSTextView the rect initially described by tvRect should grow and display text. But what actually happens is that the text continues on, but doesn't display till it gets to the edge of the container rect, when it starts on the next line of the NSTextView. I think there are only a few superfluous lines (e.g. setAutoresizesSubviews) but I really want to know what the key thing is that I'm missing. Thank you. _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden