Skip to content

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

@AleCamara

Description

@AleCamara

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions