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

Add some utility methods to ScreenScaler #327

Merged
merged 2 commits into from
Sep 17, 2022

Conversation

TimerErTim
Copy link
Contributor

@TimerErTim TimerErTim commented Sep 10, 2022

This PR would add some useful utility methods to the ScreenScaler struct.

First of all the current sizes (inner and outer) can easily be retrieved.
Furthermore a scaling factor can be calculated. The scaling factor is a single floating point number, representing how much unscaled objects need to be scaled up (or down respectively) in order to fit the screen using the ScalingMode of the screen scaler.

Motivation

This would allow easy integration of 3rd party libraries using the OpenGL context (e.g. UI libraries).

fn update(&mut self, ctx: &mut Context) -> Result<(), Error> {
    self.ui_scale = self.scaler.scale_factor();
}

fn draw(&mut self, ctx: &mut Context) -> Result<(), Error> {
    ui_library::draw(ctx, &self.ui, self.ui_scale); // Just some pseudo usage example of a 3rd party library
}

@TimerErTim TimerErTim marked this pull request as ready for review September 10, 2022 18:41
@17cupsofcoffee
Copy link
Owner

This seems like a no-brainer to add - I'll probably merge this after work :)

@17cupsofcoffee 17cupsofcoffee merged commit a872e79 into 17cupsofcoffee:main Sep 17, 2022
@17cupsofcoffee
Copy link
Owner

Sorry for the delay - thank you for the PR!

@TimerErTim
Copy link
Contributor Author

No problem!
Thanks for merging

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