Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make draw_character() and character_advance() available to users #775

Open
bbogdan-ov opened this issue Aug 6, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@bbogdan-ov
Copy link
Contributor

Hi! I'm writing a custom text input, so i need to constantly calculate the size of the text that user enters

Using basic draw_text() and measure_text() may be quite slow, because it calculates the size for the whole text.
I used slices to calculate the size of the string/text from the beginning to the cursor position, but it also slows down my game!

I want to implement something like this in text.rs module:

// May be called like `CharacterDimensions`
pub struct CharDimensions {
    width: f32,
    offset_y: f32
}

/// Draws the character and returns its size
pub fn draw_character(character: char, x: f32, y: f32, font: Option<&Font>, font_size: u16, color: Color) -> CharDimensions;
/// Returns the character size
pub fn measure_character(character: char, font: Option<&Font>, font_size: u16) -> CharDimensions;

Also i would like draw_text() and draw_text_ex() to return TextDimensions, because they have already been calculated, so we don't need to recalculate them again

Want to hear what you think about it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants