better choosing of version
This commit is contained in:
parent
222324d954
commit
ef468dcc6d
3 changed files with 17 additions and 4 deletions
|
@ -1 +1,3 @@
|
|||
mod qr;
|
||||
pub mod qr;
|
||||
|
||||
pub use qr::Mode;
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -5,6 +5,8 @@ use eframe::egui;
|
|||
use egui_extras::RetainedImage;
|
||||
use fast_qr::convert::image::ImageBuilder;
|
||||
|
||||
use godiva::qr::*;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(author, version, trailing_var_arg = true)]
|
||||
struct Cli {
|
||||
|
@ -40,21 +42,30 @@ fn main() -> Result<(), eframe::Error> {
|
|||
eframe::run_native(
|
||||
"Show an image with eframe/egui",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(Flasher { content })),
|
||||
Box::new(|_cc| {
|
||||
Box::new(Flasher {
|
||||
content,
|
||||
mode: Mode::Ascii,
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
struct Flasher {
|
||||
pub content: Vec<u8>,
|
||||
pub mode: Mode,
|
||||
}
|
||||
|
||||
impl eframe::App for Flasher {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
let heading_text = String::from_utf8(self.content.clone()).unwrap();
|
||||
let len = heading_text.len();
|
||||
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())
|
||||
.version(fast_qr::Version::V40)
|
||||
.version(version)
|
||||
.build()
|
||||
.unwrap();
|
||||
let bytes = ImageBuilder::default()
|
||||
|
|
|
@ -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::*;
|
||||
let ecl = match ecl {
|
||||
ECL::L => 0.7,
|
||||
|
|
Loading…
Reference in a new issue