egui_winit_ash_integration/lib.rs
1//! This is the [egui](https://github.com/emilk/egui) integration crate for
2//! [winit](https://github.com/rust-windowing/winit) and [ash](https://github.com/MaikKlein/ash).
3//! The default GPU allocator is
4//! [gpu_allocator](https://github.com/Traverse-Research/gpu-allocator),
5//! but you can also implement AllocatorTrait.
6//!
7//! # Example
8//! ```sh
9//! cargo run --example example
10//! ```
11//!
12//! ```sh
13//! cargo run --example user_texture
14//! ```
15//!
16//! # Usage
17//!
18//! ```
19//! fn main() -> Result<()> {
20//! let event_loop = EventLoop::new();
21//! // (1) Call Integration::<Arc<Mutex<Allocator>>>::new() in App::new().
22//! let mut app = App::new(&event_loop)?;
23//!
24//! event_loop.run(move |event, _, control_flow| {
25//! *control_flow = ControlFlow::Poll;
26//! // (2) Call integration.handle_event(&event).
27//! app.egui_integration.handle_event(&event);
28//! match event {
29//! Event::WindowEvent {
30//! event: WindowEvent::CloseRequested,
31//! ..
32//! } => *control_flow = ControlFlow::Exit,
33//! Event::WindowEvent {
34//! event: WindowEvent::Resized(_),
35//! ..
36//! } => {
37//! // (3) Call integration.recreate_swapchain(...) in app.recreate_swapchain().
38//! app.recreate_swapchain().unwrap();
39//! }
40//! Event::MainEventsCleared => app.window.request_redraw(),
41//! Event::RedrawRequested(_window_id) => {
42//! // (4) Call integration.begin_frame(), integration.end_frame(&mut window),
43//! // integration.context().tessellate(shapes), integration.paint(...)
44//! // in app.draw().
45//! app.draw().unwrap();
46//! }
47//! _ => (),
48//! }
49//! })
50//! }
51//! // (5) Call integration.destroy() when drop app.
52//! ```
53//!
54//! [Full example is in examples directory](https://github.com/MatchaChoco010/egui-winit-ash-integration/tree/main/examples)
55
56mod allocator;
57mod integration;
58mod utils;
59
60pub use allocator::*;
61pub use integration::*;
62
63#[cfg(feature = "gpu-allocator-feature")]
64mod gpu_allocator;
65#[cfg(feature = "gpu-allocator-feature")]
66pub use crate::gpu_allocator::*;