Re: Autoresizable NSTextField (2)
Re: Autoresizable NSTextField (2)
- Subject: Re: Autoresizable NSTextField (2)
- From: Robbie Haertel <email@hidden>
- Date: Sat, 30 Oct 2004 10:53:38 -0600
There's another possibility. Maybe the text container isn't resizing.
I'm not sure of the exact details of the "auto-scroll" function of
the field editor, but it is possible that being auto-scroll, the text
container isn't growing. The solution would be to mess around with
disabling the auto-scroll BEFORE editing (I think there is a delegate
method of NSWindow that requests the field editor for a given object)
and then every update re-sizing the text container. Before you go to
the trouble, stick in an NSLog of the text container size before and
after you resize the Control. By the way,you should put hte NSLog of
the frame size before you resize the control and after you resize the
control (although you just might not have shown that code).
I just realized that my assumption was that the text scrolls instead
of growing. Is this the case or does the new text just disappear and
not scroll?
In the case that everything is being sized correctly, it must be an
issue of re-drawing. I've had similar problems I've never resolved
with the field editor not updating its display when I've tried to mess
with it.
By the way, the reason the text appears properly after you are done
editing is because the field editor is still getting all the text,
just not displaying it. When you hit enter, it calls some methods in
NSControl that grab the string value of the Field Editor and display
that. Remember that the field editor is drawn on top of the
NSControl, the NSControl itself does nothing to get the text.
Let me know what happens and best of luck,
Robbie
On Sat, 30 Oct 2004 10:59:35 +0200, Lorenzo <email@hidden> wrote:
>
Hi,
>
I did what you say (I hope) but, the fieldEditor already adjusts its frame
>
size and bounds size automatically. I have seen this putting two NSLog here
>
below. Anyway, I tried to set the size by myself and redisplay it but the
>
problem is still there. I cannot see the new text.
>
>
NSText *fE = [[self window] fieldEditor:NO forObject:self];
>
if(fE != nil){
>
NSLog(@"fEd FrameSize %.2f, %.2f",
>
[fE frame].size.width, [fE frame].size.height);
>
NSLog(@"fEd BoundsSize %.2f, %.2f",
>
[fE bounds].size.width, [fE bounds].size.height);
>
[fE setFrameSize:NSMakeSize(strWidth, [fE frame].size.height)];
>
[fE setNeedsDisplay:YES];
>
}
>
>
The good thing I didn't mention earlier is that when I close the editing
>
with [[self window] endEditingFor:self]; I can see the text properly.
>
>
>
Best Regards
>
--
>
Lorenzo
>
email: email@hidden
>
>
> From: Robbie Haertel <email@hidden>
>
> Reply-To: Robbie Haertel <email@hidden>
>
> Date: Fri, 29 Oct 2004 14:39:03 -0600
>
> To: Lorenzo <email@hidden>
>
> Subject: Re: Autoresizable NSTextField (2)
>
>
>
>
>
> I'm no expert, but I do know that NSControl through NSCell adds the
>
> window's default text editor as a subview (I can't remember what it is
>
> a subview to). So in effect, you have an NSTextField on top of your
>
> control. So, you have resized your control but not the text editor.
>
> Grab the window's text editor in your textDidChange: method and resize
>
> that as well. I haven't done this, but I know this is the problem. I
>
> just hope the solution works.
>
>
>
> Good luck!
>
> Robbie
>
>
>
>
>
> On Fri, 29 Oct 2004 22:21:07 +0200, Lorenzo <email@hidden> wrote:
>
>> Hi,
>
>> I asked already but it seems nobody knows how to fix this problem...
>
>> I am trying to make an autoresizable NSTextField. So any time I type a
>
>> character it sets its width to accomplish the width of the string.
>
>> In order to do that I check for the width of the string at any new character
>
>> typed, using the method "textDidChange", so I update the NSTextField width.
>
>>
>
>> The NSTextFiels updates its width properly, but I suppose its NSCell
>
>> doesn't, because the new NSTextField's area added looks like empty (no
>
>> visible text). How to fix this? Here's my code.
>
>>
>
>> - (void)textDidChange:(NSNotification *)aNotification
>
>> {
>
>> NSAttributedString *aString = [[self cell] attributedStringValue];
>
>> NSDictionary *attrDict;
>
>> float strWidth;
>
>>
>
>> attrDict = [aString attributesAtIndex:0 effectiveRange:nil];
>
>> strWidth = [[aString string] sizeWithAttributes:attrDict].width + 4;
>
>>
>
>> [self setFrameSize:NSMakeSize(strWidth, [self frame].size.height)];
>
>>
>
>> [self setNeedsDisplay:YES];
>
>> [[self superview] setNeedsDisplay:YES];
>
>> }
>
>>
>
>> Best Regards
>
>> --
>
>> Lorenzo
>
>> email: 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
>
>>
>
>
_______________________________________________
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