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

Add simpler Event type inspired by simple Processing/oF style methods. #5

Closed
mitchmindtree opened this issue Oct 16, 2017 · 1 comment · Fixed by #22
Closed

Add simpler Event type inspired by simple Processing/oF style methods. #5

mitchmindtree opened this issue Oct 16, 2017 · 1 comment · Fixed by #22
Assignees
Milestone

Comments

@mitchmindtree
Copy link
Member

Currently we mostly just re-export the events emitted by the winit crate, however these can be pretty verbose and the pattern matching can get pretty grueling when all you want to do is check if a key was pressed or not.

It would be sweet if there was a function to convert WindowEvent to a much simpler event, something like:

enum SimpleWindowEvent {
    KeyPressed(Key),
    KeyReleased(Key),
    MouseMoved(Vector2),
    MouseDragged(Vector2, MouseButton),
    MousePressed(Vector2, MouseButton),
    MouseReleased(Vector2, MouseButton),
    MouseEntered(Vector2),
    MouseExited(Vector2),
    Resized(Dimensions),
}

In this case, the template could maybe look like something closer to this:

extern crate nannou;

use nannou::{App, Event, Frame};
use nannou::SimpleWindowEvent::*;

fn main() {
    nannou::run(model, update, draw);
}

struct Model {
    window: nannou::window::Id,
}

fn model(app: &App) -> Model {
    let window = app.new_window().build().unwrap();
    Model { window }
}

fn update(_app: &App, model: Model, event: Event) -> Model {
    match event {
        // Handle window events like mouse, keyboard, resize, etc here.
        Event::WindowEvent(_id, event) => match nannou::simple_window_event(event) {

            KeyPressed(key) => {
            },

            KeyReleased(key) => {
            },

            MouseMoved(pos) => {
            },

            MouseDragged(pos, button) => {
            },

            MousePressed(pos, button) => {
            },

            MouseEntered(pos) => {
            },

            MouseExited(pos) => {
            },

            Resized(pos) => {
            },

        },
        // `Update` the model here.
        Event::Update(_update) => {
        },
        _ => (),
    }
    model
}

// Draw the state of your `Model` into the given `Frame` here.
fn draw(_app: &App, model: &Model, frame: Frame) -> Frame {
    // Our app only has one window, so retrieve this part of the `Frame`. Color it grey.
    frame.window(model.window).unwrap().clear_color(0.1, 0.11, 0.12, 1.0);
    // Return the cleared frame.
    frame
}
@mitchmindtree mitchmindtree self-assigned this Oct 18, 2017
@mitchmindtree
Copy link
Member Author

I'll tackle this now 👍

@freesig freesig added this to the Basics milestone Oct 18, 2017
mitchmindtree added a commit to mitchmindtree/nannou that referenced this issue Oct 18, 2017
This addresses and closes nannou-org#5.

The examples have been updated and currently do a glob import e.g.

```rust
use nannou::event::SimpleWindowEvent::*;
```

However this will probably get removed soon in favour of adding these
variants to the prelude (see nannou-org#10).
@mitchmindtree mitchmindtree modified the milestones: Basics, Announce Apr 1, 2018
mitchmindtree added a commit to mitchmindtree/nannou that referenced this issue Mar 30, 2020
Allow for processing raw points of frame stream
mitchmindtree pushed a commit to mitchmindtree/nannou that referenced this issue May 15, 2022
Update dependencies to most recent version, fixes MSAA limitation
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

Successfully merging a pull request may close this issue.

2 participants