Skip to content

Commit

Permalink
Rename elwt -> event_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jan 13, 2024
1 parent c405243 commit 1dd64d8
Show file tree
Hide file tree
Showing 39 changed files with 105 additions and 103 deletions.
6 changes: 3 additions & 3 deletions examples/child_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ fn main() -> Result<(), impl std::error::Error> {

println!("parent window: {parent_window:?})");

event_loop.run(move |event: Event<()>, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, window_id } = event {
match event {
WindowEvent::CloseRequested => {
windows.clear();
elwt.exit();
event_loop.exit();
}
WindowEvent::CursorEntered { device_id: _ } => {
// On x11, println when the cursor entered in a window even if the child window is created
Expand All @@ -75,7 +75,7 @@ fn main() -> Result<(), impl std::error::Error> {
},
..
} => {
spawn_child_window(&parent_window, elwt, &mut windows);
spawn_child_window(&parent_window, event_loop, &mut windows);
}
WindowEvent::RedrawRequested => {
if let Some(window) = windows.get(&window_id) {
Expand Down
10 changes: 5 additions & 5 deletions examples/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn main() -> Result<(), impl std::error::Error> {
let mut wait_cancelled = false;
let mut close_requested = false;

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
use winit::event::StartCause;
println!("{event:?}");
match event {
Expand Down Expand Up @@ -104,22 +104,22 @@ fn main() -> Result<(), impl std::error::Error> {
}

match mode {
Mode::Wait => elwt.set_control_flow(ControlFlow::Wait),
Mode::Wait => event_loop.set_control_flow(ControlFlow::Wait),
Mode::WaitUntil => {
if !wait_cancelled {
elwt.set_control_flow(ControlFlow::WaitUntil(
event_loop.set_control_flow(ControlFlow::WaitUntil(
time::Instant::now() + WAIT_TIME,
));
}
}
Mode::Poll => {
thread::sleep(POLL_SLEEP_TIME);
elwt.set_control_flow(ControlFlow::Poll);
event_loop.set_control_flow(ControlFlow::Poll);
}
};

if close_requested {
elwt.exit();
event_loop.exit();
}
}
_ => (),
Expand Down
4 changes: 2 additions & 2 deletions examples/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() -> Result<(), impl std::error::Error> {

let mut cursor_idx = 0;

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::KeyboardInput {
Expand All @@ -42,7 +42,7 @@ fn main() -> Result<(), impl std::error::Error> {
fill::fill_window(&window);
}
WindowEvent::CloseRequested => {
elwt.exit();
event_loop.exit();
}
_ => (),
}
Expand Down
6 changes: 3 additions & 3 deletions examples/cursor_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ fn main() -> Result<(), impl std::error::Error> {

let mut modifiers = ModifiersState::default();

event_loop.run(move |event, elwt| match event {
event_loop.run(move |event, event_loop| match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::KeyboardInput {
event:
KeyEvent {
Expand All @@ -36,7 +36,7 @@ fn main() -> Result<(), impl std::error::Error> {
} => {
let result = match key {
Key::Named(NamedKey::Escape) => {
elwt.exit();
event_loop.exit();
Ok(())
}
Key::Character(ch) => match ch.to_lowercase().as_str() {
Expand Down
10 changes: 5 additions & 5 deletions examples/custom_cursors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn main() -> Result<(), impl std::error::Error> {
decode_cursor(include_bytes!("data/cross2.png"), &event_loop),
];

event_loop.run(move |event, _elwt| match event {
event_loop.run(move |event, _event_loop| match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {
event:
Expand Down Expand Up @@ -94,7 +94,7 @@ fn main() -> Result<(), impl std::error::Error> {
64,
64,
)
.build(_elwt),
.build(_event_loop),
);
}
#[cfg(wasm_platform)]
Expand All @@ -114,11 +114,11 @@ fn main() -> Result<(), impl std::error::Error> {
64,
64,
)
.build(_elwt),
.build(_event_loop),
],
)
.unwrap()
.build(_elwt),
.build(_event_loop),
);
}
_ => {}
Expand All @@ -129,7 +129,7 @@ fn main() -> Result<(), impl std::error::Error> {
}
WindowEvent::CloseRequested => {
#[cfg(not(wasm_platform))]
_elwt.exit();
_event_loop.exit();
}
_ => (),
},
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ fn main() -> Result<(), impl std::error::Error> {
}
});

event_loop.run(move |event, elwt| match event {
event_loop.run(move |event, event_loop| match event {
Event::UserEvent(event) => println!("user event: {event:?}"),
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => elwt.exit(),
} => event_loop.exit(),
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
Expand Down
4 changes: 2 additions & 2 deletions examples/drag_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ fn main() -> Result<(), impl std::error::Error> {
let mut entered_id = window_2.id();
let mut cursor_location = None;

event_loop.run(move |event, elwt| match event {
event_loop.run(move |event, event_loop| match event {
Event::NewEvents(StartCause::Init) => {
eprintln!("Switch which window is to be dragged by pressing \"x\".")
}
Event::WindowEvent { event, window_id } => match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::CursorMoved { position, .. } => cursor_location = Some(position),
WindowEvent::MouseInput { state, button, .. } => {
let window = if (window_id == window_1.id() && switched)
Expand Down
6 changes: 3 additions & 3 deletions examples/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() -> Result<(), impl std::error::Error> {
.unwrap();

let mut deadline = time::Instant::now() + time::Duration::from_secs(3);
event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
match event {
Event::NewEvents(StartCause::ResumeTimeReached { .. }) => {
// Timeout reached; focus the window.
Expand All @@ -36,7 +36,7 @@ fn main() -> Result<(), impl std::error::Error> {
window.focus_window();
}
Event::WindowEvent { event, window_id } if window_id == window.id() => match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::RedrawRequested => {
// Notify the windowing system that we'll be presenting to the window.
window.pre_present_notify();
Expand All @@ -51,6 +51,6 @@ fn main() -> Result<(), impl std::error::Error> {
_ => (),
}

elwt.set_control_flow(winit::event_loop::ControlFlow::WaitUntil(deadline));
event_loop.set_control_flow(winit::event_loop::ControlFlow::WaitUntil(deadline));
})
}
14 changes: 8 additions & 6 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ fn main() -> Result<(), impl std::error::Error> {
println!("- I\tToggle mIn size limit");
println!("- A\tToggle mAx size limit");

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::KeyboardInput {
event:
KeyEvent {
Expand All @@ -65,7 +65,7 @@ fn main() -> Result<(), impl std::error::Error> {
},
..
} => match key {
Key::Named(NamedKey::Escape) => elwt.exit(),
Key::Named(NamedKey::Escape) => event_loop.exit(),
// WARNING: Consider using `key_without_modifers()` if available on your platform.
// See the `key_binding` example
Key::Character(ch) => match ch.to_lowercase().as_str() {
Expand All @@ -88,12 +88,14 @@ fn main() -> Result<(), impl std::error::Error> {
}
"s" => {
monitor_index += 1;
if let Some(mon) = elwt.available_monitors().nth(monitor_index) {
if let Some(mon) = event_loop.available_monitors().nth(monitor_index) {
monitor = mon;
} else {
monitor_index = 0;
monitor =
elwt.available_monitors().next().expect("no monitor found!");
monitor = event_loop
.available_monitors()
.next()
.expect("no monitor found!");
}
println!("Monitor: {:?}", monitor.name());

Expand Down
4 changes: 2 additions & 2 deletions examples/handling_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> Result<(), impl std::error::Error> {

let mut close_requested = false;

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => {
Expand Down Expand Up @@ -64,7 +64,7 @@ fn main() -> Result<(), impl std::error::Error> {
// event loop (i.e. if it's a multi-window application), you need to
// drop the window. That closes it, and results in `Destroyed` being
// sent.
elwt.exit();
event_loop.exit();
}
}
Key::Character("n") => {
Expand Down
4 changes: 2 additions & 2 deletions examples/ime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ fn main() -> Result<(), impl std::error::Error> {
let mut cursor_position = PhysicalPosition::new(0.0, 0.0);
let mut ime_pos = PhysicalPosition::new(0.0, 0.0);

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::CursorMoved { position, .. } => {
cursor_position = position;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/key_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ fn main() -> Result<(), impl std::error::Error> {

let mut modifiers = ModifiersState::default();

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::ModifiersChanged(new) => {
modifiers = new.state();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ In both cases the example window should move like the content of a scroll area i
In other words, the deltas indicate the direction in which to move the content (in this case the window)."
);

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::MouseWheel { delta, .. } => match delta {
winit::event::MouseScrollDelta::LineDelta(x, y) => {
println!("mouse wheel Line Delta: ({x},{y})");
Expand Down
4 changes: 2 additions & 2 deletions examples/multithreaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ fn main() -> Result<(), impl std::error::Error> {
}
});
}
event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if window_senders.is_empty() {
elwt.exit()
event_loop.exit()
}
match event {
Event::WindowEvent { event, window_id } => match event {
Expand Down
8 changes: 4 additions & 4 deletions examples/multiwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> Result<(), impl std::error::Error> {

println!("Press N to open a new window.");

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, window_id } = event {
match event {
WindowEvent::CloseRequested => {
Expand All @@ -36,17 +36,17 @@ fn main() -> Result<(), impl std::error::Error> {
windows.remove(&window_id);

if windows.is_empty() {
elwt.exit();
event_loop.exit();
}
}
WindowEvent::KeyboardInput {
event,
is_synthetic: false,
..
} if event.state == ElementState::Pressed => match event.logical_key {
Key::Named(NamedKey::Escape) => elwt.exit(),
Key::Named(NamedKey::Escape) => event_loop.exit(),
Key::Character(c) if c == "n" || c == "N" => {
let window = Window::new(elwt).unwrap();
let window = Window::new(event_loop).unwrap();
println!("Opened a new window: {:?}", window.id());
windows.insert(window.id(), window);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/request_redraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ fn main() -> Result<(), impl std::error::Error> {
.build(&event_loop)
.unwrap();

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
println!("{event:?}");

if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::MouseInput {
state: ElementState::Released,
..
Expand Down
4 changes: 2 additions & 2 deletions examples/request_redraw_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ fn main() -> Result<(), impl std::error::Error> {
}
});

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
println!("{event:?}");

match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => elwt.exit(),
} => event_loop.exit(),
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
Expand Down
4 changes: 2 additions & 2 deletions examples/resizable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ fn main() -> Result<(), impl std::error::Error> {
.build(&event_loop)
.unwrap();

event_loop.run(move |event, elwt| {
event_loop.run(move |event, event_loop| {
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::KeyboardInput {
event:
KeyEvent {
Expand Down
Loading

0 comments on commit 1dd64d8

Please sign in to comment.