Skip to content
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

Cannot follow tutorial as is #555

Closed
Zekinler opened this issue Jun 13, 2024 · 0 comments
Closed

Cannot follow tutorial as is #555

Zekinler opened this issue Jun 13, 2024 · 0 comments

Comments

@Zekinler
Copy link

Zekinler commented Jun 13, 2024

@toolateralus:

yeah Im having a very hard time getting run going because the tutorial has either deprecated or completely erroneous code in it. specifically creating the window and running it. for example, in the first piece of code suggested:

// .. in 'fn run()'
env_logger::init();
    let event_loop = EventLoop::new().unwrap();
    let window = WindowBuilder::new().build(&event_loop).unwrap();

    event_loop.run(move |event, control_flow| match event {
        Event::WindowEvent {
            ref event,
            window_id,
        } if window_id == window.id() => match event {
            WindowEvent::CloseRequested
            | WindowEvent::KeyboardInput {
                event:
                    KeyEvent {
                        state: ElementState::Pressed,
                        physical_key: PhysicalKey::Code(KeyCode::Escape),
                        ..
                    },
                ..
            } => control_flow.exit(),
            _ => {}
        },
        _ => {}
    });

WindowBuilder no longer exists, (unless im missing a dependency? in that case, theres a missing listed dependency) event_loop.run(...) is deprecated.

Then, in the later revised version of run

pub async fn run() {
    // Window setup...

    let mut state = State::new(&window).await;

    event_loop.run(move |event, control_flow| {
        match event {
            Event::WindowEvent {
                ref event,
                window_id,
            } if window_id == state.window().id() => match event {
                WindowEvent::CloseRequested
                | WindowEvent::KeyboardInput {
                    input:
                        KeyboardInput {
                            state: ElementState::Pressed,
                            virtual_keycode: Some(VirtualKeyCode::Escape),
                            ..
                        },
                    ..
                } => *control_flow = ControlFlow::Exit,
                _ => {}
            },
            _ => {}
        }
    });
}

The Window::KeyboardEvent does not have an input field, and KeyboardInput does not exist. ControlFlow::Exit does not exist.

I may be completely wrong and may be missing dependencies, but it seems the tutorial just is impossible to follow without heavy modification. I have spent almost an hour finding workarounds for this, but winit has little to no documentation and its very challenging as a beginner to figure out how to fix this.

@sotrh:

There are breaking changes between winit = "0.29" and winit = "0.30". In the tutorial I specify that I'm using 0.29.

I (and I assume toolateralus) are using 0.29, regardless, the Window::KeyboardEvent does not have an input field, KeyboardInput does not exist, and ControlFlow::Exit does not exist.

@Zekinler Zekinler changed the title There are breaking changes between winit = "0.29" and winit = "0.30" Cannot follow tutorial as is Jun 13, 2024
@sotrh sotrh closed this as completed in a8aad5f Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant