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/tour/src/main.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'examples/tour') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index f5791ad7..c373502e 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -4,7 +4,7 @@ use iced::widget::{ scrollable, slider, text, text_input, toggler, vertical_space, }; use iced::widget::{Button, Column, Container, Slider}; -use iced::{Color, Element, Font, Length, Pixels, Sandbox, Settings}; +use iced::{Color, Element, Font, Length, Pixels}; pub fn main() -> iced::Result { #[cfg(target_arch = "wasm32")] @@ -16,7 +16,10 @@ pub fn main() -> iced::Result { #[cfg(not(target_arch = "wasm32"))] tracing_subscriber::fmt::init(); - Tour::run(Settings::default()) + iced::sandbox(Tour::update, Tour::view) + .title(Tour::title) + .centered() + .run() } pub struct Tour { @@ -24,11 +27,9 @@ pub struct Tour { debug: bool, } -impl Sandbox for Tour { - type Message = Message; - - fn new() -> Tour { - Tour { +impl Tour { + fn new() -> Self { + Self { steps: Steps::new(), debug: false, } @@ -90,6 +91,12 @@ impl Sandbox for Tour { } } +impl Default for Tour { + fn default() -> Self { + Self::new() + } +} + #[derive(Debug, Clone)] pub enum Message { BackPressed, -- 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/tour/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/tour') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index c373502e..23c4040d 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -16,8 +16,7 @@ pub fn main() -> iced::Result { #[cfg(not(target_arch = "wasm32"))] tracing_subscriber::fmt::init(); - iced::sandbox(Tour::update, Tour::view) - .title(Tour::title) + iced::sandbox(Tour::title, Tour::update, Tour::view) .centered() .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/tour/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/tour') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 23c4040d..97ce761c 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -16,7 +16,7 @@ pub fn main() -> iced::Result { #[cfg(not(target_arch = "wasm32"))] tracing_subscriber::fmt::init(); - iced::sandbox(Tour::title, Tour::update, Tour::view) + iced::application(Tour::title, Tour::update, Tour::view) .centered() .run() } -- 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/tour/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/tour') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 97ce761c..be6e24d5 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -16,7 +16,7 @@ pub fn main() -> iced::Result { #[cfg(not(target_arch = "wasm32"))] tracing_subscriber::fmt::init(); - iced::application(Tour::title, Tour::update, Tour::view) + iced::program(Tour::title, Tour::update, Tour::view) .centered() .run() } -- cgit From 943b6c965773748f8cacaa4fe385ac4a3bfb1e69 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 17 Mar 2024 19:15:31 +0100 Subject: Introduce `Program::run_with` to control the initial state --- examples/tour/src/main.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'examples/tour') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index be6e24d5..a88c0dba 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -21,19 +21,13 @@ pub fn main() -> iced::Result { .run() } +#[derive(Default)] pub struct Tour { steps: Steps, debug: bool, } impl Tour { - fn new() -> Self { - Self { - steps: Steps::new(), - debug: false, - } - } - fn title(&self) -> String { format!("{} - Iced", self.steps.title()) } @@ -90,12 +84,6 @@ impl Tour { } } -impl Default for Tour { - fn default() -> Self { - Self::new() - } -} - #[derive(Debug, Clone)] pub enum Message { BackPressed, @@ -177,6 +165,12 @@ impl Steps { } } +impl Default for Steps { + fn default() -> Self { + Steps::new() + } +} + enum Step { Welcome, Slider { -- cgit