Multi-line text boxes

A place to request and discuss new engine features / functionality

Multi-line text boxes

Postby ChrisEt » Sun Aug 31, 2014 2:40 pm

Hi guys,

I don't know if you have noticed, but IGE implements multi-line text boxes in a sub-optimal way: The line height is determined by taking the height of the text box and dividing it by the number of lines (following code is from IgeFontSmartTexture, simplified):

Code: Select all
lineHeight = Math.floor(entity._geometry.y / lineArr.length);
renderStartY = -(lineHeight / 2) * (lineArr.length - 1);

for (i = 0; i < lineArr.length; i++) {
    renderY = renderStartY + (lineHeight * i);

    // Draw text
    ctx.fillText(lineArr[i], 0, renderY);
}


This means that you have to know in advance the number of lines so you can choose the element's height accordingly, or else it may happen that lines overlap.

I did a little bit of reading and the source of the problem is HTML5 not having a way to output multi-line text. Instead you have to output line after line and choose the line height yourself.


I'm proposing the following changes:
  • The line height is fixed per text box and doesn't change with the text box's height.
  • Text boxes (more precisely: IgeFontEntities) have an attribute which can be used to change the line height.
    It defaults to 20 pixels. I suggest to use existing textLineSpacing.
  • If anybody knows a way to read the font size we could use that to calculate a default line height. But what I could find out this is not possible.

When the text lines don't fill the whole vertical space, vertical text alignment matters. I'm going to implement that now (textAlignY is not yet implemented).

What do you think? Have you come across that issue? How did you solve that?

Cheers,
Christian
ChrisEt
 
Posts: 17
Joined: Thu Oct 24, 2013 8:59 pm

Re: Multi-line text boxes

Postby ChrisEt » Sun Aug 31, 2014 4:40 pm

Ok, I implemented this in https://github.com/coolbloke1324/ige/commit/8d85771a8f9554697bcd5cb6c2e3b97b81c7d014

What do you think? Ready to make it a pull request? Or would you rather use a different attribute than textLineSpacing?

Feedback is appreciated!
ChrisEt
 
Posts: 17
Joined: Thu Oct 24, 2013 8:59 pm


Return to New Feature Discussion

Who is online

Users browsing this forum: No registered users and 1 guest
cron