15d7f5e873
- notescraft-lint (rules, safe fixes, learned style) and notescraft-blocks (block model and edits); engine lint.* and block.* commands with CLI and MCP parity - Lint tab, underlines, slash menu with preview in Source and Visual, block grip and menu, Settings > Editor and lint, Vim block keys - Visual view: tables, note embeds, %% comments, wrapping property chips - Vault knowledge (Related tab, assistant sources, Settings) and calendar plugin - Sidebar top padding fixed, dot grid follows PaperCraft spacing, right-card tabs no longer cover the collapse button Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
76 lines
3.5 KiB
Rust
76 lines
3.5 KiB
Rust
//! Renders the Visual view with a block grip (pointer hover) and optionally the block menu, offscreen.
|
|
//!
|
|
//! ```sh
|
|
//! cargo run -p notescraft-ui-egui --example blocks_snapshot -- --vault <vault> --open "note.md" \
|
|
//! --hover 700,200 [--menu] [--turn-into] --out blocks.png [--size 1440x900]
|
|
//! ```
|
|
|
|
use notescraft_engine::Session;
|
|
use notescraft_ui_egui::app::NotesApp;
|
|
use notescraft_ui_egui::block_menu::{self, BlockMenu, Page};
|
|
|
|
fn arg(args: &[String], name: &str) -> Option<String> {
|
|
args.iter().position(|a| a == name).and_then(|i| args.get(i + 1).cloned())
|
|
}
|
|
|
|
fn pair(text: &str) -> Option<(f32, f32)> {
|
|
let (a, b) = text.split_once(['x', ','])?;
|
|
Some((a.parse().ok()?, b.parse().ok()?))
|
|
}
|
|
|
|
fn main() {
|
|
let args: Vec<String> = std::env::args().collect();
|
|
let out = arg(&args, "--out").unwrap_or_else(|| "blocks.png".into());
|
|
let vault = arg(&args, "--vault").unwrap_or_else(|| "/tmp/nc-vault".into());
|
|
let (w, h) = arg(&args, "--size").and_then(|s| pair(&s)).unwrap_or((1440.0, 900.0));
|
|
let Some(theme) = notescraft_themes::builtin(&arg(&args, "--theme").unwrap_or_else(|| "catppuccin-mocha".into())) else { return };
|
|
let Ok(session) = Session::open(std::path::Path::new(&vault)) else { return };
|
|
let mut app = NotesApp::new(session, theme);
|
|
app.state.animations = false;
|
|
if let Some(path) = arg(&args, "--open") {
|
|
app.open_note(&path);
|
|
}
|
|
let mut harness =
|
|
egui_kittest::Harness::builder().with_size(egui::vec2(w, h)).with_max_steps(32).wgpu().build_ui_state(|ui, app: &mut NotesApp| app.ui(ui.ctx()), app);
|
|
let mut hover = arg(&args, "--hover").and_then(|s| pair(&s)).unwrap_or((700.0, 200.0));
|
|
let drag = arg(&args, "--drag-from").and_then(|s| pair(&s)).zip(arg(&args, "--drag-to").and_then(|s| pair(&s)));
|
|
for step in 0..12 {
|
|
harness.input_mut().events.push(egui::Event::PointerMoved(egui::pos2(hover.0, hover.1)));
|
|
harness.step();
|
|
if let Some((from, to)) = drag
|
|
&& step == 6
|
|
{
|
|
let button = |pressed| egui::Event::PointerButton {
|
|
pos: egui::pos2(from.0, from.1),
|
|
button: egui::PointerButton::Primary,
|
|
pressed,
|
|
modifiers: egui::Modifiers::NONE,
|
|
};
|
|
harness.input_mut().events.extend([egui::Event::PointerMoved(egui::pos2(from.0, from.1)), button(true)]);
|
|
harness.step();
|
|
harness.input_mut().events.push(egui::Event::PointerMoved(egui::pos2(from.0, from.1 + 12.0)));
|
|
harness.step();
|
|
harness.input_mut().events.push(egui::Event::PointerMoved(egui::pos2(to.0, to.1)));
|
|
harness.step();
|
|
harness.step();
|
|
hover = to;
|
|
}
|
|
if step == 6 && args.iter().any(|a| a == "--menu") {
|
|
let page = if args.iter().any(|a| a == "--turn-into") { Page::TurnInto } else { Page::Main };
|
|
let offset = arg(&args, "--offset").and_then(|s| s.parse().ok()).unwrap_or(0);
|
|
block_menu::open(
|
|
&harness.ctx,
|
|
BlockMenu { path: arg(&args, "--open").unwrap_or_default(), offset, anchor: egui::pos2(hover.0 - 100.0, hover.1), page },
|
|
);
|
|
}
|
|
std::thread::sleep(std::time::Duration::from_millis(40));
|
|
}
|
|
match harness.render() {
|
|
Ok(image) => match image.save(&out) {
|
|
Ok(()) => println!("wrote {out}"),
|
|
Err(error) => eprintln!("could not save {out}: {error}"),
|
|
},
|
|
Err(error) => eprintln!("render failed: {error}"),
|
|
}
|
|
}
|