• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextField or NSTextView with fixed baseline
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField or NSTextView with fixed baseline


  • Subject: Re: NSTextField or NSTextView with fixed baseline
  • From: Jon Steinmetz <email@hidden>
  • Date: Tue, 25 Oct 2005 16:03:48 -0500


On Oct 6, 2005, at 4:07 PM, Douglas Davidson wrote:

On Oct 6, 2005, at 1:51 PM, Jon Steinmetz wrote:

My current prototype uses an NSTextView with no border or background drawing but this has (at least) two problems. The first is that the text will wrap and the second is that I have no control over the baseline, the text lines are anchored to the top of the frame of the text view. I could use NSTextField to solve the line wrapping if I can still edit and retrieve RTF text. Since a NSTextView is used as the field editor there must also be a way to make NSTextView not wrap lines.


See the TextSizingExample for examples of how to set up a text view so that it does not wrap. As for the baseline issue, I don't have a prepared solution for you, but I would note that you can control the position of the text container within the text view, for example by overriding -textContainerOrigin.



I thought I would respond to this with my solution to help those with the same problem.


The wrapping can be fixed by either using NSTextField or by looking at the TextSizingExample. The example basically involves putting the NSTextView into a NSClipView to get the horizontal scrolling behavior.

The baseline problem is fixed by using something like the following snippet:

    if( fixedBaseline > 0.0 ) {
        NSLayoutManager* lm = [ self layoutManager ];
        NSTypesetter* ts = [ lm typesetter ];

if( [ lm isValidGlyphIndex: 0 ] ) {
NSRect glyphBounds = [ lm lineFragmentRectForGlyphAtIndex: 0
effectiveRange: nil ];


double baseline = [ ts baselineOffsetInLayoutManager: lm glyphIndex: 0 ];
double vOffset = ( glyphBounds.size.height - baseline ) - fixedBaseline;
[ self setTextContainerInset: NSMakeSize( 0, -vOffset ) ];
}
}


Where fixedBaseline is where you want the baseline to be from the top of NSTextField and self is the NSTextField. Usual caveats apply to the snippet, do better error checking, etc. This snippet can be called after the contents change and that appears to be enough to keep the baseline in a fixed location.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

References: 
 >NSTextField or NSTextView with fixed baseline (From: Jon Steinmetz <email@hidden>)
 >Re: NSTextField or NSTextView with fixed baseline (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: Updated: NSTextView:setString stalls sometimes...
  • Next by Date: Validating the contents of an accessory view
  • Previous by thread: Re: NSTextField or NSTextView with fixed baseline
  • Next by thread: Validating the contents of an accessory view
  • Index(es):
    • Date
    • Thread