summaryrefslogtreecommitdiffstats
path: root/examples/system_information
diff options
context:
space:
mode:
Diffstat (limited to 'examples/system_information')
-rw-r--r--examples/system_information/src/main.rs53
1 files changed, 25 insertions, 28 deletions
diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs
index 89a8383a..e2808edd 100644
--- a/examples/system_information/src/main.rs
+++ b/examples/system_information/src/main.rs
@@ -1,5 +1,5 @@
-use iced::widget::{button, column, container, text};
-use iced::{system, Command, Element};
+use iced::widget::{button, center, column, text};
+use iced::{system, Element, Task};
pub fn main() -> iced::Result {
iced::program("System Information - Iced", Example::update, Example::view)
@@ -24,19 +24,20 @@ enum Message {
}
impl Example {
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Refresh => {
*self = Self::Loading;
- return system::fetch_information(Message::InformationReceived);
+ return system::fetch_information()
+ .map(Message::InformationReceived);
}
Message::InformationReceived(information) => {
*self = Self::Loaded { information };
}
}
- Command::none()
+ Task::none()
}
fn view(&self) -> Element<Message> {
@@ -45,56 +46,56 @@ impl Example {
let content: Element<_> = match self {
Example::Loading => text("Loading...").size(40).into(),
Example::Loaded { information } => {
- let system_name = text(format!(
+ let system_name = text!(
"System name: {}",
information
.system_name
.as_ref()
.unwrap_or(&"unknown".to_string())
- ));
+ );
- let system_kernel = text(format!(
+ let system_kernel = text!(
"System kernel: {}",
information
.system_kernel
.as_ref()
.unwrap_or(&"unknown".to_string())
- ));
+ );
- let system_version = text(format!(
+ let system_version = text!(
"System version: {}",
information
.system_version
.as_ref()
.unwrap_or(&"unknown".to_string())
- ));
+ );
- let system_short_version = text(format!(
+ let system_short_version = text!(
"System short version: {}",
information
.system_short_version
.as_ref()
.unwrap_or(&"unknown".to_string())
- ));
+ );
let cpu_brand =
- text(format!("Processor brand: {}", information.cpu_brand));
+ text!("Processor brand: {}", information.cpu_brand);
- let cpu_cores = text(format!(
+ let cpu_cores = text!(
"Processor cores: {}",
information
.cpu_cores
.map_or("unknown".to_string(), |cores| cores
.to_string())
- ));
+ );
let memory_readable =
ByteSize::b(information.memory_total).to_string();
- let memory_total = text(format!(
+ let memory_total = text!(
"Memory (total): {} bytes ({memory_readable})",
information.memory_total,
- ));
+ );
let memory_text = if let Some(memory_used) =
information.memory_used
@@ -106,17 +107,13 @@ impl Example {
String::from("None")
};
- let memory_used = text(format!("Memory (used): {memory_text}"));
+ let memory_used = text!("Memory (used): {memory_text}");
- let graphics_adapter = text(format!(
- "Graphics adapter: {}",
- information.graphics_adapter
- ));
+ let graphics_adapter =
+ text!("Graphics adapter: {}", information.graphics_adapter);
- let graphics_backend = text(format!(
- "Graphics backend: {}",
- information.graphics_backend
- ));
+ let graphics_backend =
+ text!("Graphics backend: {}", information.graphics_backend);
column![
system_name.size(30),
@@ -136,6 +133,6 @@ impl Example {
}
};
- container(content).center().into()
+ center(content).into()
}
}