-
Notifications
You must be signed in to change notification settings - Fork 6
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
Improve support for High Dpi displays #1
base: master
Are you sure you want to change the base?
Conversation
Hello, thanks for the contribution! I tried to apply these changes to my test application but there were few issues. First issue is that I need a way to access the raw Second thing that comes to my mind is that there's no easy way to apply custom dpi scaling because the struct constructor accepts only Is the main issue on MacOS here where the cursor position gets messed up if the dpi is anything else than Maybe instead of exposing the What do you think? |
Without my changes, if I don't call allow_highdpi, it just looks normal but pixelated. If I do call it, it looks like this: Bildschirmaufnahme.2022-12-19.um.11.45.45.movAnd I cant get it to fill the whole screen. I think making the DpiMode private and internal only could work. Do you think a custom scaling value by the user should overwrite the systems dpi value or should it be multiplied with it? |
I think ideally an option for scaling and custom value would be the best. Perhaps this could be handled with an enum similar to the You would choose one of these:
I'll try to take another look at this on the upcoming holidays. Not sure if I can commit directly to this PR, but if you want to give it a go I can also review it. |
Add support for dpi that can be: - calculated automatically - calculated automatically and scaled - set from direct value
I added support for automatic dpi, scaled automatic dpi and direct dpi value. Also included my previous example program as part of the repository. The example program is probably not ideal but it gets the job done. Can you check the code so that it looks alright to you and test this on Mac by running the example program from the repository root with this command |
I think I am gonna merge this in the upcoming days unless you want to add something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Sorry for not getting back earlier. I gave your example a test on MacOS and first it failed because of a linker error.
Now it's compiling but if I run it it panics:
thread 'main' panicked at 'window does not have a valid contentView', /Users/lucasprivat/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-hal-0.13.2/src/metal/surface.rs:85:13
I was able to run it with my project though and it worked great!
I did a couple changes though:
- in the resize event I recalculate dpi, in case the window was moved to a different screen with different dpi
- updated egui to 0.21 (had to change the keyboard events to add a "repeat" property
Unfortunately I was not able to get your example to work with egui 0.21, and the updated wgpu version that comes with it, maybe you are able to update it?
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
sdl2 = {version= "0.35.2", features = ["raw-window-handle", "static-link", "use-pkgconfig"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdl2 = {version= "0.35.2", features = ["raw-window-handle", "static-link", "use-pkgconfig"] } | |
sdl2 = {version= "0.35.2", features = ["raw-window-handle"] } |
Had to remove these to make it compile on MacOS
I also tried updating the example program to let sdl_context = sdl2::init().expect("Cannot initialize SDL2!");
let video_subsystem = sdl_context.video().expect("Cannot get SDL2 context!");
let window: Window = video_subsystem
.window("egui-sdl2-event-example", width, height)
.position_centered()
.resizable()
.build()
.map_err(|e| e.to_string())
.expect("Cannot create SDL2 window!");
let instance = wgpu::Instance::new(InstanceDescriptor {
backends: Backends::all(),
dx12_shader_compiler: Default::default(),
});
#[allow(unsafe_code)]
let surface = unsafe { instance.create_surface(&window) }.unwrap(); // compiler error I'll fix the errors once I figure out how to make |
Hi! I made some changes to improve high dpi support (tested on macos and linux / pop os) and made some changes to make the api more similar to egui_winit (elapsed time is now handled by the crate).
DpiMode is used to differentiate between platforms with native hdpi support by sdl2 (e.g. MacOS) and platforms where it's manually done by the crate.