embedded-graphics / embedded-text

Multiline TextBox for the embedded-graphics Rust crate
MIT License
57 stars 4 forks source link

Rendering Emojis with plugins #169

Open scd31 opened 1 week ago

scd31 commented 1 week ago

I'm interested in implementing a plugin which can render emojis. Not all of them, but a few common ones. I wanted to know - is this possible, and are plugins the correct tool for the job?

Thanks!

bugadani commented 1 week ago

I don't really remember the details, but it shouldn't be impossible. To make it work, you need a font that has the symbols, or a TextRenderer implementation that does the actual drawing. Then, I think you need to implement Plugin::next_token that recognises the emojis you want to render, and maps them to the correct emoji characters in your font.

scd31 commented 6 days ago

I see, thanks. In that case, can I just do all the logic in the custom TextRenderer - no custom plugin required?

bugadani commented 6 days ago

It depends on embedded-text, and I don't know if it breaks up :) and such into multiple tokens. If it does, you'll need a plugin to re-merge the emojis before passing to a text renderer (otherwise it'd see a : in one call, and ) in another).

scd31 commented 6 days ago

I was actually thinking of emojis like :smile: but I suppose there'd still need to be merging for multi-character emojis, like country flags