linebender / druid

A data-first Rust-native UI design toolkit.
https://linebender.org/druid/
Apache License 2.0
9.45k stars 569 forks source link

Are there any ways to force `TextLayout` not to trim the string when calculating its size? #2334

Closed MicroCBer closed 1 year ago

MicroCBer commented 1 year ago

I'm making word-by-word desktop lyrics software with druid.

To do this, I've split the whole sentence into different tokens depending on the key time ( e.g. Oh (100ms), spill (128ms)me (160ms)the (182ms)tale (204ms).

Now I want to draw the lyrics word by word on my custom widget, but then I found that TextLayout would automatically trim the string so that the result is now like this. {`{8`C (TISUHN_1HB857AQ ( the gray part is drawn directly by draw_text and the white part is drawn word by word )

So, is there any way to prevent this behavior or any other approach to my target?

xStrom commented 1 year ago

What do you mean by trim the string? The Size returned by layout or does it actually modify a String object? For the layout case, you could just wrap the TextLayout in your custom widget and then have the custom widget's layout return a custom size, perhaps with some padding.

MicroCBer commented 1 year ago

What do you mean by trim the string? The Size returned by layout or does it actually modify a String object? For the layout case, you could just wrap the TextLayout in your custom widget and then have the custom widget's layout return a custom size, perhaps with some padding.

The size. I don't think it's a good idea to add some custom paddings cuz it would make the render result different from the one which directly use draw_text. but anyway, now I'm adding some custom paddings as it's the only way that can resolve my problem

xStrom commented 1 year ago

it would make the render result different

Different in some way other than padding? Generally speaking, I wouldn't expect a widget's paint to run differently if the parent's size is larger.

MicroCBer commented 1 year ago

uh, I cannot reproduce now. I'll reopen the issue when I reproduce it again.