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 methods to get device pixel ratio #249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/platform/window_sdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ impl Window {
self.window_visible = visible;
}

pub fn get_device_pixel_ratio(&self) -> f32 {
self.sdl_window.drawable_size().0 as f32 / self.sdl_window.size().0 as f32
}

pub fn get_monitor_count(&self) -> Result<i32> {
self.video_sys
.num_video_displays()
Expand Down
5 changes: 5 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ pub fn is_relative_mouse_mode(ctx: &Context) -> bool {
ctx.window.is_relative_mouse_mode()
}

/// Returns the ratio of the logical resolution to the physical resolution of the current display on which the window is being displayed.
pub fn get_device_pixel_ratio(ctx: &Context) -> f32 {
ctx.window.get_device_pixel_ratio()
}

/// Gets the number of monitors connected to the device.
///
/// # Errors
Expand Down