sotrh/learn-wgpu

new_inner_size: No such field

Cg1340 opened this issue · 3 comments

I am using winit version 0.29 and when I write the following code following the tutorial called "The Surface":

event_loop
    .run(move |event, control_flow| {
        match event {
            Event::WindowEvent {
                ref event,
                window_id,
            } if window_id == state.window().id() => {
                if !state.input(event) {
                    // UPDATED!
                    match event {
                        WindowEvent::CloseRequested
                        | WindowEvent::KeyboardInput {
                            event:
                                KeyEvent {
                                    state: ElementState::Pressed,
                                    physical_key: PhysicalKey::Code(KeyCode::Escape),
                                    ..
                                },
                            ..
                        } => control_flow.exit(),
                        WindowEvent::Resized(physical_size) => {
                            state.resize(*physical_size);
                        }
                        WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
                            state.resize(**new_inner_size);
                        }
                        _ => {}
                    }
                }
            }
            _ => {}
        }
    })
    .unwrap();

Rust gives me an error:

error[E0026]: variant `winit::event::WindowEvent::ScaleFactorChanged` does not have a field named `new_inner_size`
   --> src\lib.rs:177:63
    |
177 | ...                   WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
    |                                                         ^^^^^^^^^^^^^^ variant `winit::event::WindowEvent::ScaleFactorChanged` does not have this field

I would like to know how to deal with this problem, thanks.

You need to use an InnerSizeWriter now. Check out the docs for ScaleFactorChanged.

The updated version of the tutorial removes the ScaleFactorChanged block entirely.

Got it