From c22269bff3085012d326a0df77bf27ad5bcb41b7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 05:33:47 +0100 Subject: Introduce `Program` API --- examples/custom_shader/src/main.rs | 49 ++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'examples/custom_shader/src') diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index 9e8da3ba..5ba9a5d4 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -2,18 +2,17 @@ mod scene; use scene::Scene; -use iced::executor; use iced::time::Instant; use iced::widget::shader::wgpu; use iced::widget::{checkbox, column, container, row, shader, slider, text}; use iced::window; -use iced::{ - Alignment, Application, Color, Command, Element, Length, Subscription, - Theme, -}; +use iced::{Alignment, Color, Element, Length, Subscription}; fn main() -> iced::Result { - IcedCubes::run(iced::Settings::default()) + iced::sandbox(IcedCubes::update, IcedCubes::view) + .subscription(IcedCubes::subscription) + .title("Custom Shader - Iced") + .run() } struct IcedCubes { @@ -30,27 +29,15 @@ enum Message { LightColorChanged(Color), } -impl Application for IcedCubes { - type Executor = executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: Self::Flags) -> (Self, Command) { - ( - Self { - start: Instant::now(), - scene: Scene::new(), - }, - Command::none(), - ) - } - - fn title(&self) -> String { - "Iced Cubes".to_string() +impl IcedCubes { + fn new() -> Self { + Self { + start: Instant::now(), + scene: Scene::new(), + } } - fn update(&mut self, message: Self::Message) -> Command { + fn update(&mut self, message: Message) { match message { Message::CubeAmountChanged(amount) => { self.scene.change_amount(amount); @@ -68,11 +55,9 @@ impl Application for IcedCubes { self.scene.light_color = color; } } - - Command::none() } - fn view(&self) -> Element<'_, Self::Message> { + fn view(&self) -> Element<'_, Message> { let top_controls = row![ control( "Amount", @@ -147,11 +132,17 @@ impl Application for IcedCubes { .into() } - fn subscription(&self) -> Subscription { + fn subscription(&self) -> Subscription { window::frames().map(Message::Tick) } } +impl Default for IcedCubes { + fn default() -> Self { + Self::new() + } +} + fn control<'a>( label: &'static str, control: impl Into>, -- cgit From bb71e8481ed59f991b9bd9dc55ea7e011ba0aac6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 16:12:07 +0100 Subject: Make `sandbox` helper take a `title` as well --- examples/custom_shader/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/custom_shader/src') diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index 5ba9a5d4..341b77b6 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -9,9 +9,8 @@ use iced::window; use iced::{Alignment, Color, Element, Length, Subscription}; fn main() -> iced::Result { - iced::sandbox(IcedCubes::update, IcedCubes::view) + iced::sandbox("Custom Shader - Iced", IcedCubes::update, IcedCubes::view) .subscription(IcedCubes::subscription) - .title("Custom Shader - Iced") .run() } -- cgit From 28a27f08edccd53e06ad693e63b0a62dae921da5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 19:14:13 +0100 Subject: Remove `sandbox` by making `application` more generic :tada: --- examples/custom_shader/src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'examples/custom_shader/src') diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index 341b77b6..4457a15a 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -9,9 +9,13 @@ use iced::window; use iced::{Alignment, Color, Element, Length, Subscription}; fn main() -> iced::Result { - iced::sandbox("Custom Shader - Iced", IcedCubes::update, IcedCubes::view) - .subscription(IcedCubes::subscription) - .run() + iced::application( + "Custom Shader - Iced", + IcedCubes::update, + IcedCubes::view, + ) + .subscription(IcedCubes::subscription) + .run() } struct IcedCubes { -- cgit From 54f44754eb216d4b2c08cd2a7c3582f1dc295205 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 17 Mar 2024 14:16:38 +0100 Subject: Move `Program` to `application` module --- examples/custom_shader/src/main.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'examples/custom_shader/src') diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index 4457a15a..aa3dafe9 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -9,13 +9,9 @@ use iced::window; use iced::{Alignment, Color, Element, Length, Subscription}; fn main() -> iced::Result { - iced::application( - "Custom Shader - Iced", - IcedCubes::update, - IcedCubes::view, - ) - .subscription(IcedCubes::subscription) - .run() + iced::program("Custom Shader - Iced", IcedCubes::update, IcedCubes::view) + .subscription(IcedCubes::subscription) + .run() } struct IcedCubes { -- cgit