-
-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add window-specific view and event user function support
An `all_functions.rs` example has been added that shows all functions that can be registered with the app and model. All other examples have been updated to take advantage of the new event functions. Functions that update the model, including the existing App `event` function, now provide the model via `&mut` rather than by value to be returned.
- Loading branch information
1 parent
4458101
commit 29b4111
Showing
80 changed files
with
1,839 additions
and
1,443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
extern crate nannou; | ||
|
||
use nannou::prelude::*; | ||
|
||
fn main() { | ||
nannou::app(model) | ||
.event(event) | ||
.update(update) | ||
.view(view) | ||
.run(); | ||
} | ||
|
||
struct Model {} | ||
|
||
fn model(app: &App) -> Model { | ||
app.new_window() | ||
.with_dimensions(720, 720) | ||
.event(window_event) | ||
.raw_event(raw_window_event) | ||
.key_pressed(key_pressed) | ||
.key_released(key_released) | ||
.mouse_moved(mouse_moved) | ||
.mouse_pressed(mouse_pressed) | ||
.mouse_released(mouse_released) | ||
.mouse_wheel(mouse_wheel) | ||
.mouse_entered(mouse_entered) | ||
.mouse_exited(mouse_exited) | ||
.touch(touch) | ||
.touchpad_pressure(touchpad_pressure) | ||
.moved(window_moved) | ||
.resized(window_resized) | ||
.hovered_file(hovered_file) | ||
.hovered_file_cancelled(hovered_file_cancelled) | ||
.dropped_file(dropped_file) | ||
.focused(window_focused) | ||
.unfocused(window_unfocused) | ||
.closed(window_closed) | ||
.build() | ||
.unwrap(); | ||
Model {} | ||
} | ||
|
||
fn event(_app: &App, _model: &mut Model, event: Event) { | ||
match event { | ||
Event::WindowEvent { id: _, raw: _, simple: _ } => {} | ||
Event::DeviceEvent(_device_id, _event) => {} | ||
Event::Update(_dt) => {} | ||
Event::Awakened => {} | ||
Event::Suspended(_b) => {} | ||
} | ||
} | ||
|
||
fn update(_app: &App, _model: &mut Model, _update: Update) { | ||
} | ||
|
||
fn view(_app: &App, _model: &Model, frame: Frame) -> Frame { | ||
frame.clear(DARK_BLUE); | ||
frame | ||
} | ||
|
||
fn window_event(_app: &App, _model: &mut Model, event: WindowEvent) { | ||
match event { | ||
KeyPressed(_key) => {} | ||
KeyReleased(_key) => {} | ||
MouseMoved(_pos) => {} | ||
MousePressed(_button) => {} | ||
MouseReleased(_button) => {} | ||
MouseEntered => {} | ||
MouseExited => {} | ||
MouseWheel(_amount, _phase) => {} | ||
Moved(_pos) => {} | ||
Resized(_size) => {} | ||
Touch(_touch) => {} | ||
TouchPressure(_pressure) => {} | ||
HoveredFile(_path) => {} | ||
DroppedFile(_path) => {} | ||
HoveredFileCancelled => {} | ||
Focused => {} | ||
Unfocused => {} | ||
Closed => {} | ||
} | ||
} | ||
|
||
fn raw_window_event(_app: &App, _model: &mut Model, _event: nannou::winit::WindowEvent) { | ||
} | ||
|
||
fn key_pressed(_app: &App, _model: &mut Model, _key: Key) { | ||
} | ||
|
||
fn key_released(_app: &App, _model: &mut Model, _key: Key) { | ||
} | ||
|
||
fn mouse_moved(_app: &App, _model: &mut Model, _pos: Point2) { | ||
} | ||
|
||
fn mouse_pressed(_app: &App, _model: &mut Model, _button: MouseButton) { | ||
} | ||
|
||
fn mouse_released(_app: &App, _model: &mut Model, _button: MouseButton) { | ||
} | ||
|
||
fn mouse_wheel(_app: &App, _model: &mut Model, _dt: MouseScrollDelta, _phase: TouchPhase) { | ||
} | ||
|
||
fn mouse_entered(_app: &App, _model: &mut Model) { | ||
} | ||
|
||
fn mouse_exited(_app: &App, _model: &mut Model) { | ||
} | ||
|
||
fn touch(_app: &App, _model: &mut Model, _touch: TouchEvent) { | ||
} | ||
|
||
fn touchpad_pressure(_app: &App, _model: &mut Model, _pressure: TouchpadPressure) { | ||
} | ||
|
||
fn window_moved(_app: &App, _model: &mut Model, _pos: Point2) { | ||
} | ||
|
||
fn window_resized(_app: &App, _model: &mut Model, _dim: Vector2) { | ||
} | ||
|
||
fn window_focused(_app: &App, _model: &mut Model) { | ||
} | ||
|
||
fn window_unfocused(_app: &App, _model: &mut Model) { | ||
} | ||
|
||
fn window_closed(_app: &App, _model: &mut Model) { | ||
} | ||
|
||
fn hovered_file(_app: &App, _model: &mut Model, _path: std::path::PathBuf) { | ||
} | ||
|
||
fn hovered_file_cancelled(_app: &App, _model: &mut Model) { | ||
} | ||
|
||
fn dropped_file(_app: &App, _model: &mut Model, _path: std::path::PathBuf) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.