britzl / defold-richtext

Defold-RichText is a system to create styled text based on an HTML inspired markup language
MIT License
75 stars 12 forks source link

richtext.truncate for truncating one word at a time #38

Closed subsoap closed 5 years ago

subsoap commented 5 years ago

Would be a useful option

britzl commented 5 years ago

Hmm, good suggestion. Maybe add an option table as a third argument with an option to truncate full words/to word boundary:

richtext.truncate(words, length, { full_word = true }) -- option name?
subsoap commented 5 years ago

yes, settings table would work for this

britzl commented 5 years ago

@subsoap I need to discuss the design a bit more:

         11111111112
12345678901234567890
Hi my name is Slim Shady

truncate(words, 16)

         11111111112
12345678901234567890
Hi my name is Sl

truncate(words, 16, { full_word = true })

         11111111112
12345678901234567890
Hi my name is
britzl commented 5 years ago

PR https://github.com/britzl/defold-richtext/pull/46

subsoap commented 5 years ago

Yes, you should "round down" the words"

Although when truncating full words the counter should probably be for the actual word count and not the character accounts, single words would be a single number in the total truncation value

britzl commented 5 years ago

Good point. This has been implemented and released in 5.9.0

subsoap commented 5 years ago

Multiple &zwsp; with no spaces between are considered a single word. Probably want them each to be considered their own word no matter what because otherwise defeats their purpose as a timer buffer without modifying formatting.

britzl commented 5 years ago

Good point. This is required when truncating per word.

britzl commented 5 years ago

Fixed in https://github.com/britzl/defold-richtext/releases/tag/5.10.2