better choosing of version

This commit is contained in:
Joe Ardent 2023-08-01 14:09:36 -07:00
parent 222324d954
commit ef468dcc6d
3 changed files with 17 additions and 4 deletions

View file

@ -1 +1,3 @@
mod qr; pub mod qr;
pub use qr::Mode;

View file

@ -5,6 +5,8 @@ use eframe::egui;
use egui_extras::RetainedImage; use egui_extras::RetainedImage;
use fast_qr::convert::image::ImageBuilder; use fast_qr::convert::image::ImageBuilder;
use godiva::qr::*;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(author, version, trailing_var_arg = true)] #[clap(author, version, trailing_var_arg = true)]
struct Cli { struct Cli {
@ -40,21 +42,30 @@ fn main() -> Result<(), eframe::Error> {
eframe::run_native( eframe::run_native(
"Show an image with eframe/egui", "Show an image with eframe/egui",
options, options,
Box::new(|_cc| Box::new(Flasher { content })), Box::new(|_cc| {
Box::new(Flasher {
content,
mode: Mode::Ascii,
})
}),
) )
} }
struct Flasher { struct Flasher {
pub content: Vec<u8>, pub content: Vec<u8>,
pub mode: Mode,
} }
impl eframe::App for Flasher { impl eframe::App for Flasher {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
let heading_text = String::from_utf8(self.content.clone()).unwrap(); let heading_text = String::from_utf8(self.content.clone()).unwrap();
let len = heading_text.len();
ui.heading(heading_text); ui.heading(heading_text);
let size = get_size(len, self.mode);
let version = get_version(size, fast_qr::ECL::H);
let qr = fast_qr::QRBuilder::new(self.content.clone()) let qr = fast_qr::QRBuilder::new(self.content.clone())
.version(fast_qr::Version::V40) .version(version)
.build() .build()
.unwrap(); .unwrap();
let bytes = ImageBuilder::default() let bytes = ImageBuilder::default()

View file

@ -15,7 +15,7 @@ pub fn get_size(len: usize, mode: Mode) -> usize {
} }
} }
pub fn choose_version(size: usize, ecl: ECL) -> fast_qr::Version { pub fn get_version(size: usize, ecl: ECL) -> fast_qr::Version {
use fast_qr::Version::*; use fast_qr::Version::*;
let ecl = match ecl { let ecl = match ecl {
ECL::L => 0.7, ECL::L => 0.7,