From 34ef7339cd0a927ec2d49b15ce93d7d2bdb0ef4f Mon Sep 17 00:00:00 2001 From: Praveen Vikram Date: Tue, 10 Nov 2026 20:11:22 -0500 Subject: [PATCH 1/2] add an about dialog --- Cargo.lock | 2 +- build.rs | 3 +- src/about_dialog.rs | 29 +++++++++++ src/action.rs | 2 + src/main.rs | 6 +++ src/menu.rs | 10 +++- src/tests/about.rs | 117 ++++++++++++++++++++++++++++++++++++++++++++ src/tests/mod.rs | 1 + 8 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 src/about_dialog.rs create mode 100644 src/tests/about.rs diff --git a/Cargo.lock b/Cargo.lock index 951a29f..9e3706d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -801,7 +801,7 @@ checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" [[package]] name = "drwr" -version = "0.1.0" +version = "0.1.1" dependencies = [ "base64", "directories", diff --git a/build.rs b/build.rs index 146f804..25406a4 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,5 @@ -//! Embeds the short commit hash (or `unknown`) for `drwr -version`. +//! Embeds the short commit hash (or `unknown`) for `drwr -version` and the +//! About dialog. use std::process::Command; diff --git a/src/about_dialog.rs b/src/about_dialog.rs new file mode 100644 index 0000000..09fa062 --- /dev/null +++ b/src/about_dialog.rs @@ -0,0 +1,29 @@ +use egui::{Context, Id, Modal}; + +/// Shows the About dialog while `open`, with the version, the commit that +/// `build.rs` embeds and a link to the project page, until Close, Enter or +/// Escape closes it. +pub fn show(ctx: &Context, open: &mut bool) { + if !*open { + return; + } + let id = Id::unique("about_dialog"); + // Opaque from the first frame it's shown, unlike egui's fade-in. + let area = Modal::default_area(id).fade_in(false); + let modal = Modal::new(id).area(area).show(ctx, |ui| { + ui.strong("About drwr"); + ui.label(concat!("Version ", env!("CARGO_PKG_VERSION"))); + ui.label(concat!("Commit ", env!("DRWR_GIT_SHORT_COMMIT"))); + ui.hyperlink(env!("CARGO_PKG_HOMEPAGE")); + ui.separator(); + let close = ui.button("Close"); + // So Enter closes it, and Tab moves on to the link. + if ui.memory(|memory| memory.focused().is_none()) { + close.request_focus(); + } + close.clicked() + }); + if modal.inner || modal.should_close() { + *open = false; + } +} diff --git a/src/action.rs b/src/action.rs index 355d93b..7dcec4d 100644 --- a/src/action.rs +++ b/src/action.rs @@ -19,6 +19,8 @@ pub enum Action { /// Asks for an SVG file, which is added as a node in the middle of the /// view. InsertSvg, + /// Opens the About dialog, which shows the version and commit. + About, Quit, /// Undoes the last change to the graph, selecting what was selected /// before it. diff --git a/src/main.rs b/src/main.rs index 138eccf..47c5074 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ windows_subsystem = "windows" )] +mod about_dialog; mod action; mod atomic_file; mod canvas; @@ -150,6 +151,8 @@ struct DrwrApp { color_picker: ColorPicker, label_dialog: TextDialog, export_dialog: ExportDialog, + /// Whether the About dialog is open. + about: bool, /// The exports writing their files in the background. exports: Vec, /// The question waiting for an answer. @@ -663,6 +666,7 @@ impl DrwrApp { | Action::Save | Action::SaveAs | Action::Export + | Action::About | Action::Quit), ) => { ctx.memory_mut(|memory| memory.stop_text_input()); @@ -701,6 +705,7 @@ impl DrwrApp { self.file_dialog .open(purpose, Request::InsertSvg, ctx, frame); } + Action::About => self.about = true, Action::Quit => self.close_graph(CloseFor::Quit, ctx, frame), Action::Undo => self.step(Document::undo), Action::Redo => self.step(Document::redo), @@ -972,6 +977,7 @@ impl eframe::App for DrwrApp { if let Some(accepted) = self.export_dialog.show(ui.ctx()) { self.ask_where_to_export(accepted, ui.ctx(), frame); } + about_dialog::show(ui.ctx(), &mut self.about); self.record(); self.update_modified(); if std::mem::take(&mut self.close_requested) { diff --git a/src/menu.rs b/src/menu.rs index bb1b052..b5a802d 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -38,8 +38,14 @@ pub fn show( ui.separator(); let export = items(ui, [("Export…", Action::Export, enabled.file)]); ui.separator(); - let quit = items(ui, [("Quit", Action::Quit, true)]); - clicked = open.or(recent).or(save).or(export).or(quit); + let app = items( + ui, + [ + ("About drwr", Action::About, true), + ("Quit", Action::Quit, true), + ], + ); + clicked = open.or(recent).or(save).or(export).or(app); }); if shortcuts::file_menu_pressed(ui.ctx()) { Popup::open_id(ui.ctx(), Popup::default_response_id(&file.response)); diff --git a/src/tests/about.rs b/src/tests/about.rs new file mode 100644 index 0000000..01abbee --- /dev/null +++ b/src/tests/about.rs @@ -0,0 +1,117 @@ +use super::*; + +const PROJECT_PAGE: &str = "https://pvik.github.io/drwr/"; + +impl Harness { + /// Clicks File > About drwr. + fn open_about(&mut self) { + self.click_widget("File"); + self.click_widget("About drwr"); + assert!(self.app.about, "the About dialog didn't open"); + // Close takes the focus the frame after. + self.run(vec![]); + } + + /// Runs a frame with `events`, returning the URLs it opened. + fn opened_urls(&mut self, events: Vec) -> Vec { + let input = RawInput { + events, + ..RawInput::default() + }; + let output = self.run_input(input); + let urls = (output.platform_output.commands.iter()) + .filter_map(|command| match command { + egui::OutputCommand::OpenUrl(open) => Some(open.url.clone()), + _ => None, + }) + .collect(); + output.drop_without_applying_deltas(); + urls + } +} + +#[test] +fn file_about_shows_the_version_commit_and_project_page() { + let mut harness = Harness::new(); + harness.open_about(); + let version = format!("Version {}", env!("CARGO_PKG_VERSION")); + let commit = format!("Commit {}", env!("DRWR_GIT_SHORT_COMMIT")); + for text in [version.as_str(), commit.as_str(), PROJECT_PAGE] { + assert!(harness.painted(text), "{text:?} wasn't painted"); + } +} + +#[test] +fn the_file_menu_has_about_drwr_between_export_and_quit() { + let mut harness = Harness::new(); + harness.click_widget("File"); + let label = |name: &str, action| { + let shortcut = shortcuts::text(&harness.ctx, &action).unwrap(); + format!("{name} {shortcut}") + }; + let export = label("Export…", Action::Export); + let quit = label("Quit", Action::Quit); + let items: Vec<_> = [export.as_str(), "About drwr", quit.as_str()] + .iter() + .map(|label| testing::center(&harness.widget(label)).y) + .collect(); + assert!(items.is_sorted(), "{items:?}"); +} + +#[test] +fn close_enter_and_escape_close_the_about_dialog_keeping_the_keys() { + let mut harness = Harness::new(); + harness.press(Modifiers::NONE, Key::B); + for key in [None, Some(Key::Enter), Some(Key::Escape)] { + harness.open_about(); + match key { + Some(key) => harness.press(Modifiers::NONE, key), + None => harness.click_widget("Close"), + } + assert!(!harness.app.about, "{key:?} left it open"); + // The dialog keeps the keys in the frame it closes in. + harness.run(vec![]); + } + // Escape didn't also pick the Cursor tool. + assert_eq!(harness.app.tool, Tool::Box); +} + +#[test] +fn the_link_opens_the_project_page_on_a_click_or_tab_and_enter() { + let mut harness = Harness::new(); + harness.open_about(); + let at = testing::center(&harness.widget(PROJECT_PAGE)); + harness.run(vec![Event::PointerMoved(at)]); + harness.run(vec![button(at, true)]); + assert_eq!(harness.opened_urls(vec![button(at, false)]), [PROJECT_PAGE]); + assert!(harness.app.about); + + harness.press(Modifiers::NONE, Key::Escape); + harness.run(vec![]); + harness.open_about(); + // From Close to the link; the focus moves the frame after. + harness.press(Modifiers::NONE, Key::Tab); + harness.run(vec![]); + let enter = testing::key(Modifiers::NONE, Key::Enter); + assert_eq!(harness.opened_urls(vec![enter]), [PROJECT_PAGE]); + assert!(harness.app.about); +} + +#[test] +fn the_keyboard_opens_the_about_dialog_from_the_file_menu() { + let mut harness = Harness::new(); + harness.press(Modifiers::ALT, Key::F); + // New, Open…, Save, Save As…, Export…, then About drwr, as Recent Files + // is disabled without any. Each moves the focus the frame after. + let downs = std::iter::repeat_n(Key::ArrowDown, 6); + for key in downs.chain([Key::Enter]) { + harness.run(vec![]); + harness.press(Modifiers::NONE, key); + } + harness.run(vec![]); + // The Enter that picked it didn't close it too. + assert!(harness.app.about); + assert!(!Popup::is_any_open(&harness.ctx)); + harness.press(Modifiers::NONE, Key::Enter); + assert!(!harness.app.about); +} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 63654fb..f900569 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,3 +1,4 @@ +mod about; mod clipboard; mod edges; mod export; From a1f60572f70b9a7fa0fcac49e0a2d0847e9b56a2 Mon Sep 17 00:00:00 2001 From: Praveen Vikram Date: Tue, 10 Nov 2026 20:11:30 -0500 Subject: [PATCH 2/2] bump version --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b7e59c3..5ba229a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,9 @@ default-members = [".", "crates/graphml"] [package] name = "drwr" -version = "0.1.0" +version = "0.1.1" edition = "2024" +homepage = "https://pvik.github.io/drwr/" [dependencies] # Embeds SVG nodes' drawings in exports. usvg uses it, so it builds nothing new.