diff options
author | 2022-07-08 19:31:45 +0200 | |
---|---|---|
committer | 2022-07-08 19:31:45 +0200 | |
commit | fa55dff61db47197a961152285c6a6abfab0b217 (patch) | |
tree | 44904afb16a0cab9e22fce0d73a5616676cd426b /examples | |
parent | 1dd1a2f97fc747e15e12b5188dad6c41b0d052ea (diff) | |
parent | 66eb6263003c1bbedd1fd14d6b12f172d20a6211 (diff) | |
download | iced-fa55dff61db47197a961152285c6a6abfab0b217.tar.gz iced-fa55dff61db47197a961152285c6a6abfab0b217.tar.bz2 iced-fa55dff61db47197a961152285c6a6abfab0b217.zip |
Merge branch 'master' into theming
Diffstat (limited to 'examples')
-rw-r--r-- | examples/README.md | 5 | ||||
-rw-r--r-- | examples/integration_wgpu/src/main.rs | 18 | ||||
-rw-r--r-- | examples/integration_wgpu/src/scene.rs | 12 | ||||
-rw-r--r-- | examples/integration_wgpu/src/shader/frag.wgsl | 4 | ||||
-rw-r--r-- | examples/integration_wgpu/src/shader/vert.wgsl | 4 | ||||
-rw-r--r-- | examples/solar_system/src/main.rs | 8 | ||||
-rw-r--r-- | examples/tour/README.md | 9 |
7 files changed, 28 insertions, 32 deletions
diff --git a/examples/README.md b/examples/README.md index 137d134c..2b4919df 100644 --- a/examples/README.md +++ b/examples/README.md @@ -27,10 +27,6 @@ You can run the native version with `cargo run`: cargo run --package tour ``` -The web version can be run by following [the usage instructions of `iced_web`] or by accessing [iced.rs](https://iced.rs/)! - -[the usage instructions of `iced_web`]: https://github.com/iced-rs/iced_web#usage - ## [Todos](todos) A todos tracker inspired by [TodoMVC]. It showcases dynamic layout, text input, checkboxes, scrollables, icons, and async actions! It automatically saves your tasks in the background, even if you did not finish typing them. @@ -46,7 +42,6 @@ You can run the native version with `cargo run`: ``` cargo run --package todos ``` -We have not yet implemented a `LocalStorage` version of the auto-save feature. Therefore, it does not work on web _yet_! [TodoMVC]: http://todomvc.com/ diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 76f35eef..1108b55d 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -7,7 +7,6 @@ use scene::Scene; use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport}; use iced_winit::{conversion, futures, program, winit, Clipboard, Debug, Size}; -use futures::task::SpawnExt; use winit::{ dpi::PhysicalPosition, event::{Event, ModifiersState, WindowEvent}, @@ -91,7 +90,9 @@ pub fn main() { ( surface - .get_preferred_format(&adapter) + .get_supported_formats(&adapter) + .first() + .copied() .expect("Get preferred format"), adapter .request_device( @@ -114,15 +115,14 @@ pub fn main() { format, width: physical_size.width, height: physical_size.height, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, }, ); let mut resized = false; - // Initialize staging belt and local pool + // Initialize staging belt let mut staging_belt = wgpu::util::StagingBelt::new(5 * 1024); - let mut local_pool = futures::executor::LocalPool::new(); // Initialize scene and GUI controls let scene = Scene::new(&mut device, format); @@ -208,7 +208,7 @@ pub fn main() { format: format, width: size.width, height: size.height, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, }, ); @@ -263,12 +263,8 @@ pub fn main() { ); // And recall staging buffers - local_pool - .spawner() - .spawn(staging_belt.recall()) - .expect("Recall staging buffers"); + staging_belt.recall(); - local_pool.run_until_stalled(); } Err(error) => match error { wgpu::SurfaceError::OutOfMemory => { diff --git a/examples/integration_wgpu/src/scene.rs b/examples/integration_wgpu/src/scene.rs index fbda1326..af75e67c 100644 --- a/examples/integration_wgpu/src/scene.rs +++ b/examples/integration_wgpu/src/scene.rs @@ -23,7 +23,7 @@ impl Scene { ) -> wgpu::RenderPass<'a> { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachment { + color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: target, resolve_target: None, ops: wgpu::Operations { @@ -39,7 +39,7 @@ impl Scene { }), store: true, }, - }], + })], depth_stencil_attachment: None, }) } @@ -55,8 +55,8 @@ fn build_pipeline( texture_format: wgpu::TextureFormat, ) -> wgpu::RenderPipeline { let (vs_module, fs_module) = ( - device.create_shader_module(&wgpu::include_wgsl!("shader/vert.wgsl")), - device.create_shader_module(&wgpu::include_wgsl!("shader/frag.wgsl")), + device.create_shader_module(wgpu::include_wgsl!("shader/vert.wgsl")), + device.create_shader_module(wgpu::include_wgsl!("shader/frag.wgsl")), ); let pipeline_layout = @@ -78,14 +78,14 @@ fn build_pipeline( fragment: Some(wgpu::FragmentState { module: &fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format: texture_format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, diff --git a/examples/integration_wgpu/src/shader/frag.wgsl b/examples/integration_wgpu/src/shader/frag.wgsl index a6f61336..cf27bb56 100644 --- a/examples/integration_wgpu/src/shader/frag.wgsl +++ b/examples/integration_wgpu/src/shader/frag.wgsl @@ -1,4 +1,4 @@ -[[stage(fragment)]] -fn main() -> [[location(0)]] vec4<f32> { +@fragment +fn main() -> @location(0) vec4<f32> { return vec4<f32>(1.0, 0.0, 0.0, 1.0); } diff --git a/examples/integration_wgpu/src/shader/vert.wgsl b/examples/integration_wgpu/src/shader/vert.wgsl index 7ef47fb2..e353e6ba 100644 --- a/examples/integration_wgpu/src/shader/vert.wgsl +++ b/examples/integration_wgpu/src/shader/vert.wgsl @@ -1,5 +1,5 @@ -[[stage(vertex)]] -fn main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4<f32> { +@vertex +fn main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> { let x = f32(1 - i32(in_vertex_index)) * 0.5; let y = f32(1 - i32(in_vertex_index & 1u) * 2) * 0.5; return vec4<f32>(x, y, 0.0, 1.0); diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 5f6c309d..7e0e06b0 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -73,6 +73,10 @@ impl Application for SolarSystem { .height(Length::Fill) .into() } + + fn theme(&self) -> Theme { + Theme::Dark + } } #[derive(Debug)] @@ -142,16 +146,12 @@ impl<Message> canvas::Program<Message> for State { use std::f32::consts::PI; let background = self.space_cache.draw(bounds.size(), |frame| { - let space = Path::rectangle(Point::new(0.0, 0.0), frame.size()); - let stars = Path::new(|path| { for (p, size) in &self.stars { path.rectangle(*p, Size::new(*size, *size)); } }); - frame.fill(&space, Color::BLACK); - frame.translate(frame.center() - Point::ORIGIN); frame.fill(&stars, Color::WHITE); }); diff --git a/examples/tour/README.md b/examples/tour/README.md index e7cd2d5c..731e7e66 100644 --- a/examples/tour/README.md +++ b/examples/tour/README.md @@ -23,6 +23,11 @@ You can run the native version with `cargo run`: cargo run --package tour ``` -The web version can be run by following [the usage instructions of `iced_web`] or by accessing [iced.rs](https://iced.rs/)! +The web version can be run with [`trunk`]: -[the usage instructions of `iced_web`]: https://github.com/iced-rs/iced_web#usage +``` +cd examples/tour +trunk serve +``` + +[`trunk`]: https://trunkrs.dev/ |