opengl_graphics icon indicating copy to clipboard operation
opengl_graphics copied to clipboard

Preloaded characters in the GlyphCache cannot be easily retrieved with opt_character()

Open AleCamara opened this issue 5 years ago • 0 comments

Preloading characters in a GlyphCache creates the new characters, storing them in the cache. However, the characters get their size converted from points to pixels in character():

let size = ((size as f32) * 1.333).round() as u32; // convert points to pixels

This makes it impossible for external users to retrieve preloaded characters without reproducing the points -> pixels conversion themselves. I personally think that it'd be nice for users to not have to bother with this, so instead we could just do the size conversion when requesting the opt_character(). That way users could just pass in the same font size.

pub fn opt_character(&self, size: FontSize, ch: char) -> Option<Character<T>> {
    let size = ((size as f32) * 1.333).round() as u32; // convert points to pixels
    // ... rest
}

What do you think?

Happy to put up a PR if this is something that is useful!

AleCamara avatar Dec 27 '20 16:12 AleCamara