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/screenshot/src/main.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'examples/screenshot') diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index 2a1eded7..3f955228 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -1,12 +1,10 @@ use iced::alignment; -use iced::executor; use iced::keyboard; use iced::widget::{button, column, container, image, row, text, text_input}; use iced::window; use iced::window::screenshot::{self, Screenshot}; use iced::{ - Alignment, Application, Command, ContentFit, Element, Length, Rectangle, - Subscription, Theme, + Alignment, Command, ContentFit, Element, Length, Rectangle, Subscription, }; use ::image as img; @@ -15,7 +13,10 @@ use ::image::ColorType; fn main() -> iced::Result { tracing_subscriber::fmt::init(); - Example::run(iced::Settings::default()) + iced::application(Example::new, Example::update, Example::view) + .subscription(Example::subscription) + .title("Screenshot - Iced") + .run() } struct Example { @@ -42,13 +43,8 @@ enum Message { HeightInputChanged(Option), } -impl Application for Example { - type Executor = executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: Self::Flags) -> (Self, Command) { +impl Example { + fn new() -> (Self, Command) { ( Example { screenshot: None, @@ -64,11 +60,7 @@ impl Application for Example { ) } - fn title(&self) -> String { - "Screenshot".to_string() - } - - fn update(&mut self, message: Self::Message) -> Command { + fn update(&mut self, message: Message) -> Command { match message { Message::Screenshot => { return iced::window::screenshot( @@ -130,7 +122,7 @@ impl Application for Example { Command::none() } - fn view(&self) -> Element<'_, Self::Message> { + fn view(&self) -> Element<'_, Message> { let image: Element = if let Some(screenshot) = &self.screenshot { image(image::Handle::from_pixels( @@ -259,7 +251,7 @@ impl Application for Example { .into() } - fn subscription(&self) -> Subscription { + fn subscription(&self) -> Subscription { use keyboard::key; keyboard::on_key_press(|key, _modifiers| { -- cgit