not-fl3 / macroquad

Cross-platform game engine in Rust.
Apache License 2.0
3.04k stars 297 forks source link

Changes draw_text_ex to pass params by reference #738

Closed maxpiepenbrink closed 2 weeks ago

maxpiepenbrink commented 2 weeks ago

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

maxpiepenbrink commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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