Issue with TextNode

When a TextNode’s text has whitespace (spaces or tabs) on the left hand side of the text, it renders OK.

When a TextNode has whitespace (spaces or tabs) on the right hand side of the text, it never renders.

Example:

import direct.directbase.DirectStart
from panda3d.core import TextNode

myTextNode = render2d.attachNewNode(TextNode('myTextNode'))
myTextNode.node().setText('\t\t\t  left spacing works, right spacing fails  \t\t\t')
myTextNode.node().setAlign(TextNode.ACenter)
myTextNode.node().setCardAsMargin(0, 0, 0, 0)
myTextNode.node().setCardColor(0, 0, 0, 1)
myTextNode.setScale(0.05)

run()

Does anyone have a solution to this? I would expect TextNode to put spacing on the right just like it did on the left, why is it failing to do so? Bug or intentional?

Thank you tons,
~powerpup118

Hmm, I guess that’s a bug. As a workaround, why not just use the parameters to setCardAsMargin() to add this additional spacing, instead of embedding it in the text itself? For instance, setCardAsMargin(2, 2, 0, 0).

David

I suppose that’s the only way it’ll work, this is for a user-input widget, like DirectEntry for instance, would have been more conveniant if tabs and spaces worked, I suppose checking the end of the string for whitespace and converting it to padding will have to work for now though :slight_smile:

Thank you for helping me out,
~powerpup118

It appears this is either:

A. No bug

or:

B. A bug that was fixed.

Calling the method setPreserveTrailingWhitespace on the TextNode and passing in the argument True, will fix this issue.

Hope this helps,
~powerpup118