From 99a4bd1efe002a832c89d68b0d8579ef62868943 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 10 Jun 2022 21:06:15 +0200 Subject: [PATCH] QR code: backport Decoder new styling --- data/resources/ui/account_details_page.ui | 4 +++ src/widgets/accounts/qrcode_paintable.rs | 38 +++++++++++------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/data/resources/ui/account_details_page.ui b/data/resources/ui/account_details_page.ui index cda8608..11e42ea 100644 --- a/data/resources/ui/account_details_page.ui +++ b/data/resources/ui/account_details_page.ui @@ -37,6 +37,10 @@ 36 200 200 + hidden + diff --git a/src/widgets/accounts/qrcode_paintable.rs b/src/widgets/accounts/qrcode_paintable.rs index 2084081..112dfaa 100644 --- a/src/widgets/accounts/qrcode_paintable.rs +++ b/src/widgets/accounts/qrcode_paintable.rs @@ -39,29 +39,27 @@ impl From<&str> for QRCodeData { mod imp { fn snapshot_qrcode(snapshot: >k::Snapshot, qrcode: &QRCodeData, width: f64, height: f64) { - let is_dark_mode = adw::StyleManager::default().is_dark(); - let square_height = height as f32 / qrcode.height as f32; - let square_width = width as f32 / qrcode.width as f32; - + let padding_squares = 3.max(qrcode.height / 10); + let square_height = height as f32 / (qrcode.height + 2 * padding_squares) as f32; + let square_width = width as f32 / (qrcode.width + 2 * padding_squares) as f32; + let padding = square_height * padding_squares as f32; + let rect = graphene::Rect::new(0.0, 0.0, width as f32, height as f32); + snapshot.append_color(&gdk::RGBA::WHITE, &rect); qrcode.items.iter().enumerate().for_each(|(y, line)| { line.iter().enumerate().for_each(|(x, is_dark)| { - let color = if *is_dark { - if is_dark_mode { - gdk::RGBA::WHITE - } else { - gdk::RGBA::BLACK - } - } else { - gdk::RGBA::new(0.0, 0.0, 0.0, 0.0) - }; - let position = graphene::Rect::new( - (x as f32) * square_width, - (y as f32) * square_height, - square_width, - square_height, - ); + if *is_dark { + let mut black = gdk::RGBA::BLACK; + black.set_alpha(0.85); - snapshot.append_color(&color, &position); + let position = graphene::Rect::new( + (x as f32) * square_width + padding, + (y as f32) * square_height + padding, + square_width, + square_height, + ); + + snapshot.append_color(&black, &position); + }; }); }); }