Update winit

This commit is contained in:
grovesNL 2024-01-15 16:03:02 -03:30 committed by Josh Groves
parent ce394f9d53
commit c2469de817
2 changed files with 74 additions and 78 deletions

View file

@ -14,5 +14,5 @@ cosmic-text = "0.10"
lru = "0.11" lru = "0.11"
[dev-dependencies] [dev-dependencies]
winit = "0.28.7" winit = { version = "0.29.10", features = ["rwh_05"] }
pollster = "0.3.0" pollster = "0.3.0"

View file

@ -11,7 +11,7 @@ use wgpu::{
use winit::{ use winit::{
dpi::LogicalSize, dpi::LogicalSize,
event::{Event, WindowEvent}, event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::EventLoop,
window::WindowBuilder, window::WindowBuilder,
}; };
@ -22,7 +22,7 @@ fn main() {
async fn run() { async fn run() {
// Set up window // Set up window
let (width, height) = (800, 600); let (width, height) = (800, 600);
let event_loop = EventLoop::new(); let event_loop = EventLoop::new().unwrap();
let window = WindowBuilder::new() let window = WindowBuilder::new()
.with_inner_size(LogicalSize::new(width as f64, height as f64)) .with_inner_size(LogicalSize::new(width as f64, height as f64))
.with_title("glyphon hello world") .with_title("glyphon hello world")
@ -76,84 +76,80 @@ async fn run() {
buffer.set_text(&mut font_system, "Hello world! 👋\nThis is rendered with 🦅 glyphon 🦁\nThe text below should be partially clipped.\na b c d e f g h i j k l m n o p q r s t u v w x y z", Attrs::new().family(Family::SansSerif), Shaping::Advanced); buffer.set_text(&mut font_system, "Hello world! 👋\nThis is rendered with 🦅 glyphon 🦁\nThe text below should be partially clipped.\na b c d e f g h i j k l m n o p q r s t u v w x y z", Attrs::new().family(Family::SansSerif), Shaping::Advanced);
buffer.shape_until_scroll(&mut font_system); buffer.shape_until_scroll(&mut font_system);
event_loop.run(move |event, _, control_flow| { event_loop
let _ = (&instance, &adapter); .run(move |event, target| {
if let Event::WindowEvent {
window_id: _,
event,
} = event
{
match event {
WindowEvent::Resized(size) => {
config.width = size.width;
config.height = size.height;
surface.configure(&device, &config);
window.request_redraw();
}
WindowEvent::RedrawRequested => {
text_renderer
.prepare(
&device,
&queue,
&mut font_system,
&mut atlas,
Resolution {
width: config.width,
height: config.height,
},
[TextArea {
buffer: &buffer,
left: 10.0,
top: 10.0,
scale: 1.0,
bounds: TextBounds {
left: 0,
top: 0,
right: 600,
bottom: 160,
},
default_color: Color::rgb(255, 255, 255),
}],
&mut cache,
)
.unwrap();
*control_flow = ControlFlow::Poll; let frame = surface.get_current_texture().unwrap();
match event { let view = frame.texture.create_view(&TextureViewDescriptor::default());
Event::WindowEvent { let mut encoder = device
event: WindowEvent::Resized(size), .create_command_encoder(&CommandEncoderDescriptor { label: None });
.. {
} => { let mut pass = encoder.begin_render_pass(&RenderPassDescriptor {
config.width = size.width; label: None,
config.height = size.height; color_attachments: &[Some(RenderPassColorAttachment {
surface.configure(&device, &config); view: &view,
window.request_redraw(); resolve_target: None,
} ops: Operations {
Event::RedrawRequested(_) => { load: LoadOp::Clear(wgpu::Color::BLACK),
text_renderer store: wgpu::StoreOp::Store,
.prepare( },
&device, })],
&queue, depth_stencil_attachment: None,
&mut font_system, timestamp_writes: None,
&mut atlas, occlusion_query_set: None,
Resolution { });
width: config.width,
height: config.height,
},
[TextArea {
buffer: &buffer,
left: 10.0,
top: 10.0,
scale: 1.0,
bounds: TextBounds {
left: 0,
top: 0,
right: 600,
bottom: 160,
},
default_color: Color::rgb(255, 255, 255),
}],
&mut cache,
)
.unwrap();
let frame = surface.get_current_texture().unwrap(); text_renderer.render(&atlas, &mut pass).unwrap();
let view = frame.texture.create_view(&TextureViewDescriptor::default()); }
let mut encoder =
device.create_command_encoder(&CommandEncoderDescriptor { label: None });
{
let mut pass = encoder.begin_render_pass(&RenderPassDescriptor {
label: None,
color_attachments: &[Some(RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: Operations {
load: LoadOp::Clear(wgpu::Color::BLACK),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
text_renderer.render(&atlas, &mut pass).unwrap(); queue.submit(Some(encoder.finish()));
frame.present();
atlas.trim();
}
WindowEvent::CloseRequested => target.exit(),
_ => {}
} }
queue.submit(Some(encoder.finish()));
frame.present();
atlas.trim();
} }
Event::WindowEvent { })
event: WindowEvent::CloseRequested, .unwrap();
..
} => *control_flow = ControlFlow::Exit,
Event::MainEventsCleared => {
window.request_redraw();
}
_ => {}
}
});
} }