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/system_information/src/main.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'examples/system_information/src') diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs index 31dc92f1..079c2c46 100644 --- a/examples/system_information/src/main.rs +++ b/examples/system_information/src/main.rs @@ -1,12 +1,12 @@ use iced::widget::{button, column, container, text}; -use iced::{ - executor, system, Application, Command, Element, Length, Settings, Theme, -}; +use iced::{system, Command, Element, Length}; use bytesize::ByteSize; pub fn main() -> iced::Result { - Example::run(Settings::default()) + iced::application(Example::new, Example::update, Example::view) + .title("System Information - Iced") + .run() } #[allow(clippy::large_enum_variant)] @@ -22,23 +22,14 @@ enum Message { Refresh, } -impl Application for Example { - type Message = Message; - type Theme = Theme; - type Executor = executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (Self, Command) { +impl Example { + fn new() -> (Self, Command) { ( Self::Loading, system::fetch_information(Message::InformationReceived), ) } - fn title(&self) -> String { - String::from("System Information - Iced") - } - fn update(&mut self, message: Message) -> Command { match message { Message::Refresh => { -- cgit From 93ae790da14544667176ecdbdd6a4eaaa98a248a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 15:53:03 +0100 Subject: Implement `Program::load` to specify startup `Command` --- examples/system_information/src/main.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'examples/system_information/src') diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs index 079c2c46..75a4d8d6 100644 --- a/examples/system_information/src/main.rs +++ b/examples/system_information/src/main.rs @@ -1,18 +1,23 @@ use iced::widget::{button, column, container, text}; use iced::{system, Command, Element, Length}; -use bytesize::ByteSize; - pub fn main() -> iced::Result { - iced::application(Example::new, Example::update, Example::view) - .title("System Information - Iced") - .run() + iced::application( + "System Information - Iced", + Example::update, + Example::view, + ) + .run() } +#[derive(Default)] #[allow(clippy::large_enum_variant)] enum Example { + #[default] Loading, - Loaded { information: system::Information }, + Loaded { + information: system::Information, + }, } #[derive(Clone, Debug)] @@ -23,13 +28,6 @@ enum Message { } impl Example { - fn new() -> (Self, Command) { - ( - Self::Loading, - system::fetch_information(Message::InformationReceived), - ) - } - fn update(&mut self, message: Message) -> Command { match message { Message::Refresh => { @@ -46,6 +44,8 @@ impl Example { } fn view(&self) -> Element { + use bytesize::ByteSize; + let content: Element<_> = match self { Example::Loading => text("Loading...").size(40).into(), Example::Loaded { information } => { -- 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/system_information/src/main.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'examples/system_information/src') diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs index 75a4d8d6..a6ac27a6 100644 --- a/examples/system_information/src/main.rs +++ b/examples/system_information/src/main.rs @@ -2,12 +2,8 @@ use iced::widget::{button, column, container, text}; use iced::{system, Command, Element, Length}; pub fn main() -> iced::Result { - iced::application( - "System Information - Iced", - Example::update, - Example::view, - ) - .run() + iced::program("System Information - Iced", Example::update, Example::view) + .run() } #[derive(Default)] -- cgit