mirror of
https://gitlab.com/cleanflash/installer.git
synced 2026-08-13 02:41:38 +08:00
Implement HiDPI scaling
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#![windows_subsystem = "windows"]
|
||||
//#![windows_subsystem = "windows"]
|
||||
|
||||
mod install_flags;
|
||||
mod install_form;
|
||||
@@ -14,10 +14,16 @@ fn main() {
|
||||
clean_flash_common::update_checker::FLASH_VERSION
|
||||
);
|
||||
|
||||
// Query DPI before creating any window. The manifest already marks the process
|
||||
// as per-monitor v2 DPI aware, so GetDpiForSystem returns the real hardware DPI.
|
||||
let scale = clean_flash_ui::get_dpi_scale();
|
||||
let phys_w = (WIDTH as f32 * scale).round() as usize;
|
||||
let phys_h = (HEIGHT as f32 * scale).round() as usize;
|
||||
|
||||
let mut window = Window::new(
|
||||
&title,
|
||||
WIDTH,
|
||||
HEIGHT,
|
||||
phys_w,
|
||||
phys_h,
|
||||
WindowOptions {
|
||||
resize: false,
|
||||
..WindowOptions::default()
|
||||
@@ -31,8 +37,9 @@ fn main() {
|
||||
// Cap at ~60 fps.
|
||||
window.set_target_fps(60);
|
||||
|
||||
let mut renderer = Renderer::new(WIDTH, HEIGHT);
|
||||
let mut form = InstallForm::new();
|
||||
// Renderer operates at physical resolution; the form layout is scaled accordingly.
|
||||
let mut renderer = Renderer::new(phys_w, phys_h);
|
||||
let mut form = InstallForm::new(scale);
|
||||
|
||||
while window.is_open() && !window.is_key_down(Key::Escape) {
|
||||
let (mx, my) = window
|
||||
@@ -43,7 +50,7 @@ fn main() {
|
||||
form.update_and_draw(&mut renderer, mx as i32, my as i32, mouse_down);
|
||||
|
||||
window
|
||||
.update_with_buffer(&renderer.buffer, WIDTH, HEIGHT)
|
||||
.update_with_buffer(&renderer.buffer, phys_w, phys_h)
|
||||
.expect("Failed to update window buffer");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user