• 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
Will this code work?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Will this code work?


  • Subject: Will this code work?
  • From: email@hidden
  • Date: Wed, 12 Jul 2006 15:30:05 +0000

Hi all,

I have an nstextview which I want to be three lines long and scroll horizontally so I use the following code in the awakefromNib to achieve this:

       [vSequenceTextView setHorizontallyResizable:YES];
	[vSequenceTextView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
	[[vSequenceTextView textContainer] setContainerSize:NSMakeSize(FLT_MAX,FLT_MAX)];
	[[vSequenceTextView textContainer]setWidthTracksTextView:NO];
	NSRect tvFrameRect=[vSequenceTextView frame];
	tvFrameRect.size.width=FLT_MAX;
	[vSequenceTextView setFrame:tvFrameRect];

Scrolling for this text view (vSequenceTextView) is controlled by a scroller present on an nstableview.  So when the tableview scrolls so does my textview.  What I want to do is figure out what characters are being displayed in the textview after scrolling.  I listen to NSViewBoundsDidChangeNotification from the tableview and in the selector method for this notification I have the following code:

	NSLayoutManager* layoutManager=[vSequenceTextView layoutManager];
	int index=0;
	int numberOfLs=0;
	NSRange lineRange;
	while (index<numberOfGlyphs)
	{
		//get lineRange for charachters
		[layoutManager lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange];
		numberOfLs++;
		index=NSMaxRange(lineRange);
            //Only care about the characters in the 3rd line
            if (numberOfLs>2)
		{
			//figure out amount of room each character takes (using courier as font)
                     float charSize=boundsRect.size.width/lineRange.length;
			changedBoundsOrigin = [changedContentView bounds].origin;
                    //figure out what the location of first visible character
			float temp=changedBoundsOrigin.x/charSize;
		}
         }

Basically, I go down to the third line and try to figure out how much size each character is taking in the display and then based on that calculate which characters are visible.  Is there a better way of doing this?

Thanks in advance

Sarven
 _______________________________________________
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

  • Prev by Date: Re: crash in [NSAnimation _stopAnimation:]
  • Next by Date: End editing in an NSComboBox
  • Previous by thread: Re: pathForResource:ofType: failes under panther. (SOLVED)
  • Next by thread: End editing in an NSComboBox
  • Index(es):
    • Date
    • Thread