Closed 19wintersp closed 2 years ago
@19wintersp I'm interested in catering for this. Do have any ideas for how the API could look? I started working on exposing the variations and skin tones in a nice way but I wasn't sure exactly on the best API since I didn't have a use case. I was thinking of adding a function on the emoji that could look up the variation by skin tone and also add a way to iterate through skin tones.
Ideas:
Skin tone lookup
let hand = emojis::lookup("👋")?;
let hand_medium = hand.with_skin_tone(SkinTone::Medium)?;
assert_eq!(hand_medium, "👋🏽")
Iterating over skin tones
let hand = emojis::lookup("👋")?;
let hands: Vec<_> = hand.iter_skin_tones().collect();
// hands would contain all the emojis 👋 👋🏻 👋🏼 👋🏽 👋🏾 👋🏿
I was even thinking of adding a with_hair
fn
let emoji = emojis::lookup("man")?
.with_skin_tone(SkinTone::MediumDark)?
.with_hair(Hair::Red)?;
assert_eq!(emoji, "👨🏾🦰")
My current use case is just a basic emoji picker, where I'd like for the user to be able to select an emoji and see the other skin tone variations as well. Having that sort of builder-method-style API would be a rather interesting concept, but just iterating over them would also work fine in the short term.
I'm not too familiar with how Unicode works, but I believe there are also certain sequences or modifiers which can be used with emoji? Having an API to create those would be great, though don't feel obligated to do this :)
What do you think of the following API 🤔?
Other ideas:
a) Add SkinTone::Default
and return that from the skin_tone
function as the skin tone for emojis where skin tone is applicable .
b) Add SkinTone::Default
and return that as the default instead of an Option
from the skin_tone
function, even for emojis that don't have other skin tones.
c) Don't include the default skin tone emoji when iterating over the skin tones.
d) Don't return Option
from skin_tones
function and always return an iterator which only has a single element for emojis without skin tones.
This API looks good. Having it return SkinTone::Default
for the default yellow emoji where they can have other skin tones but None
for those which don't would make sense, and possibly also having a with_skin_tone
method or similar? For the various variations this API would also work well, but for now this is sufficient for what I need. Thanks :D
Changes are released https://docs.rs/emojis/0.2 (with some other ones as well)
Sorry, I've just noticed that the iter
function seems to exclude any emoji with a skin tone, which includes those with default skin tones like :surfer:. Is this intentional?
Oh woops that wasn't intentional, I meant it to include the default skin tone ones. Let me fix
This is done, also I opened #6, there are some outstanding questions with regards to emojis with multiple skin tones. Feel free to put any ideas there.
Hello, and thank you for this crate; I've found it very useful. I would find it rather helpful to have some of the fields in the
Emoji
struct to be public, such as the variations and skin tones, either by making the fields themselves public or adding getter methods for them. Sorry if I've missed an obvious way of doing this, or if there's a reason why these fields are private.Thanks for your time