[Biococoa-dev] calculating symbols per column

Koen van der Drift kvddrift at earthlink.net
Fri Apr 21 22:12:44 EDT 2006


I have been puzzling a bit with some code to set the number of  
symbols per column in the BCSequenceView, right now it is hard coded  
to 10, but it would be nice if we make this flexible.  Instead of the  
number of symbols in a column, the textContainer for the sequenceView  
needs to know the actual width of that particular number of symbols.  
Assuming we are using a monospaced font and don't mix lower and  
uppercase strings, I came up with the following code. First get the  
width of each character, this can be done in two ways (I am not sure  
which ones of the two to choose):

	float		characterWidth = [[self font] boundingRectForFont].size.width;


	float		characterWidth = [[self font] maximumAdvancement].width;
Then from that calculate the width of the column:

	float		columnWidth = (float) (symbolsPerColumn * characterWidth );

And pass it to the textContainer and layoutManager:

	[(BCSequenceViewContainer *) [self textContainer] setColumnWidth:  
	[(BCSequenceViewLayoutManager *) [self layoutManager]  
setSymbolsPerColumn: symbolsPerColumn];

As you may have guessed, that doesn't work as expected, I get more  
than the expected number of symbols in a column. Also the selection  
code gets screwed up a bit.

Any suggestions/ideas?


- Koen.

More information about the Biococoa-dev mailing list