summaryrefslogtreecommitdiffstats
path: root/examples/system_information
diff options
context:
space:
mode:
authorLibravatar Richard <richardsoncusto@gmail.com>2022-04-14 02:11:43 -0300
committerLibravatar Richard <richardsoncusto@gmail.com>2022-04-26 18:59:08 -0300
commitc9ea1f11dec96df04ade463ea9f33062a85c9219 (patch)
treefcdf29f469d18dfdc3b3ab40d7e6b2491a416194 /examples/system_information
parent5bfe887e3d4acb2c48cca22c73aa52f4cc4856ad (diff)
downloadiced-c9ea1f11dec96df04ade463ea9f33062a85c9219.tar.gz
iced-c9ea1f11dec96df04ade463ea9f33062a85c9219.tar.bz2
iced-c9ea1f11dec96df04ade463ea9f33062a85c9219.zip
Add memory usage to `Information` struct
Diffstat (limited to 'examples/system_information')
-rw-r--r--examples/system_information/src/main.rs43
1 files changed, 37 insertions, 6 deletions
diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs
index e0e7db09..79033e4c 100644
--- a/examples/system_information/src/main.rs
+++ b/examples/system_information/src/main.rs
@@ -1,6 +1,6 @@
use iced::{
- executor, system, Application, Column, Command, Container, Element, Length,
- Settings, Text,
+ button, executor, system, Application, Button, Column, Command, Container,
+ Element, Length, Settings, Text,
};
use bytesize::ByteSize;
@@ -11,13 +11,17 @@ pub fn main() -> iced::Result {
enum Example {
Loading,
- Loaded { information: system::Information },
+ Loaded {
+ information: system::Information,
+ refresh_button: button::State,
+ },
Unsupported,
}
-#[derive(Debug)]
+#[derive(Clone, Debug)]
enum Message {
InformationReceived(Option<system::Information>),
+ Refresh,
}
impl Application for Example {
@@ -38,9 +42,16 @@ impl Application for Example {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
+ Message::Refresh => {
+ return system::information(Message::InformationReceived);
+ }
Message::InformationReceived(information) => {
if let Some(information) = information {
- *self = Self::Loaded { information };
+ let refresh_button = button::State::new();
+ *self = Self::Loaded {
+ information,
+ refresh_button,
+ };
} else {
*self = Self::Unsupported;
}
@@ -53,7 +64,10 @@ impl Application for Example {
fn view(&mut self) -> Element<Message> {
let content: Element<Message> = match self {
Example::Loading => Text::new("Loading...").size(40).into(),
- Example::Loaded { information } => {
+ Example::Loaded {
+ information,
+ refresh_button,
+ } => {
let system_name = Text::new(format!(
"System name: {}",
information
@@ -102,6 +116,19 @@ impl Application for Example {
)
));
+ let memory_text = if let Some(memory_used) =
+ information.memory_used
+ {
+ let memory_readable = ByteSize::kb(memory_used).to_string();
+
+ format!("{} kb ({})", memory_used, memory_readable)
+ } else {
+ String::from("None")
+ };
+
+ let memory_used =
+ Text::new(format!("Memory (used): {}", memory_text));
+
let graphics_adapter = Text::new(format!(
"Graphics adapter: {}",
information.graphics_adapter
@@ -119,8 +146,12 @@ impl Application for Example {
cpu_brand.size(30).into(),
cpu_cores.size(30).into(),
memory_total.size(30).into(),
+ memory_used.size(30).into(),
graphics_adapter.size(30).into(),
graphics_backend.size(30).into(),
+ Button::new(refresh_button, Text::new("Refresh"))
+ .on_press(Message::Refresh)
+ .into(),
])
.spacing(10)
.into()