mgeisler / textwrap

An efficient and powerful Rust library for word wrapping text.
MIT License
446 stars 44 forks source link

Unit of column width #516

Closed sry948749099 closed 1 year ago

sry948749099 commented 1 year ago

Is there a way to wrap lines in pixels instead of bytes?

mgeisler commented 1 year ago

Hi @sry948749099,

Yes, see https://mgeisler.github.io/textwrap/ for an example where Textwrap is used to wrap text based on pixels.

The important part is this implementation of Fragment. The Fragment trait is what Textwrap uses when wrapping: you should implement it for your own custom type and then you'll be able to use all the wrapping algorithms on this type.

sry948749099 commented 1 year ago

Hi @sry948749099,

Yes, see https://mgeisler.github.io/textwrap/ for an example where Textwrap is used to wrap text based on pixels.

The important part is this implementation of Fragment. The Fragment trait is what Textwrap uses when wrapping: you should implement it for your own custom type and then you'll be able to use all the wrapping algorithms on this type.

Get it! Thanks for your quickly respose!