I keep trying to fix the MultiLineTextBox but it never actually gets fixed. I’ve been through the calculations over and over again, refining them, tidying them up and tinkering, but nothing ever seems to entirely fix the problems. I realised the other day that the calculations aren’t wrong; they’re the wrong calculations.
The MultiLineTextBox has three vertical alignment options. It can align to the top, centre or bottom of the visible screen. The getRowY() method, for calculating the Y co-ordinate of rows in all of these situations, works fine.
The class also has a draw(Rect) method that works out which rows of text fall within the supplied rect and only tries to draw those rows. This method also works fine.
The problem is that the draw() method is working with a different set of rows to the getRowY() method. The draw() method only clips based on top alignment, not all three possible alignment options, so it produces the wrong results.
I’ve now got a version of the MultiLineTextBox with four new draw methods - drawTextTop(), drawTextCentre() and drawTextBottom() (that work out which rows of text are visible) and drawText() (which is ultimately called by the previous three). It’s untested at the moment, but hopefully this will finally fix the problems.