Skip to content

armgit / klad

Public Imported from GitHub
0

A drawing app built for agent/human collaboration

Rust

Notices stack in the canvas's bottom left corner, not at the pointer

Indicode BV5b45ea242473
diff --git a/crates/app/src/editor.rs b/crates/app/src/editor.rs
index a556fae..7aaa0d3 100644
--- a/crates/app/src/editor.rs
+++ b/crates/app/src/editor.rs
@@ -731,7 +731,6 @@ impl Editor {
messages.say(
Tone::Error,
format!("not watching the bundle, so agent edits will not show: {e}"),
- None,
Instant::now(),
);
}
@@ -930,12 +929,11 @@ impl Editor {
}
pub(crate) fn say(&mut self, tone: Tone, text: impl Into<String>) {
- let anchor = self.pointer;
let text = text.into();
if tone == Tone::Error {
crate::report::log(&format!("editor: {text}"));
}
- self.messages.say(tone, text, anchor, Instant::now());
+ self.messages.say(tone, text, Instant::now());
self.ctx.request_repaint();
}
diff --git a/crates/app/src/editor/panels.rs b/crates/app/src/editor/panels.rs
index 402ae2f..145f6a2 100644
--- a/crates/app/src/editor/panels.rs
+++ b/crates/app/src/editor/panels.rs
@@ -198,7 +198,7 @@ impl Editor {
if tone == Tone::Error {
crate::report::log(&format!("editor: {text}"));
}
- self.messages.say(tone, text, None, Instant::now());
+ self.messages.say(tone, text, Instant::now());
}
fn tend_jobs(&mut self) {
@@ -1064,21 +1064,12 @@ impl Editor {
let screen = ctx.content_rect();
let shown: Vec<Message> = self.messages.toasts(now).into_iter().cloned().collect();
let mut dismiss = None;
- let mut near = 0.0;
- let mut corner = screen.bottom() - layout::STATUS - 10.0;
+ let canvas = Some(self.canvas_rect).filter(|r| r.width() > 0.0 && r.height() > 0.0);
+ let left = canvas.map_or(screen.left(), |r| r.left()) + 12.0;
+ let mut bottom = canvas.map_or(screen.bottom() - layout::STATUS, |r| r.bottom()) - 12.0;
shown.iter().rev().for_each(|m| {
- let (pos, pivot) = match m.anchor {
- Some(p) => {
- let at = p + vec2(18.0, 16.0 + near);
- near += 38.0;
- (at, egui::Align2::LEFT_TOP)
- }
- None => {
- let at = egui::pos2(screen.right() - 12.0, corner);
- corner -= 40.0;
- (at, egui::Align2::RIGHT_BOTTOM)
- }
- };
+ let (pos, pivot) = (egui::pos2(left, bottom), egui::Align2::LEFT_BOTTOM);
+ bottom -= 40.0;
let sticky = m.tone == Tone::Error;
egui::Area::new(Id::unique(("toast", m.id)))
.order(egui::Order::Tooltip)
diff --git a/crates/app/src/editor/ui_tests.rs b/crates/app/src/editor/ui_tests.rs
index 0ec037d..7defa6a 100644
--- a/crates/app/src/editor/ui_tests.rs
+++ b/crates/app/src/editor/ui_tests.rs
@@ -687,9 +687,12 @@ fn cmd_k_finds_and_runs_commands_and_explains_refusals() {
.query_all_by_label_contains("select frames first")
.map(|n| n.rect())
.collect();
+ let canvas = h.state().canvas_rect;
assert!(
- shown.iter().any(|r| (r.min - pos2(640.0, 200.0)).length() < 80.0),
- "no toast next to the pointer: {shown:?}"
+ shown
+ .iter()
+ .any(|r| r.left() - canvas.left() < 60.0 && (canvas.bottom() - r.bottom()).abs() < 40.0),
+ "no toast in the canvas's bottom left corner: {shown:?} in {canvas:?}"
);
assert!(
shown.iter().any(|r| r.bottom() > 800.0 - layout::STATUS),
@@ -3071,6 +3074,31 @@ fn texts(h: &Harness<'static, Editor>) -> Vec<(String, klad_core::generators::Te
.collect()
}
+#[test]
+fn notices_stack_in_the_canvas_bottom_left_corner_not_at_the_pointer() {
+ let path = sample("notices");
+ let mut h = harness(editor(&path), vec2(1440.0, 1000.0));
+ let canvas = h.state().canvas_rect;
+ h.hover_at(canvas.center());
+ h.run_steps(1);
+ h.state_mut().say(crate::messages::Tone::Done, "first notice");
+ h.state_mut().say(crate::messages::Tone::Refused, "second notice");
+ h.run_steps(2);
+ let (first, second) = (
+ h.get_by_label("first notice").rect(),
+ h.get_by_label("second notice").rect(),
+ );
+ assert!(
+ second.left() - canvas.left() < 60.0 && canvas.bottom() - second.bottom() < 40.0,
+ "the newest notice sits in the canvas's bottom left corner: {second:?} in {canvas:?}"
+ );
+ assert!(
+ (first.left() - second.left()).abs() < 1.0 && first.bottom() < second.top(),
+ "older ones stack above it: {first:?} {second:?}"
+ );
+ let _ = std::fs::remove_dir_all(&path);
+}
+
#[test]
fn text_is_typed_on_the_canvas_and_edited_in_place() {
let path = sample("text-tool");
diff --git a/crates/app/src/messages.rs b/crates/app/src/messages.rs
index e5e2da2..198fad1 100644
--- a/crates/app/src/messages.rs
+++ b/crates/app/src/messages.rs
@@ -1,4 +1,3 @@
-use egui::Pos2;
use std::collections::VecDeque;
use std::time::{Duration, Instant};
@@ -30,7 +29,6 @@ pub struct Message {
pub tone: Tone,
pub text: String,
pub at: Instant,
- pub anchor: Option<Pos2>,
pub dismissed: bool,
pub times: u32,
}
@@ -42,7 +40,7 @@ pub struct Messages {
}
impl Messages {
- pub fn say(&mut self, tone: Tone, text: impl Into<String>, anchor: Option<Pos2>, now: Instant) -> u64 {
+ pub fn say(&mut self, tone: Tone, text: impl Into<String>, now: Instant) -> u64 {
let text = text.into();
if let Some(last) = self
.log
@@ -50,7 +48,6 @@ impl Messages {
.filter(|m| m.tone == tone && m.text == text && !m.dismissed)
{
last.at = now;
- last.anchor = anchor.or(last.anchor);
last.times += 1;
return last.id;
}
@@ -60,7 +57,6 @@ impl Messages {
tone,
text,
at: now,
- anchor,
dismissed: false,
times: 1,
});
@@ -109,23 +105,20 @@ impl Messages {
#[cfg(test)]
mod tests {
use super::*;
- use egui::pos2;
#[test]
fn results_fade_refusals_linger_and_errors_stay_until_dismissed() {
let t0 = Instant::now();
let mut m = Messages::default();
- let at = Some(pos2(10.0, 20.0));
- m.say(Tone::Info, "frame 4 shown", None, t0);
- let done = m.say(Tone::Done, "copied 3 marks", at, t0);
- let refused = m.say(Tone::Refused, "nothing to duplicate on this frame", at, t0);
- let error = m.say(Tone::Error, "reading doc.json", None, t0);
+ m.say(Tone::Info, "frame 4 shown", t0);
+ let done = m.say(Tone::Done, "copied 3 marks", t0);
+ let refused = m.say(Tone::Refused, "nothing to duplicate on this frame", t0);
+ let error = m.say(Tone::Error, "reading doc.json", t0);
let texts = |m: &Messages, now| m.toasts(now).iter().map(|t| t.id).collect::<Vec<_>>();
assert_eq!(texts(&m, t0), [done, refused, error]);
assert_eq!(texts(&m, t0 + Duration::from_secs(4)), [refused, error]);
assert_eq!(texts(&m, t0 + Duration::from_secs(60)), [error]);
assert_eq!(m.latest().unwrap().id, error);
- assert_eq!(m.toasts(t0)[0].anchor, at);
m.dismiss(error);
assert!(texts(&m, t0 + Duration::from_secs(60)).is_empty());
assert_eq!(m.next_change(t0), Some(Duration::from_millis(3500)));
@@ -136,12 +129,12 @@ mod tests {
fn a_message_said_again_is_one_message() {
let t0 = Instant::now();
let mut m = Messages::default();
- let a = m.say(Tone::Error, "no watcher", None, t0);
- let b = m.say(Tone::Error, "no watcher", None, t0 + Duration::from_secs(1));
+ let a = m.say(Tone::Error, "no watcher", t0);
+ let b = m.say(Tone::Error, "no watcher", t0 + Duration::from_secs(1));
assert_eq!(a, b);
assert_eq!(m.latest().unwrap().times, 2);
(0..KEEP + 20).for_each(|i| {
- m.say(Tone::Done, format!("step {i}"), None, t0);
+ m.say(Tone::Done, format!("step {i}"), t0);
});
assert_eq!(m.log().count(), KEEP);
assert_eq!(m.toasts(t0).len(), SHOWN);
diff --git a/docs/DESIGN.md b/docs/DESIGN.md
index 6d97536..05e12b1 100644
--- a/docs/DESIGN.md
+++ b/docs/DESIGN.md
@@ -441,7 +441,7 @@ Scripts are any language that prints edit ops as JSON lines into `klad apply`. G
- First start (S8.7, `start.rs`, `editor/first.rs`, `klad_core::samples`): until the settings say `welcomed` (set when any drawing opens, or by "Not now"), the start window opens with a welcome offering first steps. First steps make `first steps.klad` (1280 by 800 on paper, one paint layer) in the drawings folder and open it with a small window of three steps that tick as they happen: a brush stroke is saved, a fill is saved, the request for an agent is copied (a sentence with the drawing's path asking the agent to read `klad skill`, render the drawing and add a shadow; "install the klad command" sits next to it). Help > First steps opens and closes the window on any drawing. The checklist is the editor's alone: it teaches the hands on the canvas, and an agent's first steps are `klad skill`. Revisit the third step when klad is an MCP server (S8.10). Under the recent drawings the start window shows the samples: the drawings `samples/shipped.json` names (name, bundle, a line on what it shows), each a card with its thumbnail and that line; a click copies it into the drawings folder without its `.cache` (`samples::copy`, `<name>.klad` or `<name> 2.klad`) and opens the copy, so a sample is never changed. `klad samples` lists the same set and `--copy <name> [--into folder]` copies one (default the current folder). Samples are found like the fonts: `KLAD_SAMPLES`, then `samples/` next to the binary, `../Resources/samples`, `../share/klad/samples`, and a source checkout's `samples/` up to five folders above the binary (where they exist after `just samples`; a sample not built is left out). `packaging/samples.sh` puts them in every build: it builds any that are missing with that build's `klad` (through the sample's `build.sh`, `PYTHON` naming the interpreter), copies them without caches, and renders each one's `<name>.thumb.png` next to it at 336 px, so the start window never renders into the app (a thumbnail outside the bundle is used as it is; only recent drawings' `.cache/thumb.png` are remade when the drawing changes). `app.sh` puts them in `Resources/samples`, `archive.sh` in the archive's `samples/` and the AppImage's `usr/share/klad/samples`; the six weigh about 4 MB.
- Messages and problem reports (S8.8, `report.rs`): a message says what happened and what to do next ("nothing to fill there: click inside closed lines, or raise the gap so small openings close"); a refusal names the step that makes the command possible. Errors that mean klad itself went wrong (an invariant broken, a picture missing that should be there) are `report::Bug`s: the editor says "something went wrong inside klad (what), everything up to your last edit is saved; Help > Report a problem copies what an issue needs" instead of the bare detail; a job whose CLI crashed reads the same, and a job that failed says "<job> did not finish: <the CLI's reason>". Every error message, job failure and crash of the editor or the CLI is appended to `klad.log` next to the settings (`KLAD_LOG` overrides it; past 512 KB the older half goes), one dated line each. Help > Report a problem opens a window with the report as it will be copied: klad's version and where it ran, the system (macOS version, the Linux distribution, Windows' version, and the processor), a place for what happened, the drawing's size, the last 40 messages and the last 40 lines of the log, with the home folder written as `~` and the drawing's folder as `<the drawing's folder>`. "include the drawing" zips the drawing without its cache next to it (`<name> for a report.zip`, stored entries, written by klad itself) and the report names the file to attach; "copy the report" copies it and "open klad's issues" opens GitHub. Nothing is sent by klad. `klad report [--drawing <bundle>]` prints the same report from the command line (version, system, log, the drawing zipped).
- Menus (S8.6, `commands::MENUS`, `menus.rs`): one list of menus holds every command but the holds (pan, zoom, the eyedropper, flipping, rolling, the parallax preview and sizing on the canvas, which are gestures), so the menus, the palette and the keys stay one list; a test fails when a command is in no menu or in two. The menus, in order: File (new, open, recent, close; import; export; the path and the command line tool), Edit (undo; copy, paste, duplicate, delete; selecting; Transform, Strokes and Points submenus), Tools (the tools, the brush, the colours), Layer (new, duplicate, rename, group, delete; show, lock, clip, lock alpha; Mask and Shape generators submenus, paint over; refill and gaps), Frame (stepping, drawings, holds and moves, inserting and removing frames), Animation (playback, onion skin, exposure, Selected frames and Clip submenus, the checks across frames), View (zoom, rotation, flip, the reference), Window (the panels, the message log, numbers) and Help. Each command has a short menu label (`Cmd::menu`: "Show", "Clip to layer below", "Export…"), since the menu says what it acts on, while the palette and hints keep the longer names; "…" marks a command that opens a window. Items show one key each (Backspace for delete); toggles show a tick, except commands that open a window; a command that cannot run now is greyed out (its reason is the palette's). A test keeps labels unique in each menu and under 30 characters. On macOS the list becomes the system menu bar (`menus::install`, rebuilt when the keys or the recent drawings change): an app menu with About, Settings, Services, hide and Quit, then the list, whose Window menu also gets the system's Minimize, Zoom and Bring all to front (it is the app's windows menu). Items target one Objective-C object (`KladMenuTarget`, `define_class!`) whose `kladRun:` queues the command for the next frame (the editor runs it through `Editor::invoke` as any key would) and whose `validateMenuItem:` reads a snapshot of what is off and on that the app refreshes every 0.4 s. The item keys are shown but not claimed: the object is each menu's delegate and answers no to `menuHasKeyEquivalent:forEvent:target:action:`, so a key still reaches the editor's own dispatch (which knows holds, repeats and text fields) and nothing runs twice; only the app menu's own keys (cmd , cmd Q cmd H) and Window's cmd M are AppKit's. On Windows and Linux (and in tests) the same list is an egui menu bar over the window, hidden with the panels (Tab). File > Open recent lists the last ten drawings; File > Close the drawing (cmd W, refused while a job runs) goes back to the start window, where only new, open, recent and quit run. Settings and Quit sit in the app menu on macOS and in Edit and File elsewhere; About (with the licences) is in Help everywhere and also in the macOS app menu.
-- Messages and jobs (M4 batch 1): every result, refusal and error goes through `Editor::say` with a tone (info, done, refused, error). Done and refused messages show for 3.5 and 6 s as a toast next to the pointer where the user acted (jobs' messages at the bottom right), errors until dismissed, info only in the status line; the status line shows the latest message (a click opens the message log, the last 200 with times), the frame, where the next stroke goes ("draws into c12 on lines, frames 4 to 7"), running jobs with a cancel button, slow internal work (preparing a selection, drawing an edited path, loading a frame), zoom and rotation. Times that used to be status text (stroke, fill, edit, undo, sync, frame step, last play, last job) are kept by name for the numbers window. Background jobs (in-betweens, Godot export) run the same `klad` binary through one job list (`jobs.rs`); when the CLI exits with code 75 (the document changed while it computed) the job runs again, up to three times, so an edit made in the editor meanwhile is never overwritten.
+- Messages and jobs (M4 batch 1): every result, refusal and error goes through `Editor::say` with a tone (info, done, refused, error). Done and refused messages show for 3.5 and 6 s as a toast in the bottom left corner of the canvas, newest lowest (2026-11-08: they used to follow the pointer, which got in the way), errors until dismissed, info only in the status line; the status line shows the latest message (a click opens the message log, the last 200 with times), the frame, where the next stroke goes ("draws into c12 on lines, frames 4 to 7"), running jobs with a cancel button, slow internal work (preparing a selection, drawing an edited path, loading a frame), zoom and rotation. Times that used to be status text (stroke, fill, edit, undo, sync, frame step, last play, last job) are kept by name for the numbers window. Background jobs (in-betweens, Godot export) run the same `klad` binary through one job list (`jobs.rs`); when the CLI exits with code 75 (the document changed while it computed) the job runs again, up to three times, so an edit made in the editor meanwhile is never overwritten.
- Tools: brush, eraser, smudge, fill (inside lines, gap closing), lasso select and transform, move/rotate/scale handles, path point editing, eyedropper.
- Stroke select (S, M2): a click picks the mark you see under the pointer. With "all layers" (the S and V options and Edit > Pick from all layers, `pickAllLayers` in the settings, on by default) that is on the topmost visible, unlocked paint layer that shows paint there, which becomes active: a layer shows paint where its raster's alpha, times its own and its groups' opacity, outside its mask and inside its clip base, passes 5%, and a layer whose pixels are not loaded counts by its marks' shapes (`Scene::seen_at`, `Scene::marks_at`); with "this layer" it is the active layer. In that layer the mark is the topmost one covering the point (inside a stroke's painted width or a fill's coverage, never an eraser stroke), and only when none covers it does one within 5 pt of the point count, so a thin line is still easy to take (`markedit::pick`); when no layer shows paint there, the topmost mark within those 5 pt on any of the layers is taken. A shift click adds or removes on the active layer, a dragged loop picks every stroke whose samples are all inside it and every fill whose pixels are, shift adds or toggles. With "a lasso cuts strokes at its edge" (on by default) the loop also takes the parts of strokes and fills crossing it: the selection shows the dashed lasso and the parts that will move, and the first edit (move, recolour, delete, ...) writes one `lasso` op that splits them, after which the selection is the moved marks. The selection shows as thin lines and a box with corner handles (uniform scale), edge handles (stretch one axis; dragging past the other edge flips) and a rotate knob; dragging moves it on the GPU (the selected marks drawn alone, over the cel replayed without them) and release writes one `transform` or `lasso` op. Layer settings recolour (the current colour), makes thinner or thicker, sets opacity, flips left-right or up-down and deletes, each as one history step. The selection is shared with the agent as addresses.
- Layers (M2 batch 4): layer settings sets clip to the layer below and lock alpha, adds a mask (empty, or hiding all), turns it on and off, removes it, and "paint on the mask" makes the mask the active layer (it also has its own row under its layer). Painting on a mask hides the layer under the strokes; the eraser shows it again. While a mask is active, what it hides is tinted red ("show the mask in red", on by default), and the brush panel says whether the brush or the eraser is on. The brush and fill tools record lock alpha from the active layer.