From 40d54065f4001b196d00a53060f824b32e4d29ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guti=C3=A9rrez=20Alonso?= <30444886+margual56@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:35:05 +0100 Subject: [PATCH] Adds a banner to the web version advertising the existance of the native version (#41) * Add a small ad to download the native version * Add a tooltip; Fix positioning * Bump version * Format code --- Cargo.lock | 2 +- locales/ads.json | 14 ++++++++++++++ src/window.rs | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 locales/ads.json diff --git a/Cargo.lock b/Cargo.lock index ce00505..04ec3f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3404,7 +3404,7 @@ dependencies = [ [[package]] name = "turing-machine" -version = "1.3.3" +version = "1.3.4" dependencies = [ "base64", "bincode", diff --git a/locales/ads.json b/locales/ads.json new file mode 100644 index 0000000..d1343ce --- /dev/null +++ b/locales/ads.json @@ -0,0 +1,14 @@ +{ + "lbl.ad.native": { + "en": "Please consider using the native version for a better experience.", + "es": "Por favor, considere usar la versión nativa para una mejor experiencia." + }, + "lbl.ad.exe": { + "en": "Click to download.", + "es": "Haz click aquí para descargarla." + }, + "lbl.ad.explanation": { + "en": "The native version has code autosaving, persistent configuration, and more.", + "es": "La versión nativa tiene autoguardado de código, configuración persistente, y más." + } +} diff --git a/src/window.rs b/src/window.rs index 6323349..4dc1aa2 100644 --- a/src/window.rs +++ b/src/window.rs @@ -825,7 +825,7 @@ impl MyApp { if ui.link(t!("menu.repository", lang)).clicked() { webbrowser::open( - "https://github.com/margual56/turing-machine-2.0", + "https://github.com/turing-marcos/turing-machine", ) .unwrap(); } @@ -1167,6 +1167,37 @@ impl MyApp { } }); }); + + #[cfg(target_family = "wasm")] + { + let child_size = egui::Rect::from_center_size( + egui::pos2( + main_panel.cursor().center().x, + ctx.available_rect().center_bottom().y - 50.0, + ), + egui::Vec2::new(ctx.available_rect().width() / 2.0, 30.0), + ); + let mut popup = main_panel.child_ui(child_size, egui::Layout::default()); + egui::Frame::popup(&ctx.style()) + .stroke(egui::Stroke::NONE) + .fill(Color32::from_rgba_unmultiplied(0, 0, 0, 0)) + .show(&mut popup, |ui| { + ui.vertical_centered(|ui| { + ui.horizontal(|ui| { + ui.label(t!("lbl.ad.native", &lang)); + + if ui.link(t!("lbl.ad.exe", &lang)).clicked() { + webbrowser::open( + "https://github.com/turing-marcos/turing-machine/releases/latest", + ) + .unwrap(); + } + }); + }); + }) + .response + .on_hover_text_at_pointer(t!("lbl.ad.explanation", &lang)); + } }); } }