mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-02 06:40:06 -04:00
Fix examples to have an exit code
This commit is contained in:
@@ -88,7 +88,7 @@ fn main() {
|
|||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
if close_requested {
|
if close_requested {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_window_id) => {}
|
Event::RedrawRequested(_window_id) => {}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ fn main() {
|
|||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ fn main() {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit(0),
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
KeyboardInput {
|
KeyboardInput {
|
||||||
@@ -33,7 +33,7 @@ fn main() {
|
|||||||
} => {
|
} => {
|
||||||
use winit::event::VirtualKeyCode::*;
|
use winit::event::VirtualKeyCode::*;
|
||||||
match key {
|
match key {
|
||||||
Escape => *control_flow = ControlFlow::Exit,
|
Escape => *control_flow = ControlFlow::Exit(0),
|
||||||
G => window.set_cursor_grab(!modifiers.shift()).unwrap(),
|
G => window.set_cursor_grab(!modifiers.shift()).unwrap(),
|
||||||
H => window.set_cursor_visible(modifiers.shift()),
|
H => window.set_cursor_visible(modifiers.shift()),
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ fn main() {
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => *control_flow = ControlFlow::Exit,
|
} => *control_flow = ControlFlow::Exit(0),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ fn main() {
|
|||||||
eprintln!("Switch which window is to be dragged by pressing \"x\".")
|
eprintln!("Switch which window is to be dragged by pressing \"x\".")
|
||||||
}
|
}
|
||||||
Event::WindowEvent { event, window_id } => match event {
|
Event::WindowEvent { event, window_id } => match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit(0),
|
||||||
WindowEvent::MouseInput {
|
WindowEvent::MouseInput {
|
||||||
state: ElementState::Pressed,
|
state: ElementState::Pressed,
|
||||||
button: MouseButton::Left,
|
button: MouseButton::Left,
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ fn main() {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit(0),
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
KeyboardInput {
|
KeyboardInput {
|
||||||
@@ -46,7 +46,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
..
|
..
|
||||||
} => match (virtual_code, state) {
|
} => match (virtual_code, state) {
|
||||||
(VirtualKeyCode::Escape, _) => *control_flow = ControlFlow::Exit,
|
(VirtualKeyCode::Escape, _) => *control_flow = ControlFlow::Exit(0),
|
||||||
(VirtualKeyCode::F, ElementState::Pressed) => {
|
(VirtualKeyCode::F, ElementState::Pressed) => {
|
||||||
if window.fullscreen().is_some() {
|
if window.fullscreen().is_some() {
|
||||||
window.set_fullscreen(None);
|
window.set_fullscreen(None);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ fn main() {
|
|||||||
// event loop (i.e. if it's a multi-window application), you need to
|
// 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
|
// drop the window. That closes it, and results in `Destroyed` being
|
||||||
// sent.
|
// sent.
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
N => {
|
N => {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ fn main() {
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => *control_flow = ControlFlow::Exit,
|
} => *control_flow = ControlFlow::Exit(0),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ fn main() {
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => *control_flow = ControlFlow::Exit,
|
} => *control_flow = ControlFlow::Exit(0),
|
||||||
|
|
||||||
// Keyboard input event to handle minimize via a hotkey
|
// Keyboard input event to handle minimize via a hotkey
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ fn main() {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit(0),
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::DeviceEvent { event, .. } => match event {
|
Event::DeviceEvent { event, .. } => match event {
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ fn main() {
|
|||||||
event_loop.run(move |event, _event_loop, control_flow| {
|
event_loop.run(move |event, _event_loop, control_flow| {
|
||||||
*control_flow = match !window_senders.is_empty() {
|
*control_flow = match !window_senders.is_empty() {
|
||||||
true => ControlFlow::Wait,
|
true => ControlFlow::Wait,
|
||||||
false => ControlFlow::Exit,
|
false => ControlFlow::Exit(0),
|
||||||
};
|
};
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, window_id } => match event {
|
Event::WindowEvent { event, window_id } => match event {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ fn main() {
|
|||||||
windows.remove(&window_id);
|
windows.remove(&window_id);
|
||||||
|
|
||||||
if windows.is_empty() {
|
if windows.is_empty() {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ fn main() {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit(0),
|
||||||
WindowEvent::MouseInput {
|
WindowEvent::MouseInput {
|
||||||
state: ElementState::Released,
|
state: ElementState::Released,
|
||||||
..
|
..
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fn main() {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit(0),
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::RedrawRequested(_) => {
|
Event::RedrawRequested(_) => {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ fn main() {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit(0),
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
KeyboardInput {
|
KeyboardInput {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ fn main() {
|
|||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fn main() {
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => *control_flow = ControlFlow::Exit,
|
} => *control_flow = ControlFlow::Exit(0),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ fn main() {
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => *control_flow = ControlFlow::Exit,
|
} => *control_flow = ControlFlow::Exit(0),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ pub fn main() {
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
window_id,
|
window_id,
|
||||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
} if window_id == window.id() => *control_flow = ControlFlow::Exit(0),
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ fn main() {
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
window_id,
|
window_id,
|
||||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
} if window_id == window.id() => *control_flow = ControlFlow::Exit(0),
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ fn main() {
|
|||||||
window.set_minimized(minimized);
|
window.set_minimized(minimized);
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Q => {
|
VirtualKeyCode::Q => {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit(0);
|
||||||
}
|
}
|
||||||
VirtualKeyCode::V => {
|
VirtualKeyCode::V => {
|
||||||
visible = !visible;
|
visible = !visible;
|
||||||
@@ -118,7 +118,7 @@ fn main() {
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
window_id,
|
window_id,
|
||||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
} if window_id == window.id() => *control_flow = ControlFlow::Exit(0),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ fn main() {
|
|||||||
if let Event::WindowEvent { event, .. } = event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
use winit::event::WindowEvent::*;
|
use winit::event::WindowEvent::*;
|
||||||
match event {
|
match event {
|
||||||
CloseRequested => *control_flow = ControlFlow::Exit,
|
CloseRequested => *control_flow = ControlFlow::Exit(0),
|
||||||
DroppedFile(path) => {
|
DroppedFile(path) => {
|
||||||
window.set_window_icon(Some(load_icon(&path)));
|
window.set_window_icon(Some(load_icon(&path)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ fn main() {
|
|||||||
quit = true;
|
quit = true;
|
||||||
}
|
}
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit(0);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user