From dedc9c14e25bb8247fc447a896a2579786922b91 Mon Sep 17 00:00:00 2001 From: Josh Simmons Date: Thu, 9 May 2024 11:00:12 +0200 Subject: [PATCH] shark: Add HIDPI support --- title/shark/src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/title/shark/src/main.rs b/title/shark/src/main.rs index 63f760e..7054fac 100644 --- a/title/shark/src/main.rs +++ b/title/shark/src/main.rs @@ -460,6 +460,11 @@ pub fn main() { std::env::set_var("RUST_BACKTRACE", "1") } + // Default to wayland because otherwise HiDPI is totally borked. + if std::env::var("SDL_VIDEODRIVER").is_err() { + std::env::set_var("SDL_VIDEODRIVER", "wayland") + } + let app = create_app(); let main_window = app.create_window(&WindowDesc { title: "shark", @@ -604,13 +609,19 @@ pub fn main() { let mut basic_transforms = vec![]; + let mut ui_scale; + 'main: loop { let frame = device.begin_frame(); { let frame = &frame; let (width, height, swapchain_image) = loop { - let (width, height) = main_window.extent(); + let (virtual_width, _virtual_height) = main_window.extent(); + let (width, height) = main_window.drawable_extent(); + + ui_scale = width as f32 / virtual_width as f32; + if let Ok(result) = device.acquire_swapchain( frame, main_window.upcast(), @@ -797,6 +808,8 @@ pub fn main() { (FontFamily::NotoSansJapanese, 22.0, line1) }; + let font_size_px = font_size_px * ui_scale; + let font = fonts.font(font_family); let scale = font.scale_for_size_px(font_size_px); -- 2.49.0