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/layout/src/main.rs | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'examples/layout') diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index 17c51e3d..fc3a1f82 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -1,4 +1,3 @@ -use iced::executor; use iced::keyboard; use iced::mouse; use iced::widget::{ @@ -6,15 +5,19 @@ use iced::widget::{ row, scrollable, text, }; use iced::{ - color, Alignment, Application, Command, Element, Font, Length, Point, - Rectangle, Renderer, Settings, Subscription, Theme, + color, Alignment, Element, Font, Length, Point, Rectangle, Renderer, + Subscription, Theme, }; pub fn main() -> iced::Result { - Layout::run(Settings::default()) + iced::sandbox(Layout::update, Layout::view) + .title(Layout::title) + .subscription(Layout::subscription) + .theme(Layout::theme) + .run() } -#[derive(Debug)] +#[derive(Default, Debug)] struct Layout { example: Example, explain: bool, @@ -29,28 +32,12 @@ enum Message { ThemeSelected(Theme), } -impl Application for Layout { - type Message = Message; - type Theme = Theme; - type Executor = executor::Default; - type Flags = (); - - fn new(_flags: Self::Flags) -> (Self, Command) { - ( - Self { - example: Example::default(), - explain: false, - theme: Theme::Light, - }, - Command::none(), - ) - } - +impl Layout { fn title(&self) -> String { format!("{} - Layout - Iced", self.example.title) } - fn update(&mut self, message: Self::Message) -> Command { + fn update(&mut self, message: Message) { match message { Message::Next => { self.example = self.example.next(); @@ -65,8 +52,6 @@ impl Application for Layout { self.theme = theme; } } - - Command::none() } fn subscription(&self) -> Subscription { -- 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/layout/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/layout') diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index fc3a1f82..371f2ae2 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -10,8 +10,7 @@ use iced::{ }; pub fn main() -> iced::Result { - iced::sandbox(Layout::update, Layout::view) - .title(Layout::title) + iced::sandbox(Layout::title, Layout::update, Layout::view) .subscription(Layout::subscription) .theme(Layout::theme) .run() -- cgit