Page 2 of 2

Re: Fill a circle with text

Posted: Tue Jan 10, 2023 6:47 pm
by pgimeno
Bigfoot71 wrote: Mon Jan 09, 2023 11:19 pm Wow, super cool! I wanted to understand your approach to the problem, so I restructured it a bit by commenting on the passages, I also took the liberty of putting the declaration of `words` in the `while` loop because even if a redefinition in a loop is slower than predefining it upstream it seems to me that it is preferable to do so since another loop takes care of "emptying" it afterwards, or maybe I did not understand a subtlety.
Thanks for adding comments.

The while loop is usually faster than allocating the table and clearing the garbage afterwards; also garbage collection is often responsible for CPU spikes that sometimes produce micro-stutters. There's a lot of garbage being generated in other sections, but that was one thing I could do something about. Ideally the table should be out of the function but that would have looked too extreme.

There's a minor issue in one of the comments; 'If the alignment is not "justify", use the default alignment' should not say default alignment, but specified alignment. Also, the math.min() line lacks a comment that says that it calculates the minimum between the width at the top and the width at the bottom of the line, which is the width to use. If the width of the circle at the bottom of the line is smaller, it means we're close to the bottom of the circle.

On a side note, after thinking about it, I could not have done much to use the built-in justify even if it worked well in this version. My initial plan was to include two lines and use scissor to cut out the second line, but that would have required a canvas rather than a text object. Probably slower, and almost surely more resource-intensive. I've requested a feature that would have helped.

And note that this version does not handle newline characters (\n) in the string, and doesn't let you choose a different line spacing, which would be cool.

Re: Fill a circle with text

Posted: Tue Jan 10, 2023 6:51 pm
by RNavega
9912 wrote: Tue Jan 10, 2023 5:24 pm to display the text like a visual novel on round display.
If you're gonna use it with large texts that overflow the circle, you'll have to modify pgimeno's pretty cool function to also return the index of the string where it you can continue from, for pagination (splitting the huge text over several pages).

So in your last image, you know the text ended in "malesuad", you'll return the index of the next word after that, so for the next circle text you can supply myText:sub(nextWordStart) to show the rest of the text, doing that until the return index is nil or whatever (so after a few circles, all of the huge text was shown).

Re: Fill a circle with text

Posted: Tue Jan 10, 2023 10:53 pm
by Bigfoot71
pgimeno wrote: Tue Jan 10, 2023 6:47 pm Thanks for adding comments.

The while loop is usually faster than allocating the table and clearing the garbage afterwards; also garbage collection is often responsible for CPU spikes that sometimes produce micro-stutters. There's a lot of garbage being generated in other sections, but that was one thing I could do something about. Ideally the table should be out of the function but that would have looked too extreme.

There's a minor issue in one of the comments; 'If the alignment is not "justify", use the default alignment' should not say default alignment, but specified alignment. Also, the math.min() line lacks a comment that says that it calculates the minimum between the width at the top and the width at the bottom of the line, which is the width to use. If the width of the circle at the bottom of the line is smaller, it means we're close to the bottom of the circle.

On a side note, after thinking about it, I could not have done much to use the built-in justify even if it worked well in this version. My initial plan was to include two lines and use scissor to cut out the second line, but that would have required a canvas rather than a text object. Probably slower, and almost surely more resource-intensive. I've requested a feature that would have helped.

And note that this version does not handle newline characters (\n) in the string, and doesn't let you choose a different line spacing, which would be cool.
Thank you for these details, it's very useful to know, so I corrected the comments and put back the totally original code. I also made some attempts about what you advised on word wrap wanting to add an option for line spacing as well, I got there but there are still some issues at the moment , I will share it here of course when I have succeeded.

[Solved] Fill a circle with text

Posted: Wed Jan 18, 2023 8:00 pm
by 9912
Thank you all for the help, now for future use is better to have this code as a library for future use