From 1d83e59e8ab51d403baee0daa878644c6a37be3f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 1 Apr 2024 21:36:08 +0200 Subject: Specialize `widget::text` helper with custom `IntoContent` trait --- examples/lazy/src/main.rs | 2 +- examples/tour/src/main.rs | 6 +++--- examples/websocket/src/main.rs | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/lazy/src/main.rs b/examples/lazy/src/main.rs index 2d53df93..c3f6b8de 100644 --- a/examples/lazy/src/main.rs +++ b/examples/lazy/src/main.rs @@ -173,7 +173,7 @@ impl App { .style(button::danger); row![ - text(&item.name).color(item.color), + text(item.name.clone()).color(item.color), horizontal_space(), pick_list(Color::ALL, Some(item.color), move |color| { Message::ItemColorChanged(item.clone(), color) diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index a88c0dba..e3a2ca87 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -357,7 +357,7 @@ impl<'a> Step { .into() } - fn container(title: &str) -> Column<'a, StepMessage> { + fn container(title: &str) -> Column<'_, StepMessage> { column![text(title).size(50)].spacing(20) } @@ -589,7 +589,7 @@ impl<'a> Step { value: &str, is_secure: bool, is_showing_icon: bool, - ) -> Column<'a, StepMessage> { + ) -> Column<'_, StepMessage> { let mut text_input = text_input("Type something to continue...", value) .on_input(StepMessage::InputChanged) .padding(10) @@ -674,7 +674,7 @@ fn ferris<'a>( .center_x() } -fn padded_button<'a, Message: Clone>(label: &str) -> Button<'a, Message> { +fn padded_button(label: &str) -> Button<'_, Message> { button(text(label)).padding([12, 24]) } diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs index 460d9a08..ef450524 100644 --- a/examples/websocket/src/main.rs +++ b/examples/websocket/src/main.rs @@ -97,7 +97,11 @@ impl WebSocket { } else { scrollable( column( - self.messages.iter().cloned().map(text).map(Element::from), + self.messages + .iter() + .map(ToString::to_string) + .map(text) + .map(Element::from), ) .spacing(10), ) -- cgit From b8d5df28172a9f50c8b48123df05a336801f2bdc Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 1 Apr 2024 21:36:52 +0200 Subject: Reintroduce old `text` helper as `value` helper --- examples/websocket/src/main.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs index ef450524..369ae820 100644 --- a/examples/websocket/src/main.rs +++ b/examples/websocket/src/main.rs @@ -2,7 +2,7 @@ mod echo; use iced::alignment::{self, Alignment}; use iced::widget::{ - button, column, container, row, scrollable, text, text_input, + button, column, container, row, scrollable, text, text_input, value, }; use iced::{color, Command, Element, Length, Subscription}; use once_cell::sync::Lazy; @@ -96,14 +96,8 @@ impl WebSocket { .into() } else { scrollable( - column( - self.messages - .iter() - .map(ToString::to_string) - .map(text) - .map(Element::from), - ) - .spacing(10), + column(self.messages.iter().map(value).map(Element::from)) + .spacing(10), ) .id(MESSAGE_LOG.clone()) .height(Length::Fill) -- cgit From 488cac714896002791f3c7b9a99181310c1d1b5c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 2 Apr 2024 09:29:16 +0200 Subject: Avoid extra text allocations in `websocket` example --- examples/websocket/src/echo.rs | 23 ++++++++++++++++------- examples/websocket/src/main.rs | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/websocket/src/echo.rs b/examples/websocket/src/echo.rs index 281ed4bd..cd32cb66 100644 --- a/examples/websocket/src/echo.rs +++ b/examples/websocket/src/echo.rs @@ -2,6 +2,7 @@ pub mod server; use iced::futures; use iced::subscription::{self, Subscription}; +use iced::widget::text; use futures::channel::mpsc; use futures::sink::SinkExt; @@ -136,16 +137,24 @@ impl Message { pub fn disconnected() -> Self { Message::Disconnected } + + pub fn as_str(&self) -> &str { + match self { + Message::Connected => "Connected successfully!", + Message::Disconnected => "Connection lost... Retrying...", + Message::User(message) => message.as_str(), + } + } } impl fmt::Display for Message { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Message::Connected => write!(f, "Connected successfully!"), - Message::Disconnected => { - write!(f, "Connection lost... Retrying...") - } - Message::User(message) => write!(f, "{message}"), - } + f.write_str(self.as_str()) + } +} + +impl<'a> text::IntoFragment<'a> for &'a Message { + fn into_fragment(self) -> text::Fragment<'a> { + text::Fragment::Borrowed(self.as_str()) } } diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs index 369ae820..b479fe89 100644 --- a/examples/websocket/src/main.rs +++ b/examples/websocket/src/main.rs @@ -2,7 +2,7 @@ mod echo; use iced::alignment::{self, Alignment}; use iced::widget::{ - button, column, container, row, scrollable, text, text_input, value, + button, column, container, row, scrollable, text, text_input, }; use iced::{color, Command, Element, Length, Subscription}; use once_cell::sync::Lazy; @@ -96,7 +96,7 @@ impl WebSocket { .into() } else { scrollable( - column(self.messages.iter().map(value).map(Element::from)) + column(self.messages.iter().map(text).map(Element::from)) .spacing(10), ) .id(MESSAGE_LOG.clone()) -- cgit From b05e61f5c8ae61c9f3c7cc08cded53901ebbccfd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 3 Apr 2024 21:07:54 +0200 Subject: Redesign `iced_wgpu` layering architecture --- examples/geometry/src/main.rs | 6 +++++- examples/integration/src/main.rs | 35 +++++++++++++++-------------------- 2 files changed, 20 insertions(+), 21 deletions(-) (limited to 'examples') diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index 16cdb86f..9532a24a 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -6,7 +6,10 @@ mod rainbow { use iced::advanced::renderer; use iced::advanced::widget::{self, Widget}; use iced::mouse; - use iced::{Element, Length, Rectangle, Renderer, Size, Theme, Vector}; + use iced::{ + Element, Length, Rectangle, Renderer, Size, Theme, Transformation, + Vector, + }; #[derive(Debug, Clone, Copy, Default)] pub struct Rainbow; @@ -130,6 +133,7 @@ mod rainbow { 0, 8, 1, // L ], }, + transformation: Transformation::IDENTITY, }; renderer.with_translation( diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 9cd801b2..c292709f 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -5,12 +5,12 @@ use controls::Controls; use scene::Scene; use iced_wgpu::graphics::Viewport; -use iced_wgpu::{wgpu, Backend, Renderer, Settings}; +use iced_wgpu::{wgpu, Engine, Renderer, Settings}; use iced_winit::conversion; use iced_winit::core::mouse; use iced_winit::core::renderer; use iced_winit::core::window; -use iced_winit::core::{Color, Font, Pixels, Size, Theme}; +use iced_winit::core::{Color, Size, Theme}; use iced_winit::futures; use iced_winit::runtime::program; use iced_winit::runtime::Debug; @@ -155,11 +155,8 @@ pub fn main() -> Result<(), Box> { // Initialize iced let mut debug = Debug::new(); - let mut renderer = Renderer::new( - Backend::new(&adapter, &device, &queue, Settings::default(), format), - Font::default(), - Pixels(16.0), - ); + let mut engine = Engine::new(&adapter, &device, &queue, format, None); + let mut renderer = Renderer::new(Settings::default(), &engine); let mut state = program::State::new( controls, @@ -228,19 +225,17 @@ pub fn main() -> Result<(), Box> { } // And then iced on top - renderer.with_primitives(|backend, primitive| { - backend.present( - &device, - &queue, - &mut encoder, - None, - frame.texture.format(), - &view, - primitive, - &viewport, - &debug.overlay(), - ); - }); + renderer.present( + &mut engine, + &device, + &queue, + &mut encoder, + None, + frame.texture.format(), + &view, + &viewport, + &debug.overlay(), + ); // Then we submit the work queue.submit(Some(encoder.finish())); -- cgit From 6d3e1d835e1688fbc58622a03a784ed25ed3f0e1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 5 Apr 2024 23:59:21 +0200 Subject: Decouple caching from layering and simplify everything --- examples/geometry/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index 9532a24a..31b8a4ce 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -82,7 +82,6 @@ mod rainbow { let posn_l = [0.0, bounds.height / 2.0]; let mesh = Mesh::Solid { - size: bounds.size(), buffers: mesh::Indexed { vertices: vec![ SolidVertex2D { @@ -134,6 +133,7 @@ mod rainbow { ], }, transformation: Transformation::IDENTITY, + clip_bounds: Rectangle::INFINITE, }; renderer.with_translation( -- cgit From d922b478156488a7bc03c6e791e05c040d702634 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 8 Apr 2024 15:04:35 +0200 Subject: Reintroduce support for custom primitives in `iced_wgpu` --- examples/custom_shader/src/scene.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'examples') diff --git a/examples/custom_shader/src/scene.rs b/examples/custom_shader/src/scene.rs index a35efdd9..5fa42188 100644 --- a/examples/custom_shader/src/scene.rs +++ b/examples/custom_shader/src/scene.rs @@ -9,8 +9,8 @@ use pipeline::cube::{self, Cube}; use iced::mouse; use iced::time::Duration; -use iced::widget::shader; -use iced::{Color, Rectangle, Size}; +use iced::widget::shader::{self, Viewport}; +use iced::{Color, Rectangle}; use glam::Vec3; use rand::Rng; @@ -130,25 +130,29 @@ impl Primitive { impl shader::Primitive for Primitive { fn prepare( &self, - format: wgpu::TextureFormat, device: &wgpu::Device, queue: &wgpu::Queue, - _bounds: Rectangle, - target_size: Size, - _scale_factor: f32, + format: wgpu::TextureFormat, storage: &mut shader::Storage, + _bounds: &Rectangle, + viewport: &Viewport, ) { if !storage.has::() { - storage.store(Pipeline::new(device, queue, format, target_size)); + storage.store(Pipeline::new( + device, + queue, + format, + viewport.physical_size(), + )); } let pipeline = storage.get_mut::().unwrap(); - //upload data to GPU + // Upload data to GPU pipeline.update( device, queue, - target_size, + viewport.physical_size(), &self.uniforms, self.cubes.len(), &self.cubes, @@ -157,20 +161,19 @@ impl shader::Primitive for Primitive { fn render( &self, + encoder: &mut wgpu::CommandEncoder, storage: &shader::Storage, target: &wgpu::TextureView, - _target_size: Size, - viewport: Rectangle, - encoder: &mut wgpu::CommandEncoder, + clip_bounds: &Rectangle, ) { - //at this point our pipeline should always be initialized + // At this point our pipeline should always be initialized let pipeline = storage.get::().unwrap(); - //render primitive + // Render primitive pipeline.render( target, encoder, - viewport, + *clip_bounds, self.cubes.len() as u32, self.show_depth_buffer, ); -- cgit From 2c6fd9ac14c5d270e05b97b7a7fab811d25834c4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 8 Apr 2024 15:35:54 +0200 Subject: Make arguments of `Renderer::new` explicit in `iced_wgpu` --- examples/integration/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index c292709f..c4b57ecf 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -5,12 +5,12 @@ use controls::Controls; use scene::Scene; use iced_wgpu::graphics::Viewport; -use iced_wgpu::{wgpu, Engine, Renderer, Settings}; +use iced_wgpu::{wgpu, Engine, Renderer}; use iced_winit::conversion; use iced_winit::core::mouse; use iced_winit::core::renderer; use iced_winit::core::window; -use iced_winit::core::{Color, Size, Theme}; +use iced_winit::core::{Color, Font, Pixels, Size, Theme}; use iced_winit::futures; use iced_winit::runtime::program; use iced_winit::runtime::Debug; @@ -156,7 +156,8 @@ pub fn main() -> Result<(), Box> { // Initialize iced let mut debug = Debug::new(); let mut engine = Engine::new(&adapter, &device, &queue, format, None); - let mut renderer = Renderer::new(Settings::default(), &engine); + let mut renderer = + Renderer::new(&engine, Font::default(), Pixels::from(16)); let mut state = program::State::new( controls, -- cgit From 9cbad0a352fcf12c5352e37bc15c0d20be6f89d7 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:37:37 +0100 Subject: Remove extra Download struct from dowload_progress example --- examples/download_progress/src/download.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'examples') diff --git a/examples/download_progress/src/download.rs b/examples/download_progress/src/download.rs index 3b11cb76..d6cc1e24 100644 --- a/examples/download_progress/src/download.rs +++ b/examples/download_progress/src/download.rs @@ -12,12 +12,6 @@ pub fn file( }) } -#[derive(Debug, Hash, Clone)] -pub struct Download { - id: I, - url: String, -} - async fn download(id: I, state: State) -> ((I, Progress), State) { match state { State::Ready(url) => { -- cgit