use scale_factor for egui
This commit is contained in:
parent
d623b8fc46
commit
7640cf053b
|
@ -16,6 +16,7 @@ struct WindowState {
|
|||
window: Window,
|
||||
egui_platform: egui_winit_platform::Platform,
|
||||
demo_app: egui_demo_lib::DemoWindows,
|
||||
scale_factor: f64,
|
||||
}
|
||||
|
||||
struct WinitState {
|
||||
|
@ -121,16 +122,18 @@ impl WinitState {
|
|||
window.window_handle().expect("window handle"),
|
||||
);
|
||||
|
||||
let scale_factor = window.scale_factor();
|
||||
self.windows2.insert(
|
||||
window_id,
|
||||
WindowState {
|
||||
window,
|
||||
scale_factor,
|
||||
demo_app: egui_demo_lib::DemoWindows::default(),
|
||||
egui_platform: egui_winit_platform::Platform::new(
|
||||
egui_winit_platform::PlatformDescriptor {
|
||||
physical_width: size.width,
|
||||
physical_height: size.height,
|
||||
scale_factor: 1.0,
|
||||
scale_factor,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
|
@ -229,6 +232,11 @@ impl ApplicationHandler for WinitState {
|
|||
winit::event::WindowEvent::RedrawRequested => {
|
||||
self.handle_draw_request(window_id);
|
||||
}
|
||||
winit::event::WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
|
||||
if let Some(window) = self.windows2.get_mut(&window_id) {
|
||||
window.scale_factor = scale_factor;
|
||||
}
|
||||
}
|
||||
_ => {} // unhandled event
|
||||
}
|
||||
}
|
||||
|
|
|
@ -609,6 +609,7 @@ pub fn egui_pass(
|
|||
let pipeline = egui_state.pipeline.clone();
|
||||
let pipeline_layout = egui_state.pipeline_layout.clone();
|
||||
let descriptor_set = egui_state.descriptor_set;
|
||||
let screen_rect = egui.screen_rect();
|
||||
|
||||
move |ctx: &RenderContext| -> crate::Result<()> {
|
||||
let cmd = &ctx.cmd;
|
||||
|
@ -717,7 +718,7 @@ pub fn egui_pass(
|
|||
vk::ShaderStageFlags::VERTEX,
|
||||
0,
|
||||
bytemuck::cast_slice(
|
||||
&[target.width() as f32, target.height() as f32].map(|f| f.to_bits()),
|
||||
&[screen_rect.width(), screen_rect.height()].map(|f| f.to_bits()),
|
||||
),
|
||||
);
|
||||
cmd.bind_descriptor_sets(
|
||||
|
|
Loading…
Reference in a new issue