summaryrefslogtreecommitdiffstats
path: root/examples/qr_code
diff options
context:
space:
mode:
authorLibravatar Jedsek <jedsek@qq.com>2023-01-20 13:46:09 +0800
committerLibravatar GitHub <noreply@github.com>2023-01-20 13:46:09 +0800
commitccd02c525bd5751d828bb6ab7b656d88526b2b55 (patch)
tree776188d30edae83eda060c898c37c564bd595448 /examples/qr_code
parenteb4fcba05fb54741289a28ec9b921c90c9acc7fd (diff)
downloadiced-ccd02c525bd5751d828bb6ab7b656d88526b2b55.tar.gz
iced-ccd02c525bd5751d828bb6ab7b656d88526b2b55.tar.bz2
iced-ccd02c525bd5751d828bb6ab7b656d88526b2b55.zip
Update main.rs
The app should not render qr_code when data is empty
Diffstat (limited to 'examples/qr_code')
-rw-r--r--examples/qr_code/src/main.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/examples/qr_code/src/main.rs b/examples/qr_code/src/main.rs
index 6f487e4c..27b41fdc 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;
}
}