Add the canvas engine and a canvas playground example
The canvas draws a frame in three steps. Scene::build works out what's shown and where: folding decides which nodes show, boxes are sized from their wrapped titles (with tags and a +N badge in the bottom border), the camera turns canvas positions into screen cells, and every branch and cross-link gets a right-angle route. The line layer records which arms meet in each cell, so borders and lines join with the right box-drawing character (├ ┼ ┨ ╭), in any mix of light, thick, double, dashed and dotted. Rendering then writes lines, arrowheads and labels, and the nodes on top. Branches leave sideways and bend near their parent, so siblings share one bus; cross-links take the wider gap and carry their label on the longest level run. Far zoom keeps the full width and halves the height (one line per node), Overview shows dots. hjkl picks the nearest node within 45° of the direction, and new nodes find a free spot next to their parent or sibling. The theme works out looks in layers (default, tag style, named style, the node's own), with a mid-tone palette for dark and light terminals, and an ASCII fallback for fonts without box drawing. `cargo run --example canvas` opens a sample document to move around, zoom, fold, edit and drag with the mouse. The tests compare rendered text against the DESIGN.md mockup. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
69aa7eee58
commit
3b58d6494d
23 files changed
+3641
-7
No files matched your search
+65
-1
@@ -1,4 +1,4 @@
|
||||
//! Places on the canvas.
|
||||
//! Places and sizes on the canvas.
|
||||
//!
|
||||
//! The canvas is a grid of terminal cells (at Normal zoom) with no edges, so
|
||||
//! coordinates can be negative. `x` grows to the right and `y` downward, as in
|
||||
@@ -64,3 +64,67 @@ impl Neg for CanvasOffset {
|
||||
CanvasOffset::new(-self.dx, -self.dy)
|
||||
}
|
||||
}
|
||||
|
||||
/// A width and a height on the canvas, in cells.
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
pub struct CanvasSize {
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
}
|
||||
|
||||
impl CanvasSize {
|
||||
/// A size of `width` by `height` cells.
|
||||
pub const fn new(width: u16, height: u16) -> CanvasSize {
|
||||
CanvasSize { width, height }
|
||||
}
|
||||
}
|
||||
|
||||
/// A rectangle on the canvas: its top-left corner and its size.
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
pub struct CanvasRect {
|
||||
pub pos: CanvasPos,
|
||||
pub size: CanvasSize,
|
||||
}
|
||||
|
||||
impl CanvasRect {
|
||||
/// The rectangle with its top-left corner at `pos`.
|
||||
pub const fn new(pos: CanvasPos, size: CanvasSize) -> CanvasRect {
|
||||
CanvasRect { pos, size }
|
||||
}
|
||||
|
||||
/// The first column inside.
|
||||
pub fn left(self) -> i32 {
|
||||
self.pos.x
|
||||
}
|
||||
|
||||
/// The first row inside.
|
||||
pub fn top(self) -> i32 {
|
||||
self.pos.y
|
||||
}
|
||||
|
||||
/// The first column past the right edge.
|
||||
pub fn right(self) -> i32 {
|
||||
self.pos.x + i32::from(self.size.width)
|
||||
}
|
||||
|
||||
/// The first row past the bottom edge.
|
||||
pub fn bottom(self) -> i32 {
|
||||
self.pos.y + i32::from(self.size.height)
|
||||
}
|
||||
|
||||
/// The middle cell (rounded toward the top left).
|
||||
pub fn center(self) -> CanvasPos {
|
||||
CanvasPos::new(
|
||||
self.pos.x + i32::from(self.size.width) / 2,
|
||||
self.pos.y + i32::from(self.size.height) / 2,
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether the two rectangles share at least one cell.
|
||||
pub fn overlaps(self, other: CanvasRect) -> bool {
|
||||
self.left() < other.right()
|
||||
&& other.left() < self.right()
|
||||
&& self.top() < other.bottom()
|
||||
&& other.top() < self.bottom()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user