britzl / defold-richtext

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

Color tag shouldn't cause words to be "broken up"? #74

Open subsoap opened 2 years ago

subsoap commented 2 years ago

<color=green>Some are born great, some ach</color>ieve greatness, and some have greatness thrust upon them.

This text for example causes a line break.

x

I feel like this shouldn't happen because it doesn't happen in HTML. Is there currently a way to avoid this behavior?

subsoap commented 2 years ago

https://user-images.githubusercontent.com/409170/174688134-92049f3b-f467-469b-8d72-9423ff5a3683.mp4

Another related issue is how the spacing of the letters changes.

sample_project.zip

subsoap commented 2 years ago

Dummy tags with no function (like <test1></test1>) also have the same behavior with modifying the spacing / line breaks when it feels like they should not.

britzl commented 2 years ago

I feel like this shouldn't happen because it doesn't happen in HTML. Is there currently a way to avoid this behavior?

I think you can prevent it like this:

<color=green>Some are born great, some</color> <nobr><color=green>ach</color>ieve</nobr> greatness, and some have greatness thrust upon them.
britzl commented 2 years ago

Another related issue is how the spacing of the letters changes.

This is a duplicate of https://github.com/britzl/defold-richtext/issues/66

subsoap commented 2 years ago

I think you can prevent it like this:

A simpler way for me to deal with it maybe would be to manually force line breaks after so many words/characters in the base text when it detects the characters would overflow there anyway.

subsoap commented 2 years ago

A simpler way for me to deal with it maybe would be to manually force line breaks after so many words/characters in the base text when it detects the characters would overflow there anyway.

It's not simpler lol. It complicates things more too since there are more characters to keep track of.

Wrapping the currently spliced word seems wrong still because it would make the spliced word hang over the current line until it's no longer spliced / wrapped then it would snap to the next line which would look odd.

subsoap commented 2 years ago

Related to https://github.com/britzl/defold-richtext/issues/66, for my use case I tried layering two copies of richtext output a normal and bg, it helps to make the color jitter of #66 not a problem, but I still have to solve not having partial words broken up.

https://user-images.githubusercontent.com/409170/174742321-a89985da-5684-434d-9b85-95b848245dd5.mp4

So I referenced the bg version's position and forced the partial node versions all to match their static node positions.

local function update_positions()
    for k,v in ipairs(text_nodes) do
        local position = gui.get_position(text_nodes_bg[k].node)
        gui.set_position(text_nodes[k].node, position)
    end
end

https://user-images.githubusercontent.com/409170/174743821-03228b38-9c5e-436c-b698-8dbbed96e85b.mp4

Of course this would not work for most reasons why #66 would be annoying.