-
-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to get the height of wrapped text? #138
Comments
I think you're looking for
This returns an object with fields > ROT.Text.measure("This is a very long and wrapped text.", 13)
{ width: 13, height: 3 } Maybe @ondras can add an entry to the interactive manual? |
FWIW `display.drawText` will do the wrapping if you give it a `maxWidth`
argument at the end; the function also returns the number of lines it ended
up drawing so you can get the height-measure there.
That said, that's only useful if you don't need the height *before* you do
the drawing :)
…On Thu, Aug 16, 2018 at 1:14 PM Patrick Meade ***@***.***> wrote:
I think you're looking for ROT.Text.measure:
measure: function(str, maxWidth)
This returns an object with fields width and height.
> ROT.Text.measure("This is a very long and wrapped text.", 13)
{ width: 13, height: 3 }
Maybe @ondras <https://github.com/ondras> can add an entry to the
interactive manual?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#138 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAA1TTCzXAWrEyfNf_MUxyw7vaRMtKeTks5uRaiNgaJpZM4V_ETi>
.
--
Roger Ostrander
|
Wow, this is amazing. Thank you all!
I have figured out a way to work around this. let width = display.drawText(999, 999, "This is a very long and wrapped text.", 13);
display.clear();
display.drawText(1, 1, "This is a very long and wrapped text.", 13);
console.log("The width of the wrapped text is: " + width); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Ondras, I have made a game with rot.js, the libray is very handy! <3
But there is one feature I hope rot.js could provide natively. When I want to print a long text in the message board, the width and height of which is fixed, I need to know how 'tall' the wrapped text is. For example, the height of the following text is 3:
I have tried myself following these steps:
The length of the array (wrappedText) is the height of the wrapped text.
I don't know whether there are some better solutions. Could you please shed some light on this? Thank you. :)
The text was updated successfully, but these errors were encountered: