Re: Resizing custom subclassed NSTextView
Re: Resizing custom subclassed NSTextView
- Subject: Re: Resizing custom subclassed NSTextView
- From: Joe White <email@hidden>
- Date: Thu, 09 Jun 2011 11:11:33 +0100
Hi Ross
On 9 June 2011 01:51, Ross Carter <email@hidden> wrote:
> On Jun 8, 2011, at 7:19 PM, Joe White wrote:
>
> > Basically, the interface is separate editable objects that are usually
> single symbols with a few arguments included. This means that the each
> object is always one line high and usually not that wide.
> >
> > I started off using NSTextField (which I could resize easily) but I want
> to add syntax highlighting and auto-completion. From what I read NSTextView
> is the way forward.
>
> First let me say that I have not done what you are doing, so my advice is a
> mere guess. Others may have better advice.
>
> It seems to me that you need to use NSTextField objects and subclass the
> field editor to provide the custom behavior you need. It might be easiest to
> get one text view working the way you want and then look into using that
> text view class as the field editor.
>
>
> > Thanks for the code, it does indeed resize for me. However it doesn't
> shrink when I remove text.
> >
> > From poring over the Apple docs again (
> http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextLayout/Tasks/StringHeight.html)
> I managed to get my the NSTextView subclass to resize. However it doesn't
> redraw itself and looks weird until I change the size of the main canvas.
>
> Right, I forgot about that. The textView is resizing when you remove
> characters, but its superview is not updating. If you observe the
> NSViewFrameDidChangeNotification for the textView, you can update the
> display of its superview and watch the textView grow and shrink.
>
> [tv setPostsFrameChangedNotifications:YES];
> [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewFrameDidChange:)
> name:NSViewFrameDidChangeNotification object:tv];
>
> - (void)textViewFrameDidChange:(NSNotification *)note {
> [[[note object] superview] setNeedsDisplayInRect:<calculate a
> reasonable rect here>];
> }
>
Thanks, I thought this was case. I'll try it out later.
>
>
> > Would you say I am taking the wrong approach? All I wish to do is to have
> multiple instances of an object each with its own resizable/auto completing
> text field as a subview.
>
> If you've got syntax highlighting and auto-correction working the way you
> want, I'd say you're most of the way there. If you have only a few text
> objects or if the app is not for production, text views are fine. In
> production, I'd want to use text fields instead of text views to avoid the
> overhead of having a layout manager for every one of those text objects.
>
> We'll that's the thing with NSTextView - Auto-completion is kinda already
set-up, I can get suggestions (although not correct) by pressing esc. For
syntax highlighting I found this for inspiration -
http://www.cocoadev.com/index.pl?ImplementSyntaxHighlighting
However it is a concern about overhead. The interface would look very
similar to this - http://rhoadley.org/images/screenshots/pd/anomap.gif.
However there is the potential it could look like this -
http://goto10.org/wp-content/uploads/goto10.org/2008/11/pure_data-workshop.png
I think it would solve all my problems if I was able to do auto-completion,
etc... with NSTextField. I don't have enough knowledge of the Cocoa API to
make an informed decision yet.
Thank you very much for the feedback,
Joe
--
Joe White
Production Department, RjDj
Tel : +44 7515 731499
Reality Jockey Ltd.
Floor B “The Mission”
55 Holywell Lane
London
EC2A 3PQ
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden