From 3be8f6e98990f7e8a3af11400bbecaecddda336c Mon Sep 17 00:00:00 2001 From: Nick Senger Date: Tue, 10 May 2022 17:18:08 -0700 Subject: fix: prevent building overlay with stale layout --- lazy/src/component.rs | 36 +++++++++++++++++++++++++++++++++--- lazy/src/pure/component.rs | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/lazy/src/component.rs b/lazy/src/component.rs index 9e5937e9..06392c33 100644 --- a/lazy/src/component.rs +++ b/lazy/src/component.rs @@ -376,6 +376,38 @@ where let mut local_messages = Vec::new(); let mut local_shell = Shell::new(&mut local_messages); + if self + .instance + .state + .borrow() + .as_ref() + .and_then(|state| state.borrow_cache().as_ref()) + .and_then(|cache| cache.borrow_overlay().as_ref()) + .is_none() + { + let component = + self.instance.state.take().unwrap().into_heads().component; + + self.instance.state = RefCell::new(Some( + StateBuilder { + component, + message: PhantomData, + cache_builder: |state| { + Some( + CacheBuilder { + element: state.view(), + overlay_builder: |element| { + element.overlay(layout, renderer) + }, + } + .build(), + ) + }, + } + .build(), + )); + } + let event_status = self .with_overlay_mut_maybe(|overlay| { overlay.on_event( @@ -410,9 +442,7 @@ where Some( CacheBuilder { element: state.view(), - overlay_builder: |element| { - element.overlay(layout, renderer) - }, + overlay_builder: |_| None, } .build(), ) diff --git a/lazy/src/pure/component.rs b/lazy/src/pure/component.rs index 2971d2b7..bf6ff908 100644 --- a/lazy/src/pure/component.rs +++ b/lazy/src/pure/component.rs @@ -415,6 +415,35 @@ where let mut local_messages = Vec::new(); let mut local_shell = Shell::new(&mut local_messages); + if self + .overlay + .as_ref() + .and_then(|overlay| overlay.borrow_overlay().as_ref()) + .is_none() + { + let overlay = self.overlay.take().unwrap().into_heads(); + + self.overlay = Some( + OverlayBuilder { + instance: overlay.instance, + instance_ref_builder: |instance| instance.state.borrow(), + tree: overlay.tree, + types: PhantomData, + overlay_builder: |instance, tree| { + instance + .as_ref() + .unwrap() + .borrow_element() + .as_ref() + .unwrap() + .as_widget() + .overlay(&mut tree.children[0], layout, renderer) + }, + } + .build(), + ); + } + let event_status = self .with_overlay_mut_maybe(|overlay| { overlay.on_event( @@ -464,16 +493,7 @@ where instance_ref_builder: |instance| instance.state.borrow(), tree: overlay.tree, types: PhantomData, - overlay_builder: |instance, tree| { - instance - .as_ref() - .unwrap() - .borrow_element() - .as_ref() - .unwrap() - .as_widget() - .overlay(&mut tree.children[0], layout, renderer) - }, + overlay_builder: |_, _| None, } .build(), ); -- cgit From 4c98de0a53b9a59a3a03cee0c5d7ce34ac434067 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 13 May 2022 18:45:03 +0200 Subject: Revert "fix: prevent building overlay with stale layout" This reverts commit 3be8f6e98990f7e8a3af11400bbecaecddda336c. --- lazy/src/component.rs | 36 +++--------------------------------- lazy/src/pure/component.rs | 40 ++++++++++------------------------------ 2 files changed, 13 insertions(+), 63 deletions(-) diff --git a/lazy/src/component.rs b/lazy/src/component.rs index 06392c33..9e5937e9 100644 --- a/lazy/src/component.rs +++ b/lazy/src/component.rs @@ -376,38 +376,6 @@ where let mut local_messages = Vec::new(); let mut local_shell = Shell::new(&mut local_messages); - if self - .instance - .state - .borrow() - .as_ref() - .and_then(|state| state.borrow_cache().as_ref()) - .and_then(|cache| cache.borrow_overlay().as_ref()) - .is_none() - { - let component = - self.instance.state.take().unwrap().into_heads().component; - - self.instance.state = RefCell::new(Some( - StateBuilder { - component, - message: PhantomData, - cache_builder: |state| { - Some( - CacheBuilder { - element: state.view(), - overlay_builder: |element| { - element.overlay(layout, renderer) - }, - } - .build(), - ) - }, - } - .build(), - )); - } - let event_status = self .with_overlay_mut_maybe(|overlay| { overlay.on_event( @@ -442,7 +410,9 @@ where Some( CacheBuilder { element: state.view(), - overlay_builder: |_| None, + overlay_builder: |element| { + element.overlay(layout, renderer) + }, } .build(), ) diff --git a/lazy/src/pure/component.rs b/lazy/src/pure/component.rs index bf6ff908..2971d2b7 100644 --- a/lazy/src/pure/component.rs +++ b/lazy/src/pure/component.rs @@ -415,35 +415,6 @@ where let mut local_messages = Vec::new(); let mut local_shell = Shell::new(&mut local_messages); - if self - .overlay - .as_ref() - .and_then(|overlay| overlay.borrow_overlay().as_ref()) - .is_none() - { - let overlay = self.overlay.take().unwrap().into_heads(); - - self.overlay = Some( - OverlayBuilder { - instance: overlay.instance, - instance_ref_builder: |instance| instance.state.borrow(), - tree: overlay.tree, - types: PhantomData, - overlay_builder: |instance, tree| { - instance - .as_ref() - .unwrap() - .borrow_element() - .as_ref() - .unwrap() - .as_widget() - .overlay(&mut tree.children[0], layout, renderer) - }, - } - .build(), - ); - } - let event_status = self .with_overlay_mut_maybe(|overlay| { overlay.on_event( @@ -493,7 +464,16 @@ where instance_ref_builder: |instance| instance.state.borrow(), tree: overlay.tree, types: PhantomData, - overlay_builder: |_, _| None, + overlay_builder: |instance, tree| { + instance + .as_ref() + .unwrap() + .borrow_element() + .as_ref() + .unwrap() + .as_widget() + .overlay(&mut tree.children[0], layout, renderer) + }, } .build(), ); -- cgit From 296e157dcf2efe1ae52ae6cc35060b2f0cf212bf Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 13 May 2022 19:07:54 +0200 Subject: Relayout base layer when layout is invalidated from an overlay --- native/src/shell.rs | 5 ++++ native/src/user_interface.rs | 67 +++++++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/native/src/shell.rs b/native/src/shell.rs index 4a0aa9c6..b96d23e5 100644 --- a/native/src/shell.rs +++ b/native/src/shell.rs @@ -31,6 +31,11 @@ impl<'a, Message> Shell<'a, Message> { } } + /// Returns whether the current layout is invalid or not. + pub fn is_layout_invalid(&self) -> bool { + self.is_layout_invalid + } + /// Publish the given `Message` for an application to process it. pub fn publish(&mut self, message: Message) { self.messages.push(message); diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs index f80786aa..785ee56a 100644 --- a/native/src/user_interface.rs +++ b/native/src/user_interface.rs @@ -177,40 +177,61 @@ where clipboard: &mut dyn Clipboard, messages: &mut Vec, ) -> (State, Vec) { + use std::mem::ManuallyDrop; + let mut state = State::Updated; + let mut manual_overlay = ManuallyDrop::new( + self.root.overlay(Layout::new(&self.base), renderer), + ); - let (base_cursor, overlay_statuses) = if let Some(mut overlay) = - self.root.overlay(Layout::new(&self.base), renderer) - { + let (base_cursor, overlay_statuses) = if manual_overlay.is_some() { let bounds = self.bounds; + + let mut overlay = manual_overlay.as_mut().unwrap(); let mut layout = overlay.layout(renderer, bounds); + let mut event_statuses = Vec::new(); - let event_statuses = events - .iter() - .cloned() - .map(|event| { - let mut shell = Shell::new(messages); + for event in events.iter().cloned() { + let mut shell = Shell::new(messages); - let event_status = overlay.on_event( - event, - Layout::new(&layout), - cursor_position, - renderer, - clipboard, - &mut shell, + let event_status = overlay.on_event( + event, + Layout::new(&layout), + cursor_position, + renderer, + clipboard, + &mut shell, + ); + + event_statuses.push(event_status); + + if shell.is_layout_invalid() { + let _ = ManuallyDrop::into_inner(manual_overlay); + + self.base = renderer.layout( + &self.root, + &layout::Limits::new(Size::ZERO, self.bounds), + ); + + manual_overlay = ManuallyDrop::new( + self.root.overlay(Layout::new(&self.base), renderer), ); + if manual_overlay.is_none() { + break; + } + + overlay = manual_overlay.as_mut().unwrap(); + shell.revalidate_layout(|| { layout = overlay.layout(renderer, bounds); }); + } - if shell.are_widgets_invalid() { - state = State::Outdated; - } - - event_status - }) - .collect(); + if shell.are_widgets_invalid() { + state = State::Outdated; + } + } let base_cursor = if layout.bounds().contains(cursor_position) { // TODO: Type-safe cursor availability @@ -226,6 +247,8 @@ where (cursor_position, vec![event::Status::Ignored; events.len()]) }; + let _ = ManuallyDrop::into_inner(manual_overlay); + let event_statuses = events .iter() .cloned() -- cgit From ea389ac34c5a4929b7369da0f163ab6ae07bc000 Mon Sep 17 00:00:00 2001 From: Nick Senger Date: Fri, 13 May 2022 12:38:16 -0700 Subject: remove rebuild of component overlay from `on_event` --- lazy/src/component.rs | 4 +--- lazy/src/pure/component.rs | 11 +---------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/lazy/src/component.rs b/lazy/src/component.rs index 9e5937e9..2029c2a3 100644 --- a/lazy/src/component.rs +++ b/lazy/src/component.rs @@ -410,9 +410,7 @@ where Some( CacheBuilder { element: state.view(), - overlay_builder: |element| { - element.overlay(layout, renderer) - }, + overlay_builder: |_| None, } .build(), ) diff --git a/lazy/src/pure/component.rs b/lazy/src/pure/component.rs index 2971d2b7..b6e10054 100644 --- a/lazy/src/pure/component.rs +++ b/lazy/src/pure/component.rs @@ -464,16 +464,7 @@ where instance_ref_builder: |instance| instance.state.borrow(), tree: overlay.tree, types: PhantomData, - overlay_builder: |instance, tree| { - instance - .as_ref() - .unwrap() - .borrow_element() - .as_ref() - .unwrap() - .as_widget() - .overlay(&mut tree.children[0], layout, renderer) - }, + overlay_builder: |_, _| None, } .build(), ); -- cgit From ecd00cf02b23ccafd4427f498507621ebb017be7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 27 May 2022 19:43:50 +0200 Subject: Fix `Subscription` cancelation when never awaiting `StreamExt::forward` will keep polling a ready `Stream` in a loop. If the `Stream` is always ready, the `poll` method of `Forward` effectively blocks (see https://github.com/rust-lang/futures-rs/issues/2552). The fix consists in manually implementing a simpler version of `Forward`. --- futures/src/subscription/tracker.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/futures/src/subscription/tracker.rs b/futures/src/subscription/tracker.rs index 421fb917..2cf98284 100644 --- a/futures/src/subscription/tracker.rs +++ b/futures/src/subscription/tracker.rs @@ -1,6 +1,9 @@ use crate::{BoxFuture, MaybeSend, Subscription}; -use futures::{channel::mpsc, sink::Sink}; +use futures::{ + channel::mpsc, + sink::{Sink, SinkExt}, +}; use std::{collections::HashMap, marker::PhantomData}; /// A registry of subscription streams. @@ -64,7 +67,7 @@ where + MaybeSend + Clone, { - use futures::{future::FutureExt, stream::StreamExt}; + use futures::stream::StreamExt; let mut futures: Vec> = Vec::new(); @@ -85,19 +88,29 @@ where continue; } - let (cancel, cancelled) = futures::channel::oneshot::channel(); + let (cancel, mut canceled) = futures::channel::oneshot::channel(); // TODO: Use bus if/when it supports async let (event_sender, event_receiver) = futures::channel::mpsc::channel(100); - let stream = recipe.stream(event_receiver.boxed()); - - let future = futures::future::select( - cancelled, - stream.map(Ok).forward(receiver.clone()), - ) - .map(|_| ()); + let mut receiver = receiver.clone(); + let mut stream = recipe.stream(event_receiver.boxed()); + + let future = async move { + loop { + let select = + futures::future::select(&mut canceled, stream.next()); + + match select.await { + futures::future::Either::Left(_) + | futures::future::Either::Right((None, _)) => break, + futures::future::Either::Right((Some(message), _)) => { + let _ = receiver.send(message).await; + } + } + } + }; let _ = self.subscriptions.insert( id, -- cgit From cec032f9ed742f2ecd13dc5d6cdce0bdd5191732 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Thu, 26 May 2022 10:43:23 -0700 Subject: Don't process captured overlay statuses --- native/src/user_interface.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs index 785ee56a..2f2dc110 100644 --- a/native/src/user_interface.rs +++ b/native/src/user_interface.rs @@ -254,6 +254,10 @@ where .cloned() .zip(overlay_statuses.into_iter()) .map(|(event, overlay_status)| { + if matches!(overlay_status, event::Status::Captured) { + return overlay_status; + } + let mut shell = Shell::new(messages); let event_status = self.root.widget.on_event( -- cgit From 33653b766752a6aa0785357127af21af9932f6fc Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 31 May 2022 04:17:52 +0200 Subject: Try `Limits::default` in `iced_wgpu` before `downlevel_defaults` --- wgpu/src/window/compositor.rs | 46 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 54ea8247..dde5f09f 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -1,6 +1,8 @@ use crate::{Backend, Color, Error, Renderer, Settings, Viewport}; +use futures::stream::{self, StreamExt}; use futures::task::SpawnExt; + use iced_graphics::compositor; use iced_native::futures; use raw_window_handle::HasRawWindowHandle; @@ -66,28 +68,34 @@ impl Compositor { log::info!("Selected format: {:?}", format); #[cfg(target_arch = "wasm32")] - let limits = wgpu::Limits::downlevel_webgl2_defaults() - .using_resolution(adapter.limits()); + let limits = [wgpu::Limits::downlevel_webgl2_defaults() + .using_resolution(adapter.limits())]; #[cfg(not(target_arch = "wasm32"))] - let limits = wgpu::Limits::downlevel_defaults(); - - let (device, queue) = adapter - .request_device( - &wgpu::DeviceDescriptor { - label: Some( - "iced_wgpu::window::compositor device descriptor", - ), - features: wgpu::Features::empty(), - limits: wgpu::Limits { - max_bind_groups: 2, - ..limits + let limits = + [wgpu::Limits::default(), wgpu::Limits::downlevel_defaults()]; + + let limits = limits.into_iter().map(|limits| wgpu::Limits { + max_bind_groups: 2, + ..limits + }); + + let (device, queue) = stream::iter(limits) + .filter_map(|limits| async { + adapter.request_device( + &wgpu::DeviceDescriptor { + label: Some( + "iced_wgpu::window::compositor device descriptor", + ), + features: wgpu::Features::empty(), + limits, }, - }, - None, - ) - .await - .ok()?; + None, + ).await.ok() + }) + .boxed() + .next() + .await?; let staging_belt = wgpu::util::StagingBelt::new(Self::CHUNK_SIZE); let local_pool = futures::executor::LocalPool::new(); -- cgit From cb712f3b84590a3d2541744e3518e1532667c510 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 31 May 2022 05:40:39 +0200 Subject: Bump versions :tada: --- futures/Cargo.toml | 2 +- native/Cargo.toml | 2 +- pure/Cargo.toml | 2 +- wgpu/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/futures/Cargo.toml b/futures/Cargo.toml index ed99d79a..61ee00a5 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_futures" -version = "0.4.0" +version = "0.4.1" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "Commands, subscriptions, and runtimes for Iced" diff --git a/native/Cargo.toml b/native/Cargo.toml index a21385de..b4945c05 100644 --- a/native/Cargo.toml +++ b/native/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_native" -version = "0.5.0" +version = "0.5.1" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "A renderer-agnostic library for native GUIs" diff --git a/pure/Cargo.toml b/pure/Cargo.toml index 2301031d..b57e4c5a 100644 --- a/pure/Cargo.toml +++ b/pure/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_pure" -version = "0.2.1" +version = "0.2.2" edition = "2021" description = "Pure widgets for Iced" license = "MIT" diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 6911ff56..a4378aa0 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_wgpu" -version = "0.5.0" +version = "0.5.1" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "A wgpu renderer for Iced" -- cgit From ab7698f1f6bcf3fd951657a1ad357992145f7246 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm <2248455+casperstorm@users.noreply.github.com> Date: Thu, 2 Jun 2022 10:11:19 +0200 Subject: corrected images in README to be similar height --- README.md | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d4b7b39f..abb5b037 100644 --- a/README.md +++ b/README.md @@ -18,27 +18,28 @@ Inspired by [Elm]. - + ## Features - * Simple, easy-to-use, batteries-included API - * Type-safe, reactive programming model - * [Cross-platform support] (Windows, macOS, Linux, and [the Web]) - * Responsive layout - * Built-in widgets (including [text inputs], [scrollables], and more!) - * Custom widget support (create your own!) - * [Debug overlay with performance metrics] - * First-class support for async actions (use futures!) - * [Modular ecosystem] split into reusable parts: - * A [renderer-agnostic native runtime] enabling integration with existing systems - * Two [built-in renderers] leveraging [`wgpu`] and [`glow`] - * [`iced_wgpu`] supporting Vulkan, Metal and DX12 - * [`iced_glow`] supporting OpenGL 2.1+ and OpenGL ES 2.0+ - * A [windowing shell] - * A [web runtime] leveraging the DOM + +* Simple, easy-to-use, batteries-included API +* Type-safe, reactive programming model +* [Cross-platform support] (Windows, macOS, Linux, and [the Web]) +* Responsive layout +* Built-in widgets (including [text inputs], [scrollables], and more!) +* Custom widget support (create your own!) +* [Debug overlay with performance metrics] +* First-class support for async actions (use futures!) +* [Modular ecosystem] split into reusable parts: + * A [renderer-agnostic native runtime] enabling integration with existing systems + * Two [built-in renderers] leveraging [`wgpu`] and [`glow`] + * [`iced_wgpu`] supporting Vulkan, Metal and DX12 + * [`iced_glow`] supporting OpenGL 2.1+ and OpenGL ES 2.0+ + * A [windowing shell] + * A [web runtime] leveraging the DOM __Iced is currently experimental software.__ [Take a look at the roadmap], [check out the issues], and [feel free to contribute!] @@ -63,6 +64,7 @@ __Iced is currently experimental software.__ [Take a look at the roadmap], [feel free to contribute!]: #contributing--feedback ## Installation + Add `iced` as a dependency in your `Cargo.toml`: ```toml @@ -78,15 +80,16 @@ you want to learn about a specific release, check out [the release list]. [the release list]: https://github.com/iced-rs/iced/releases ## Overview + Inspired by [The Elm Architecture], Iced expects you to split user interfaces into four different concepts: - * __State__ — the state of your application - * __Messages__ — user interactions or meaningful events that you care +* __State__ — the state of your application +* __Messages__ — user interactions or meaningful events that you care about - * __View logic__ — a way to display your __state__ as widgets that +* __View logic__ — a way to display your __state__ as widgets that may produce __messages__ on user interaction - * __Update logic__ — a way to react to __messages__ and update your +* __Update logic__ — a way to react to __messages__ and update your __state__ We can build something to see how this works! Let's say we want a simple counter @@ -179,6 +182,7 @@ to: Browse the [documentation] and the [examples] to learn more! ## Implementation details + Iced was originally born as an attempt at bringing the simplicity of [Elm] and [The Elm Architecture] into [Coffee], a 2D game engine I am working on. @@ -204,7 +208,9 @@ end-user-oriented GUI library, while keeping [the ecosystem] modular: [the ecosystem]: ECOSYSTEM.md ## Troubleshooting + ### `GraphicsAdapterNotFound` + This occurs when the selected [built-in renderer] is not able to create a context. Often this will occur while using [`iced_wgpu`] as the renderer without @@ -212,22 +218,25 @@ supported hardware (needs Vulkan, Metal or DX12). In this case, you could try us [`iced_glow`] renderer: First, check if it works with + ```console -$ cargo run --features iced/glow --package game_of_life +cargo run --features iced/glow --package game_of_life ``` and then use it in your project with + ```toml iced = { version = "0.4", default-features = false, features = ["glow"] } ``` -**NOTE:** Chances are you have hardware that supports at least OpenGL 2.1 or OpenGL ES 2.0, +__NOTE:__ Chances are you have hardware that supports at least OpenGL 2.1 or OpenGL ES 2.0, but if you don't, right now there's no software fallback, so it means your hardware doesn't support Iced. [built-in renderer]: https://github.com/iced-rs/iced/blob/master/ECOSYSTEM.md#Renderers ## Contributing / Feedback + Contributions are greatly appreciated! If you want to contribute, please read our [contributing guidelines] for more details. @@ -237,6 +246,7 @@ awesome folks) over the `#games-and-graphics` and `#gui-and-ui` channels in the [Rust Community Discord]. I go by `lone_scientist#9554` there. ## Sponsors + The development of Iced is sponsored by the [Cryptowatch] team at [Kraken.com] [documentation]: https://docs.rs/iced/ -- cgit From 20780f36d1c00666140b31e8192e74e1cf36570c Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Tue, 7 Jun 2022 07:30:44 +0800 Subject: Prevent pane grid title bar content and controls from overlapping --- native/src/widget/pane_grid/title_bar.rs | 71 +++++++++++++++++++---------- pure/src/widget/pane_grid/title_bar.rs | 78 ++++++++++++++++++++------------ 2 files changed, 97 insertions(+), 52 deletions(-) diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index a10181af..6713724a 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -105,19 +105,17 @@ where let mut children = padded.children(); let title_layout = children.next().unwrap(); - - self.content.draw( - renderer, - &inherited_style, - title_layout, - cursor_position, - viewport, - ); + let mut show_title = true; if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); if show_controls || self.always_show_controls { + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } controls.draw( renderer, &inherited_style, @@ -127,6 +125,16 @@ where ); } } + + if show_title { + self.content.draw( + renderer, + &inherited_style, + title_layout, + cursor_position, + viewport, + ); + } } /// Returns whether the mouse cursor is over the pick area of the @@ -214,9 +222,15 @@ where let mut children = padded.children(); let title_layout = children.next().unwrap(); + let mut show_title = true; let control_status = if let Some(controls) = &mut self.controls { let controls_layout = children.next().unwrap(); + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } controls.on_event( event.clone(), @@ -230,14 +244,18 @@ where event::Status::Ignored }; - let title_status = self.content.on_event( - event, - title_layout, - cursor_position, - renderer, - clipboard, - shell, - ); + let title_status = if show_title { + self.content.on_event( + event, + title_layout, + cursor_position, + renderer, + clipboard, + shell, + ) + } else { + event::Status::Ignored + }; control_status.merge(title_status) } @@ -264,15 +282,20 @@ where if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); + let controls_interaction = controls.mouse_interaction( + controls_layout, + cursor_position, + viewport, + renderer, + ); - controls - .mouse_interaction( - controls_layout, - cursor_position, - viewport, - renderer, - ) - .max(title_interaction) + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + controls_interaction + } else { + controls_interaction.max(title_interaction) + } } else { title_interaction } diff --git a/pure/src/widget/pane_grid/title_bar.rs b/pure/src/widget/pane_grid/title_bar.rs index 4a7c8c17..af71dc43 100644 --- a/pure/src/widget/pane_grid/title_bar.rs +++ b/pure/src/widget/pane_grid/title_bar.rs @@ -132,18 +132,15 @@ where let mut children = padded.children(); let title_layout = children.next().unwrap(); - - self.content.as_widget().draw( - &tree.children[0], - renderer, - &inherited_style, - title_layout, - cursor_position, - viewport, - ); + let mut show_title = true; if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } if show_controls || self.always_show_controls { controls.as_widget().draw( @@ -156,6 +153,17 @@ where ); } } + + if show_title { + self.content.as_widget().draw( + &tree.children[0], + renderer, + &inherited_style, + title_layout, + cursor_position, + viewport, + ); + } } /// Returns whether the mouse cursor is over the pick area of the @@ -247,9 +255,15 @@ where let mut children = padded.children(); let title_layout = children.next().unwrap(); + let mut show_title = true; let control_status = if let Some(controls) = &mut self.controls { let controls_layout = children.next().unwrap(); + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } controls.as_widget_mut().on_event( &mut tree.children[1], @@ -264,15 +278,19 @@ where event::Status::Ignored }; - let title_status = self.content.as_widget_mut().on_event( - &mut tree.children[0], - event, - title_layout, - cursor_position, - renderer, - clipboard, - shell, - ); + let title_status = if show_title { + self.content.as_widget_mut().on_event( + &mut tree.children[0], + event, + title_layout, + cursor_position, + renderer, + clipboard, + shell, + ) + } else { + event::Status::Ignored + }; control_status.merge(title_status) } @@ -301,17 +319,21 @@ where if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); + let controls_interaction = controls.as_widget().mouse_interaction( + &tree.children[1], + controls_layout, + cursor_position, + viewport, + renderer, + ); - controls - .as_widget() - .mouse_interaction( - &tree.children[1], - controls_layout, - cursor_position, - viewport, - renderer, - ) - .max(title_interaction) + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + controls_interaction + } else { + controls_interaction.max(title_interaction) + } } else { title_interaction } -- cgit From 449bbb112e0c1e07c34cbf88786062c1ff7361c1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 10 Jun 2022 18:10:29 +0200 Subject: Update web instructions of the `tour` example --- examples/README.md | 5 ----- examples/tour/README.md | 9 +++++++-- 2 files changed, 7 insertions(+), 7 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/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/ -- cgit From aae880ca5d50b144abdae482a92cefbffcdf3a40 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Thu, 16 Jun 2022 12:26:03 -0700 Subject: Fix alpha blending for wgpu msaa --- examples/solar_system/src/main.rs | 8 ++++---- wgpu/src/triangle.rs | 13 +------------ wgpu/src/triangle/msaa.rs | 15 +++------------ 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 12184dd1..e96b53ff 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -48,6 +48,10 @@ impl Application for SolarSystem { String::from("Solar system - Iced") } + fn background_color(&self) -> Color { + Color::BLACK + } + fn update(&mut self, message: Message) -> Command { match message { Message::Tick(instant) => { @@ -137,16 +141,12 @@ impl canvas::Program 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/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index c702243b..bed64e99 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -162,18 +162,7 @@ impl Pipeline { entry_point: "fs_main", targets: &[wgpu::ColorTargetState { format, - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - }), + blend: Some(wgpu::BlendState::ALPHA_BLENDING), write_mask: wgpu::ColorWrites::ALL, }], }), diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 9fb87544..5d3ee311 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -95,18 +95,9 @@ impl Blit { entry_point: "fs_main", targets: &[wgpu::ColorTargetState { format, - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - }), + blend: Some( + wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING, + ), write_mask: wgpu::ColorWrites::ALL, }], }), -- cgit From a983c0c15b8d92e24adbeda45879260de50687fc Mon Sep 17 00:00:00 2001 From: Jhanny Jimenez Date: Wed, 22 Jun 2022 17:32:55 -0400 Subject: Added more clarification as to how the position and alignment of the Canvas Text structure interact --- graphics/src/widget/canvas/text.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/graphics/src/widget/canvas/text.rs b/graphics/src/widget/canvas/text.rs index ab070a70..056f8204 100644 --- a/graphics/src/widget/canvas/text.rs +++ b/graphics/src/widget/canvas/text.rs @@ -6,7 +6,14 @@ use crate::{Color, Font, Point}; pub struct Text { /// The contents of the text pub content: String, - /// The position where to begin drawing the text (top-left corner coordinates) + /// The position of the text relative to the alignment properties. + /// By default, this position will be relative to the top-left corner coordinate meaning that + /// if the horizontal and vertical alignments are unchanged, this property will tell where the + /// top-left corner of the text should be placed. + /// By changing the horizontal_alignment and vertical_alignment properties, you are are able to + /// change what part of text is placed at this positions. + /// For example, when the horizontal_alignment and vertical_alignment are set to Center, the + /// center of the text will be placed at the given position NOT the top-left coordinate. pub position: Point, /// The color of the text pub color: Color, -- cgit From 05e025b49f7f840241e3e2dcceb05b1e5fb7ad9a Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Thu, 23 Jun 2022 15:20:31 -0700 Subject: Allow overriding pure text_input value during draw --- pure/src/widget/text_input.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pure/src/widget/text_input.rs b/pure/src/widget/text_input.rs index 57ad26d9..ee790359 100644 --- a/pure/src/widget/text_input.rs +++ b/pure/src/widget/text_input.rs @@ -121,6 +121,32 @@ where self.style_sheet = style_sheet.into(); self } + + /// Draws the [`TextInput`] with the given [`Renderer`], overriding its + /// [`text_input::Value`] if provided. + /// + /// [`Renderer`]: text::Renderer + pub fn draw( + &self, + tree: &Tree, + renderer: &mut Renderer, + layout: Layout<'_>, + cursor_position: Point, + value: Option<&text_input::Value>, + ) { + text_input::draw( + renderer, + layout, + cursor_position, + tree.state.downcast_ref::(), + value.unwrap_or(&self.value), + &self.placeholder, + self.size, + &self.font, + self.is_secure, + self.style_sheet.as_ref(), + ) + } } impl<'a, Message, Renderer> Widget -- cgit From 9330a83775991539e2d0b395b1422072b4baec21 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Jul 2022 03:37:28 +0200 Subject: Fix `Widget::tag` implementation of `pure::Canvas` Using `P::State` can cause a panic if the `Canvas` has `()` as `P::State` and replaces a stateless widget in a future `view` call. --- graphics/src/widget/pure/canvas.rs | 3 ++- lazy/src/pure/component.rs | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/graphics/src/widget/pure/canvas.rs b/graphics/src/widget/pure/canvas.rs index 2e3e7ede..b51d5853 100644 --- a/graphics/src/widget/pure/canvas.rs +++ b/graphics/src/widget/pure/canvas.rs @@ -109,7 +109,8 @@ where B: Backend, { fn tag(&self) -> tree::Tag { - tree::Tag::of::() + struct Tag(T); + tree::Tag::of::>() } fn state(&self) -> tree::State { diff --git a/lazy/src/pure/component.rs b/lazy/src/pure/component.rs index b6e10054..8de40e8c 100644 --- a/lazy/src/pure/component.rs +++ b/lazy/src/pure/component.rs @@ -70,8 +70,6 @@ where }) } -struct Tag(T); - struct Instance<'a, Message, Renderer, Event, S> { state: RefCell>>, } @@ -132,6 +130,7 @@ where Renderer: iced_native::Renderer, { fn tag(&self) -> tree::Tag { + struct Tag(T); tree::Tag::of::>() } -- cgit From e6e3eff8762e9e8350f00b340348dc2261dd0053 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Jul 2022 04:02:38 +0200 Subject: Bump versions :tada: --- graphics/Cargo.toml | 2 +- lazy/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index e916975d..a27c5d7c 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_graphics" -version = "0.3.0" +version = "0.3.1" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "A bunch of backend-agnostic types that can be leveraged to build a renderer for Iced" diff --git a/lazy/Cargo.toml b/lazy/Cargo.toml index 7d439e47..9a184dd1 100644 --- a/lazy/Cargo.toml +++ b/lazy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_lazy" -version = "0.1.0" +version = "0.1.1" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "Lazy widgets for Iced" -- cgit From c148557cabf1fb9127b00b248479de2eb1d1d477 Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 15:39:42 +0800 Subject: update `wgpu` to `0.13` --- examples/integration_wgpu/src/main.rs | 18 +++----- examples/integration_wgpu/src/scene.rs | 12 +++--- examples/integration_wgpu/src/shader/frag.wgsl | 4 +- examples/integration_wgpu/src/shader/vert.wgsl | 4 +- wgpu/Cargo.toml | 6 +-- wgpu/src/image.rs | 22 +++++----- wgpu/src/quad.rs | 22 +++++----- wgpu/src/settings.rs | 2 +- wgpu/src/shader/blit.wgsl | 16 +++---- wgpu/src/shader/image.wgsl | 30 ++++++------- wgpu/src/shader/quad.wgsl | 44 +++++++++---------- wgpu/src/shader/triangle.wgsl | 18 ++++---- wgpu/src/triangle.rs | 18 ++++---- wgpu/src/triangle/msaa.rs | 10 ++--- wgpu/src/window/compositor.rs | 60 +++++++++++++------------- 15 files changed, 141 insertions(+), 145 deletions(-) diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 045ee0d3..7235e72b 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}, @@ -90,9 +89,7 @@ pub fn main() { let needed_limits = wgpu::Limits::default(); ( - surface - .get_preferred_format(&adapter) - .expect("Get preferred format"), + surface.get_supported_formats(&adapter)[0], adapter .request_device( &wgpu::DeviceDescriptor { @@ -114,15 +111,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); @@ -207,7 +203,7 @@ pub fn main() { format: format, width: size.width, height: size.height, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, }, ); @@ -262,12 +258,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 { +@fragment +fn main() -> @location(0) vec4 { return vec4(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 { +@vertex +fn main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4 { let x = f32(1 - i32(in_vertex_index)) * 0.5; let y = f32(1 - i32(in_vertex_index & 1u) * 2) * 0.5; return vec4(x, y, 0.0, 1.0); diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index a4378aa0..803f3e3b 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -28,8 +28,8 @@ spirv = ["wgpu/spirv"] webgl = ["wgpu/webgl"] [dependencies] -wgpu = "0.12" -wgpu_glyph = "0.16" +wgpu = "0.13" +wgpu_glyph = {version = "0.16",path = "../../wgpu_glyph"} glyph_brush = "0.7" raw-window-handle = "0.4" log = "0.4" @@ -39,7 +39,7 @@ kamadak-exif = "0.5" bitflags = "1.2" [dependencies.bytemuck] -version = "1.4" +version = "1.9" features = ["derive"] [dependencies.iced_native] diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 0fefbfaf..750ad62a 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -136,7 +136,7 @@ impl Pipeline { }); let shader = - device.create_shader_module(&wgpu::ShaderModuleDescriptor { + device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("iced_wgpu::image::shader"), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/image.wgsl"), @@ -176,7 +176,7 @@ impl Pipeline { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent { @@ -191,7 +191,7 @@ impl Pipeline { }, }), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, @@ -406,14 +406,16 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::image render pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { - view: target, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, - store: true, + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view: target, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Load, + store: true, + }, }, - }], + )], depth_stencil_attachment: None, }); diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 22f3b815..a117df64 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -59,7 +59,7 @@ impl Pipeline { }); let shader = - device.create_shader_module(&wgpu::ShaderModuleDescriptor { + device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("iced_wgpu::quad::shader"), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/quad.wgsl"), @@ -100,7 +100,7 @@ impl Pipeline { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent { @@ -115,7 +115,7 @@ impl Pipeline { }, }), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, @@ -211,14 +211,16 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::quad render pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { - view: target, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, - store: true, + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view: target, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Load, + store: true, + }, }, - }], + )], depth_stencil_attachment: None, }); diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 23b55904..7bc752ff 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -63,7 +63,7 @@ impl Settings { impl Default for Settings { fn default() -> Settings { Settings { - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, internal_backend: wgpu::Backends::all(), default_font: None, default_text_size: 20, diff --git a/wgpu/src/shader/blit.wgsl b/wgpu/src/shader/blit.wgsl index f8f6e2d4..5ff86f0a 100644 --- a/wgpu/src/shader/blit.wgsl +++ b/wgpu/src/shader/blit.wgsl @@ -16,19 +16,19 @@ var uvs: array, 6> = array, 6>( vec2(1.0, 1.0) ); -[[group(0), binding(0)]] var u_sampler: sampler; -[[group(1), binding(0)]] var u_texture: texture_2d; +@group(0) @binding(0) var u_sampler: sampler; +@group(1) @binding(0) var u_texture: texture_2d; struct VertexInput { - [[builtin(vertex_index)]] vertex_index: u32; + @builtin(vertex_index) vertex_index: u32, }; struct VertexOutput { - [[builtin(position)]] position: vec4; - [[location(0)]] uv: vec2; + @builtin(position) position: vec4, + @location(0) uv: vec2, }; -[[stage(vertex)]] +@vertex fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; out.uv = uvs[input.vertex_index]; @@ -37,7 +37,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { return out; } -[[stage(fragment)]] -fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { +@fragment +fn fs_main(input: VertexOutput) -> @location(0) vec4 { return textureSample(u_texture, u_sampler, input.uv); } diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index ff304422..bb1c6b9d 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -2,26 +2,26 @@ struct Globals { transform: mat4x4; }; -[[group(0), binding(0)]] var globals: Globals; -[[group(0), binding(1)]] var u_sampler: sampler; -[[group(1), binding(0)]] var u_texture: texture_2d_array; +@group(0) @binding(0) var globals: Globals; +@group(0) @binding(1) var u_sampler: sampler; +@group(1) @binding(0) var u_texture: texture_2d_array; struct VertexInput { - [[location(0)]] v_pos: vec2; - [[location(1)]] pos: vec2; - [[location(2)]] scale: vec2; - [[location(3)]] atlas_pos: vec2; - [[location(4)]] atlas_scale: vec2; - [[location(5)]] layer: i32; + @location(0) v_pos: vec2, + @location(1) pos: vec2, + @location(2) scale: vec2, + @location(3) atlas_pos: vec2, + @location(4) atlas_scale: vec2, + @location(5) layer: i32, }; struct VertexOutput { - [[builtin(position)]] position: vec4; - [[location(0)]] uv: vec2; - [[location(1)]] layer: f32; // this should be an i32, but naga currently reads that as requiring interpolation. + @builtin(position) position: vec4, + @location(0) uv: vec2, + @location(1) layer: f32, // this should be an i32, but naga currently reads that as requiring interpolation. }; -[[stage(vertex)]] +@vertex fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; @@ -40,7 +40,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { return out; } -[[stage(fragment)]] -fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { +@fragment +fn fs_main(input: VertexOutput) -> @location(0) vec4 { return textureSample(u_texture, u_sampler, input.uv, i32(input.layer)); } diff --git a/wgpu/src/shader/quad.wgsl b/wgpu/src/shader/quad.wgsl index 73f5d597..2e31cde3 100644 --- a/wgpu/src/shader/quad.wgsl +++ b/wgpu/src/shader/quad.wgsl @@ -1,31 +1,31 @@ struct Globals { - transform: mat4x4; - scale: f32; + transform: mat4x4, + scale: f32, }; -[[group(0), binding(0)]] var globals: Globals; +@group(0) @binding(0) var globals: Globals; struct VertexInput { - [[location(0)]] v_pos: vec2; - [[location(1)]] pos: vec2; - [[location(2)]] scale: vec2; - [[location(3)]] color: vec4; - [[location(4)]] border_color: vec4; - [[location(5)]] border_radius: f32; - [[location(6)]] border_width: f32; + @location(0) v_pos: vec2, + @location(1) pos: vec2, + @location(2) scale: vec2, + @location(3) color: vec4, + @location(4) border_color: vec4, + @location(5) border_radius: f32, + @location(6) border_width: f32, }; struct VertexOutput { - [[builtin(position)]] position: vec4; - [[location(0)]] color: vec4; - [[location(1)]] border_color: vec4; - [[location(2)]] pos: vec2; - [[location(3)]] scale: vec2; - [[location(4)]] border_radius: f32; - [[location(5)]] border_width: f32; + @builtin(position) position: vec4, + @location(0) color: vec4, + @location(1) border_color: vec4, + @location(2) pos: vec2, + @location(3) scale: vec2, + @location(4) border_radius: f32, + @location(5) border_width: f32, }; -[[stage(vertex)]] +@vertex fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; @@ -77,10 +77,10 @@ fn distance_alg( } -[[stage(fragment)]] +@fragment fn fs_main( input: VertexOutput -) -> [[location(0)]] vec4 { +) -> @location(0) vec4 { var mixed_color: vec4 = input.color; if (input.border_width > 0.0) { @@ -96,7 +96,7 @@ fn fs_main( internal_border ); - var border_mix: f32 = smoothStep( + var border_mix: f32 = smoothstep( max(internal_border - 0.5, 0.0), internal_border + 0.5, internal_distance @@ -112,7 +112,7 @@ fn fs_main( input.border_radius ); - var radius_alpha: f32 = 1.0 - smoothStep( + var radius_alpha: f32 = 1.0 - smoothstep( max(input.border_radius - 0.5, 0.0), input.border_radius + 0.5, dist); diff --git a/wgpu/src/shader/triangle.wgsl b/wgpu/src/shader/triangle.wgsl index 61d9c5a4..4348cffd 100644 --- a/wgpu/src/shader/triangle.wgsl +++ b/wgpu/src/shader/triangle.wgsl @@ -1,20 +1,20 @@ struct Globals { - transform: mat4x4; + transform: mat4x4, }; -[[group(0), binding(0)]] var globals: Globals; +@group(0) @binding(0) var globals: Globals; struct VertexInput { - [[location(0)]] position: vec2; - [[location(1)]] color: vec4; + @location(0) position: vec2, + @location(1) color: vec4, }; struct VertexOutput { - [[builtin(position)]] position: vec4; - [[location(0)]] color: vec4; + @builtin(position) position: vec4, + @location(0) color: vec4, }; -[[stage(vertex)]] +@vertex fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; @@ -24,7 +24,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { return out; } -[[stage(fragment)]] -fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { +@fragment +fn fs_main(input: VertexOutput) -> @location(0) vec4 { return input.color; } diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index bed64e99..40e2f855 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -132,7 +132,7 @@ impl Pipeline { }); let shader = - device.create_shader_module(&wgpu::ShaderModuleDescriptor { + device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("iced_wgpu::triangle::shader"), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/triangle.wgsl"), @@ -160,11 +160,11 @@ impl Pipeline { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format, blend: Some(wgpu::BlendState::ALPHA_BLENDING), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, @@ -350,11 +350,13 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::triangle render pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { - view: attachment, - resolve_target, - ops: wgpu::Operations { load, store: true }, - }], + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view: attachment, + resolve_target, + ops: wgpu::Operations { load, store: true }, + }, + )], depth_stencil_attachment: None, }); diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 5d3ee311..7edeeb94 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -74,7 +74,7 @@ impl Blit { }); let shader = - device.create_shader_module(&wgpu::ShaderModuleDescriptor { + device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("iced_wgpu::triangle::blit_shader"), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("../shader/blit.wgsl"), @@ -93,13 +93,13 @@ impl Blit { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format, blend: Some( wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING, ), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, @@ -169,14 +169,14 @@ impl Blit { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::triangle::msaa render pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { + color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: target, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, store: true, }, - }], + })], depth_stencil_attachment: None, }); diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index dde5f09f..c064a86c 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -1,7 +1,6 @@ use crate::{Backend, Color, Error, Renderer, Settings, Viewport}; use futures::stream::{self, StreamExt}; -use futures::task::SpawnExt; use iced_graphics::compositor; use iced_native::futures; @@ -16,7 +15,6 @@ pub struct Compositor { device: wgpu::Device, queue: wgpu::Queue, staging_belt: wgpu::util::StagingBelt, - local_pool: futures::executor::LocalPool, format: wgpu::TextureFormat, } @@ -61,9 +59,14 @@ impl Compositor { log::info!("Selected: {:#?}", adapter.get_info()); - let format = compatible_surface - .as_ref() - .and_then(|surface| surface.get_preferred_format(&adapter))?; + let format = compatible_surface.as_ref().and_then(|surface| { + let formats = surface.get_supported_formats(&adapter); + if formats.is_empty() { + None + } else { + Some(formats[0]) + } + })?; log::info!("Selected format: {:?}", format); @@ -98,7 +101,6 @@ impl Compositor { .await?; let staging_belt = wgpu::util::StagingBelt::new(Self::CHUNK_SIZE); - let local_pool = futures::executor::LocalPool::new(); Some(Compositor { instance, @@ -107,7 +109,6 @@ impl Compositor { device, queue, staging_belt, - local_pool, format, }) } @@ -200,24 +201,26 @@ impl iced_graphics::window::Compositor for Compositor { label: Some( "iced_wgpu::window::Compositor render pass", ), - color_attachments: &[wgpu::RenderPassColorAttachment { - view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear({ - let [r, g, b, a] = - background_color.into_linear(); - - wgpu::Color { - r: f64::from(r), - g: f64::from(g), - b: f64::from(b), - a: f64::from(a), - } - }), - store: true, + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear({ + let [r, g, b, a] = + background_color.into_linear(); + + wgpu::Color { + r: f64::from(r), + g: f64::from(g), + b: f64::from(b), + a: f64::from(a), + } + }), + store: true, + }, }, - }], + )], depth_stencil_attachment: None, }); @@ -235,16 +238,11 @@ impl iced_graphics::window::Compositor for Compositor { // Submit work self.staging_belt.finish(); - self.queue.submit(Some(encoder.finish())); + let _idx = self.queue.submit(Some(encoder.finish())); frame.present(); // Recall staging buffers - self.local_pool - .spawner() - .spawn(self.staging_belt.recall()) - .expect("Recall staging belt"); - - self.local_pool.run_until_stalled(); + self.staging_belt.recall(); Ok(()) } -- cgit From 095ac18c158c352c9ca4214d4f136d3c06882e6d Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 15:55:10 +0800 Subject: replace `path` to `git` --- wgpu/Cargo.toml | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 803f3e3b..ec10a4ea 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -1,35 +1,35 @@ [package] name = "iced_wgpu" version = "0.5.1" -authors = ["Héctor Ramón Jiménez "] +authors = [ "Héctor Ramón Jiménez " ] edition = "2021" description = "A wgpu renderer for Iced" license = "MIT AND OFL-1.1" repository = "https://github.com/iced-rs/iced" [features] -svg = ["resvg", "usvg", "tiny-skia"] -image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"] -png = ["image_rs/png"] -jpeg = ["image_rs/jpeg"] -jpeg_rayon = ["image_rs/jpeg_rayon"] -gif = ["image_rs/gif"] -webp = ["image_rs/webp"] -pnm = ["image_rs/pnm"] -ico = ["image_rs/ico"] -bmp = ["image_rs/bmp"] -hdr = ["image_rs/hdr"] -dds = ["image_rs/dds"] -farbfeld = ["image_rs/farbfeld"] -canvas = ["iced_graphics/canvas"] -qr_code = ["iced_graphics/qr_code"] -default_system_font = ["iced_graphics/font-source"] -spirv = ["wgpu/spirv"] -webgl = ["wgpu/webgl"] +svg = [ "resvg", "usvg", "tiny-skia" ] +image = [ "png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp" ] +png = [ "image_rs/png" ] +jpeg = [ "image_rs/jpeg" ] +jpeg_rayon = [ "image_rs/jpeg_rayon" ] +gif = [ "image_rs/gif" ] +webp = [ "image_rs/webp" ] +pnm = [ "image_rs/pnm" ] +ico = [ "image_rs/ico" ] +bmp = [ "image_rs/bmp" ] +hdr = [ "image_rs/hdr" ] +dds = [ "image_rs/dds" ] +farbfeld = [ "image_rs/farbfeld" ] +canvas = [ "iced_graphics/canvas" ] +qr_code = [ "iced_graphics/qr_code" ] +default_system_font = [ "iced_graphics/font-source" ] +spirv = [ "wgpu/spirv" ] +webgl = [ "wgpu/webgl" ] [dependencies] wgpu = "0.13" -wgpu_glyph = {version = "0.16",path = "../../wgpu_glyph"} +wgpu_glyph = { version = "0.16", git = "https://github.com/Cupnfish/wgpu_glyph.git", branch = "wgpu-0.13" } glyph_brush = "0.7" raw-window-handle = "0.4" log = "0.4" @@ -40,7 +40,7 @@ bitflags = "1.2" [dependencies.bytemuck] version = "1.9" -features = ["derive"] +features = [ "derive" ] [dependencies.iced_native] version = "0.5" @@ -49,7 +49,7 @@ path = "../native" [dependencies.iced_graphics] version = "0.3" path = "../graphics" -features = ["font-fallback", "font-icons"] +features = [ "font-fallback", "font-icons" ] [dependencies.image_rs] version = "0.23" @@ -70,5 +70,5 @@ version = "0.6" optional = true [package.metadata.docs.rs] -rustdoc-args = ["--cfg", "docsrs"] +rustdoc-args = [ "--cfg", "docsrs" ] all-features = true -- cgit From 64e37b26301eeab27b1089062bf24120306a3e86 Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 20:30:28 +0800 Subject: remove unnecessary `Cargo.toml` formatting --- wgpu/Cargo.toml | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index ec10a4ea..62fba54b 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -1,31 +1,31 @@ [package] name = "iced_wgpu" version = "0.5.1" -authors = [ "Héctor Ramón Jiménez " ] +authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "A wgpu renderer for Iced" license = "MIT AND OFL-1.1" repository = "https://github.com/iced-rs/iced" [features] -svg = [ "resvg", "usvg", "tiny-skia" ] -image = [ "png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp" ] -png = [ "image_rs/png" ] -jpeg = [ "image_rs/jpeg" ] -jpeg_rayon = [ "image_rs/jpeg_rayon" ] -gif = [ "image_rs/gif" ] -webp = [ "image_rs/webp" ] -pnm = [ "image_rs/pnm" ] -ico = [ "image_rs/ico" ] -bmp = [ "image_rs/bmp" ] -hdr = [ "image_rs/hdr" ] -dds = [ "image_rs/dds" ] -farbfeld = [ "image_rs/farbfeld" ] -canvas = [ "iced_graphics/canvas" ] -qr_code = [ "iced_graphics/qr_code" ] -default_system_font = [ "iced_graphics/font-source" ] -spirv = [ "wgpu/spirv" ] -webgl = [ "wgpu/webgl" ] +svg = ["resvg", "usvg", "tiny-skia"] +image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"] +png = ["image_rs/png"] +jpeg = ["image_rs/jpeg"] +jpeg_rayon = ["image_rs/jpeg_rayon"] +gif = ["image_rs/gif"] +webp = ["image_rs/webp"] +pnm = ["image_rs/pnm"] +ico = ["image_rs/ico"] +bmp = ["image_rs/bmp"] +hdr = ["image_rs/hdr"] +dds = ["image_rs/dds"] +farbfeld = ["image_rs/farbfeld"] +canvas = ["iced_graphics/canvas"] +qr_code = ["iced_graphics/qr_code"] +default_system_font = ["iced_graphics/font-source"] +spirv = ["wgpu/spirv"] +webgl = ["wgpu/webgl"] [dependencies] wgpu = "0.13" @@ -40,7 +40,7 @@ bitflags = "1.2" [dependencies.bytemuck] version = "1.9" -features = [ "derive" ] +features = ["derive"] [dependencies.iced_native] version = "0.5" @@ -49,7 +49,7 @@ path = "../native" [dependencies.iced_graphics] version = "0.3" path = "../graphics" -features = [ "font-fallback", "font-icons" ] +features = ["font-fallback", "font-icons"] [dependencies.image_rs] version = "0.23" @@ -70,5 +70,5 @@ version = "0.6" optional = true [package.metadata.docs.rs] -rustdoc-args = [ "--cfg", "docsrs" ] +rustdoc-args = ["--cfg", "docsrs"] all-features = true -- cgit From a88155b2a28bfcbe39c7b87d7e9befb73a7dc8d7 Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 22:29:49 +0800 Subject: fix `wgsl` syntax --- wgpu/src/shader/image.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index bb1c6b9d..773ef90a 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -1,5 +1,5 @@ struct Globals { - transform: mat4x4; + transform: mat4x4, }; @group(0) @binding(0) var globals: Globals; -- cgit From 390e2a2d34d610dec057a3b6679b795e8c2a5c94 Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 22:51:51 +0800 Subject: better `wgsl` code style --- wgpu/src/shader/blit.wgsl | 4 ++-- wgpu/src/shader/image.wgsl | 6 +++--- wgpu/src/shader/quad.wgsl | 6 +++--- wgpu/src/shader/triangle.wgsl | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/wgpu/src/shader/blit.wgsl b/wgpu/src/shader/blit.wgsl index 5ff86f0a..c2ea223f 100644 --- a/wgpu/src/shader/blit.wgsl +++ b/wgpu/src/shader/blit.wgsl @@ -21,12 +21,12 @@ var uvs: array, 6> = array, 6>( struct VertexInput { @builtin(vertex_index) vertex_index: u32, -}; +} struct VertexOutput { @builtin(position) position: vec4, @location(0) uv: vec2, -}; +} @vertex fn vs_main(input: VertexInput) -> VertexOutput { diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index 773ef90a..5e22cdf4 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -1,6 +1,6 @@ struct Globals { transform: mat4x4, -}; +} @group(0) @binding(0) var globals: Globals; @group(0) @binding(1) var u_sampler: sampler; @@ -13,13 +13,13 @@ struct VertexInput { @location(3) atlas_pos: vec2, @location(4) atlas_scale: vec2, @location(5) layer: i32, -}; +} struct VertexOutput { @builtin(position) position: vec4, @location(0) uv: vec2, @location(1) layer: f32, // this should be an i32, but naga currently reads that as requiring interpolation. -}; +} @vertex fn vs_main(input: VertexInput) -> VertexOutput { diff --git a/wgpu/src/shader/quad.wgsl b/wgpu/src/shader/quad.wgsl index 2e31cde3..73edd97c 100644 --- a/wgpu/src/shader/quad.wgsl +++ b/wgpu/src/shader/quad.wgsl @@ -1,7 +1,7 @@ struct Globals { transform: mat4x4, scale: f32, -}; +} @group(0) @binding(0) var globals: Globals; @@ -13,7 +13,7 @@ struct VertexInput { @location(4) border_color: vec4, @location(5) border_radius: f32, @location(6) border_width: f32, -}; +} struct VertexOutput { @builtin(position) position: vec4, @@ -23,7 +23,7 @@ struct VertexOutput { @location(3) scale: vec2, @location(4) border_radius: f32, @location(5) border_width: f32, -}; +} @vertex fn vs_main(input: VertexInput) -> VertexOutput { diff --git a/wgpu/src/shader/triangle.wgsl b/wgpu/src/shader/triangle.wgsl index 4348cffd..b24402f8 100644 --- a/wgpu/src/shader/triangle.wgsl +++ b/wgpu/src/shader/triangle.wgsl @@ -1,18 +1,18 @@ struct Globals { transform: mat4x4, -}; +} @group(0) @binding(0) var globals: Globals; struct VertexInput { @location(0) position: vec2, @location(1) color: vec4, -}; +} struct VertexOutput { @builtin(position) position: vec4, @location(0) color: vec4, -}; +} @vertex fn vs_main(input: VertexInput) -> VertexOutput { -- cgit From 8b250d12e70f13240efd0f56828d06ab8ef78071 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 3 Jul 2022 15:24:16 +0200 Subject: Use latest `wgpu_glyph` release on crates.io --- wgpu/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 62fba54b..586f97d3 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -29,7 +29,7 @@ webgl = ["wgpu/webgl"] [dependencies] wgpu = "0.13" -wgpu_glyph = { version = "0.16", git = "https://github.com/Cupnfish/wgpu_glyph.git", branch = "wgpu-0.13" } +wgpu_glyph = "0.17" glyph_brush = "0.7" raw-window-handle = "0.4" log = "0.4" -- cgit From 2010977bd20fe5f562e0389f24c5aa284d89e25c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 3 Jul 2022 15:27:23 +0200 Subject: Use `expect` in `integration_wgpu` example ... together with `first` and `copied`. --- examples/integration_wgpu/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 7235e72b..89ae03c6 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -89,7 +89,11 @@ pub fn main() { let needed_limits = wgpu::Limits::default(); ( - surface.get_supported_formats(&adapter)[0], + surface + .get_supported_formats(&adapter) + .first() + .copied() + .expect("Get preferred format"), adapter .request_device( &wgpu::DeviceDescriptor { -- cgit From 3d38d0af91ce4a1165928cf933c1e40dc80983ae Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 3 Jul 2022 15:30:04 +0200 Subject: Simplify format selection in `iced_wgpu` --- wgpu/src/window/compositor.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index c064a86c..cff7104d 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -60,12 +60,7 @@ impl Compositor { log::info!("Selected: {:#?}", adapter.get_info()); let format = compatible_surface.as_ref().and_then(|surface| { - let formats = surface.get_supported_formats(&adapter); - if formats.is_empty() { - None - } else { - Some(formats[0]) - } + surface.get_supported_formats(&adapter).first().copied() })?; log::info!("Selected format: {:?}", format); -- cgit From 9adc20922d16b990eede1f6c5f059e68efe15d0e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 3 Jul 2022 15:48:32 +0200 Subject: Replace name abbreviation in `iced_wgpu` --- wgpu/src/window/compositor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index cff7104d..91884ec4 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -233,7 +233,7 @@ impl iced_graphics::window::Compositor for Compositor { // Submit work self.staging_belt.finish(); - let _idx = self.queue.submit(Some(encoder.finish())); + let _submission = self.queue.submit(Some(encoder.finish())); frame.present(); // Recall staging buffers -- cgit