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

Changes draw_text_ex to pass params by reference #738

Conversation

maxpiepenbrink
Copy link

@maxpiepenbrink maxpiepenbrink commented Jun 16, 2024

If you're re-using TextParams for various things, it can be a little clumsy to need to .clone() it everywhere.

@maxpiepenbrink
Copy link
Author

maxpiepenbrink commented Jun 16, 2024

Feel free to shoot this down :) Just ran into this while playing around with a text heavy prototype in MacroQuad where a single draw might be building 30+ of these every frame. The cost is negligible but a & prefix didn't feel much worse than .clone() or TextParams { blah, ..defaults::Default() } or TextParams::default() everywhere.

Example case using this change:

impl Displayable for Header {
    fn draw(&self, context: &MenuContext) {
        let measure = measure_text(
            &self.text,
            context.text_params.font,
            context.text_params.font_size,
            context.text_params.font_scale,
        );
        draw_text_ex(
            &self.text,
            context.screen_center_x - (measure.width / 2.0),
            20.0,
            &context.text_params, // <-- currently have to .clone() this instead
        );
    }
}

@maxpiepenbrink
Copy link
Author

I completely overlooked that many of the other _ex functions are also not passing by reference, I have to assume this is just intentional then! 👍 carry on

@not-fl3
Copy link
Owner

not-fl3 commented Jun 16, 2024

I agree, an extra & is not a big deal. But, yes, changing all those functions would be too much of a breaking change :(

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

Successfully merging this pull request may close these issues.

2 participants