hakolao / egui_winit_vulkano

Egui gui integration with winit and vulkano
Apache License 2.0
78 stars 36 forks source link

Adjusting UI scaling / scale factor #23

Closed x3ro closed 2 years ago

x3ro commented 2 years ago

Hey there. First of all, thanks for this glue package, it's made playing around with egui much easier :)

I noticed that, running the wholesome example on macOS, that pixel density / HiDPI / whatever you want to call it was not taken into account. In other words, logical pixels and physical pixels were treated as the same thing, resulting in very small rendering. Note the disparity between the size of the window title and the content of the window:

Screenshot 2022-08-26 at 19 05 19

I did find scale_factor_override in WindowDescriptor, but adjusting that only resulted in the size of the window changing. That is, if I tried to create a window 500x500px and set a scale_factor_override of 2, then the window would be 1000x1000px, but the content was still the same size.

Investigating a bit further, I found that egui_winit handles this sort of scaling via the set_pixels_per_point method on egui_winit::State. This state is created in integration::Gui::new, and adding the following before returning from the constructor results in the (imo) "correct" content size:

egui_winit.set_pixels_per_point(surface.window().scale_factor() as f32);
Screenshot 2022-08-26 at 19 08 37

So, long story short, this results in a bunch of questions from my side:

hakolao commented 2 years ago

Yea, this should not occur. Let me get back to you when I get a moment :) tonight or over the weekend

hakolao commented 2 years ago

Looks like I broke it when updating to new egui_winit whose api changed. I'll make a fix! @x3ro

hakolao commented 2 years ago

scale_factor_override is used in the window builder in vulkano-utils. I think it just tells winit what the scale factor should be (if it's set), but if we don't tell egui_winit what the scale factor is, then egui will look wrong.

egui_winit is already publicly exposed from Gui thus you can set the scale factor for egui later if you wish.

hakolao commented 2 years ago

Thanks for reporting and using this lib!

x3ro commented 2 years ago

Nice, thanks for the quick fix! :)