tobspr / LUI

Lightweight User Interface for Panda3D
MIT License
84 stars 24 forks source link

Implement text wordwrap #27

Closed michaeladams closed 7 years ago

michaeladams commented 7 years ago

I noticed wordwrap didn't seem to be implemented, and I wanted some longtext/paragraph support in my game.

The LuiText.cxx changes and moving the init function around in the LUILabel.py I'm not too sure about - but everything seems to be working ok.

I didn't use FormattedLabel because the logic around the add function is slightly different, although I could maybe put the changes into a FormattedLabel and implement a new widget if thats better.

You can add wrapping to an existing label by passing wordwrap=True and a width into the constructor. (If you don't pass a width, it'll be 0, so will wrap on every character). I couldn't figure out how to get the ACTUAL width of a parent element, it'd always return 0 unless it has been set explicitly.

I hope this doesn't break anything, or I'm implementing something thats already possible. 😄

tobspr commented 7 years ago

The PR looks fine to me, at least code wise. I don't have time to test it right now, but I will still merge it and test it later on then. Thanks for your effort!