From ccd02c525bd5751d828bb6ab7b656d88526b2b55 Mon Sep 17 00:00:00 2001 From: Jedsek Date: Fri, 20 Jan 2023 13:46:09 +0800 Subject: [PATCH 1/3] Update main.rs The app should not render qr_code when data is empty --- examples/qr_code/src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs index 6f487e4cbd..27b41fdc84 100644 --- a/examples/qr_code/src/main.rs +++ b/examples/qr_code/src/main.rs @@ -21,10 +21,7 @@ impl Sandbox for QRGenerator { type Message = Message; fn new() -> Self { - QRGenerator { - qr_code: qr_code::State::new("").ok(), - ..Self::default() - } + QRGenerator::default() } fn title(&self) -> String { @@ -36,7 +33,12 @@ impl Sandbox for QRGenerator { Message::DataChanged(mut data) => { data.truncate(100); - self.qr_code = qr_code::State::new(&data).ok(); + self.qr_code = if data.is_empty() { + None + } else { + qr_code::State::new(&data).ok() + } + self.data = data; } } From 06fb7e0b51e0750122e6775ab5cec59d6e3431d4 Mon Sep 17 00:00:00 2001 From: Jedsek Date: Fri, 20 Jan 2023 13:56:02 +0800 Subject: [PATCH 2/3] Update main.rs --- examples/qr_code/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs index 27b41fdc84..42b58a21d5 100644 --- a/examples/qr_code/src/main.rs +++ b/examples/qr_code/src/main.rs @@ -37,7 +37,7 @@ impl Sandbox for QRGenerator { None } else { qr_code::State::new(&data).ok() - } + }; self.data = data; } From ac1945404efde5fbec7f3004f688dfd08f28cf55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 17 Feb 2023 13:57:04 +0100 Subject: [PATCH 3/3] Run `cargo fmt` --- examples/qr_code/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs index 42b58a21d5..c10c665b1a 100644 --- a/examples/qr_code/src/main.rs +++ b/examples/qr_code/src/main.rs @@ -38,7 +38,7 @@ impl Sandbox for QRGenerator { } else { qr_code::State::new(&data).ok() }; - + self.data = data; } }