Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
29 changes: 29 additions & 0 deletions src/about_dialog.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
windows_subsystem = "windows"
)]

mod about_dialog;
mod action;
mod atomic_file;
mod canvas;
Expand Down Expand Up @@ -150,6 +151,8 @@ struct DrwrApp {
color_picker: ColorPicker<ColorProperty>,
label_dialog: TextDialog<LabelEdit>,
export_dialog: ExportDialog,
/// Whether the About dialog is open.
about: bool,
/// The exports writing their files in the background.
exports: Vec<Writing>,
/// The question waiting for an answer.
Expand Down Expand Up @@ -663,6 +666,7 @@ impl DrwrApp {
| Action::Save
| Action::SaveAs
| Action::Export
| Action::About
| Action::Quit),
) => {
ctx.memory_mut(|memory| memory.stop_text_input());
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
117 changes: 117 additions & 0 deletions src/tests/about.rs
Original file line number Diff line number Diff line change
@@ -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<Event>) -> Vec<String> {
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);
}
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod about;
mod clipboard;
mod edges;
mod export;
Expand Down
Loading