From 9ba5d1fbf6a845530464655298216d8d7b41485b Mon Sep 17 00:00:00 2001 From: DWAA1660 Date: Tue, 17 Nov 2026 15:10:42 -0700 Subject: [PATCH] feat(draw): auto shapes, ink replay, section tabs, text colours - Draw > Automatic Shapes (#294): when on, a hand-drawn line, rectangle, ellipse or triangle is redrawn clean on pen lift. Strict recognition (notecraft_ink::recognise), checked against the Welcome notebook's real strokes; one Undo restores the hand stroke. The setting is kept. - Draw > Ink Replay (#295): replays the page's strokes in their saved order at an even speed, with play/pause, restart, step and speed. It never changes the drawing or undo. - View > Tabs layout (#268, #33): the notebook's sections as coloured tabs over the page; a group is a tab with a list. - Home > Font Colour and Text Highlight Colour (#260): exact #rrggbb colours on the selection or next typing, kept in HTML and CMGFM as span color / background-color, readable on every theme. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Y4im4nDYbxmtByUCBaBzNq --- crates/formats/src/boxes.rs | 6 +- crates/formats/src/html.rs | 22 ++- crates/formats/src/markdown.rs | 81 ++++++-- crates/formats/src/render.rs | 38 ++++ crates/ink/src/lib.rs | 1 + crates/ink/src/recognise.rs | 286 +++++++++++++++++++++++++++++ crates/ink/src/shapes.rs | 6 + crates/ink/tests/recognise_demo.rs | 36 ++++ crates/ui-egui/src/app.rs | 139 ++++++++++++++ crates/ui-egui/src/inkpad.rs | 166 ++++++++++++++++- crates/ui-egui/src/lib.rs | 3 + crates/ui-egui/src/pageedit.rs | 19 +- crates/ui-egui/src/pagetext.rs | 47 ++++- crates/ui-egui/src/preview.rs | 8 +- crates/ui-egui/src/replay.rs | 206 +++++++++++++++++++++ crates/ui-egui/src/ribbon.rs | 125 +++++++++++-- crates/ui-egui/src/sectiontabs.rs | 170 +++++++++++++++++ crates/ui-egui/src/textcolour.rs | 96 ++++++++++ crates/ui-egui/tests/ui.rs | 249 +++++++++++++++++++++++++ docs/gaps.md | 24 ++- i18n/ar-XB.tsv | 51 +++++ i18n/en-XA.tsv | 51 +++++ i18n/en.tsv | 51 +++++ 23 files changed, 1837 insertions(+), 44 deletions(-) create mode 100644 crates/ink/src/recognise.rs create mode 100644 crates/ink/tests/recognise_demo.rs create mode 100644 crates/ui-egui/src/replay.rs create mode 100644 crates/ui-egui/src/sectiontabs.rs create mode 100644 crates/ui-egui/src/textcolour.rs diff --git a/crates/formats/src/boxes.rs b/crates/formats/src/boxes.rs index 9173fd52..e7e04acc 100644 --- a/crates/formats/src/boxes.rs +++ b/crates/formats/src/boxes.rs @@ -303,7 +303,11 @@ fn styled_spans_in(block: &Block) -> usize { Block::Table { head, rows } => head.iter().chain(rows.iter().flatten()).collect(), Block::Code { .. } | Block::MathBlock(_) | Block::Rule | Block::Image { .. } => Vec::new(), }; - lines.iter().flat_map(|spans| spans.iter()).filter(|span| span.font_size.is_some() || span.font_family.is_some()).count() + lines + .iter() + .flat_map(|spans| spans.iter()) + .filter(|span| span.font_size.is_some() || span.font_family.is_some() || span.colour.is_some() || span.highlight.is_some()) + .count() } #[cfg(test)] diff --git a/crates/formats/src/html.rs b/crates/formats/src/html.rs index 602ab6f1..f79de27a 100644 --- a/crates/formats/src/html.rs +++ b/crates/formats/src/html.rs @@ -330,6 +330,15 @@ fn font_size(attrs: &str) -> Option { }) } +/// The text colour or highlight of an HTML span, when it is a colour NoteCraft writes (#260). +fn span_colour(attrs: &str, wanted: &str) -> Option { + let style = attr(attrs, "style")?; + crate::markdown::style_declarations(&style).into_iter().find_map(|declaration| { + let (property, value) = declaration.split_once(':')?; + property.trim().eq_ignore_ascii_case(wanted).then(|| crate::markdown::css_colour(value)).flatten() + }) +} + fn font_family(attrs: &str) -> Option { let style = attr(attrs, "style")?; crate::markdown::style_declarations(&style).into_iter().find_map(|declaration| { @@ -603,8 +612,11 @@ impl Writer { ("span", false) => { let size = font_size(attrs); let family = font_family(attrs); - self.span_sizes.push(size.is_some() || family.is_some()); - if size.is_some() || family.is_some() { + let colour = span_colour(attrs, "color"); + let highlight = span_colour(attrs, "background-color"); + let styled = size.is_some() || family.is_some() || colour.is_some() || highlight.is_some(); + self.span_sizes.push(styled); + if styled { let mut styles = Vec::new(); if let Some(family) = family { styles.push(format!("font-family: {}", escape(&crate::markdown::font_family_css(&family)))); @@ -612,6 +624,12 @@ impl Writer { if let Some(size) = size { styles.push(format!("font-size: {size}pt")); } + if let Some(colour) = colour { + styles.push(format!("color: {colour}")); + } + if let Some(colour) = highlight { + styles.push(format!("background-color: {colour}")); + } self.push(&format!("", styles.join("; "))); } if attrs.to_lowercase().contains("math") { diff --git a/crates/formats/src/markdown.rs b/crates/formats/src/markdown.rs index 42f8b7cf..7b850045 100644 --- a/crates/formats/src/markdown.rs +++ b/crates/formats/src/markdown.rs @@ -21,6 +21,10 @@ pub struct Span { /// Font size in points, carried by a NoteCraft inline ``. pub font_size: Option, pub font_family: Option, + /// Text colour, as `#rrggbb`, from a NoteCraft inline `` (#260). + pub colour: Option, + /// Highlight behind the text, as `#rrggbb`, from `background-color` (#260). + pub highlight: Option, /// Link target, if this span is part of a link. pub link: Option, /// Image source, if this span is an inline image (the text is the alt text). @@ -69,6 +73,8 @@ struct Style { script: Option