summaryrefslogtreecommitdiffstats
path: root/examples/system_information/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-03-16 17:09:00 +0100
committerLibravatar GitHub <noreply@github.com>2024-03-16 17:09:00 +0100
commit503a48e89977437bf8b7bf485f416a15a2e83ed0 (patch)
tree30306bbaee7a31090ace9d7725d46c2c0027fe6b /examples/system_information/src
parent0524e9b4571d264018656418f02a1f9e27e268d7 (diff)
parentcfc0383bbfff083786840e3f1fd499e5991fa629 (diff)
downloadiced-503a48e89977437bf8b7bf485f416a15a2e83ed0.tar.gz
iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.tar.bz2
iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.zip
Merge pull request #2331 from iced-rs/program-api
`Program` API
Diffstat (limited to 'examples/system_information/src')
-rw-r--r--examples/system_information/src/main.rs39
1 files changed, 15 insertions, 24 deletions
diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs
index 31dc92f1..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::{
- executor, system, Application, Command, Element, Length, Settings, Theme,
-};
-
-use bytesize::ByteSize;
+use iced::{system, Command, Element, Length};
pub fn main() -> iced::Result {
- Example::run(Settings::default())
+ 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)]
@@ -22,23 +27,7 @@ enum Message {
Refresh,
}
-impl Application for Example {
- type Message = Message;
- type Theme = Theme;
- type Executor = executor::Default;
- type Flags = ();
-
- fn new(_flags: ()) -> (Self, Command<Message>) {
- (
- Self::Loading,
- system::fetch_information(Message::InformationReceived),
- )
- }
-
- fn title(&self) -> String {
- String::from("System Information - Iced")
- }
-
+impl Example {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Refresh => {
@@ -55,6 +44,8 @@ impl Application for Example {
}
fn view(&self) -> Element<Message> {
+ use bytesize::ByteSize;
+
let content: Element<_> = match self {
Example::Loading => text("Loading...").size(40).into(),
Example::Loaded { information } => {