Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
73b1278
feat(ui): colour icons for Paste and other ribbon controls
alientechsw Nov 29, 2026
8391410
feat(i18n): translate the page template names and categories
alientechsw Nov 29, 2026
3bea87e
feat(ui): page thumbnails in the Templates pane
alientechsw Nov 29, 2026
397d313
feat(ui): language button shows a globe and the code
alientechsw Nov 29, 2026
6644e6a
feat(ui): Fluent icons for Cut, Copy and Format Painter
alientechsw Nov 29, 2026
9971122
docs(demo): page templates page in all 14 languages
alientechsw Nov 29, 2026
290b977
feat(ui): colour Paste icon in the How to paste menu
alientechsw Nov 29, 2026
043bcb7
feat(ui): template thumbnail cards that wrap with the pane
alientechsw Nov 29, 2026
eeebe05
feat(ui): colour icons for Equation, Symbol, Diagram and Sticker
alientechsw Nov 29, 2026
385c4d0
feat(templates): colour page templates
alientechsw Nov 29, 2026
1eb08ea
feat(templates): picture background templates
alientechsw Nov 29, 2026
89c65a3
feat(templates): margin pictures, real thumbnails, exact page colours
alientechsw Nov 29, 2026
a4ced25
Merge origin/main into feat/page-templates/agent-2
alientechsw Nov 29, 2026
537b77d
feat(ui): Set Picture as Background, and the demo page that shows it
alientechsw Nov 29, 2026
a8b09ad
feat(model): a box can be the page background
alientechsw Nov 29, 2026
1c01d7f
feat(templates): LTR and RTL margin pictures, and the picture repeat fix
alientechsw Nov 29, 2026
189a82c
chore(model): assert a bool directly in the container test
alientechsw Nov 29, 2026
7371258
fix(templates): saved previews, RTL checks, bidi names, focus
alientechsw Nov 29, 2026
02a7fc2
feat(ui): Set Picture as Background toggles a box
alientechsw Nov 29, 2026
e1150d6
test(model): the background toggle is a tested function
alientechsw Nov 29, 2026
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
3 changes: 2 additions & 1 deletion ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ data.
specifications. No Microsoft text or code is included.

| \crates/ui-egui/assets/fluent/*.svg\ | Selected Fluent UI System Icons used by the ribbon | Microsoft Fluent UI System Icons, MIT licensed; source: https://github.com/microsoft/fluentui-system-icons | Microsoft Corporation and contributors |
| \crates/ui-egui/assets/fluent-color/*.svg\ | Selected Fluent UI System Icons colour versions (calendar, clock, link, image, table, video, mic, document) used by the ribbon | Microsoft Fluent UI System Icons, MIT licensed; source: https://github.com/microsoft/fluentui-system-icons (`assets/<Name>/SVG/ic_fluent_<name>_24_color.svg`) | Microsoft Corporation and contributors |
| \crates/ui-egui/assets/fluent-color/*.svg\ | Selected Fluent UI System Icons colour versions (calendar, clock, link, image, table, video, mic, document, notebook, code, lock closed, question circle, clipboard) used by the ribbon | Microsoft Fluent UI System Icons, MIT licensed; source: https://github.com/microsoft/fluentui-system-icons (`assets/<Name>/SVG/ic_fluent_<name>_24_color.svg`) | Microsoft Corporation and contributors |
| \crates/ui-egui/assets/notecraft-color/*.svg\ | Colour icons used by the ribbon that Fluent has no colour version of: pen, unlocked padlock, equation, symbol, diagram and sticker. Drawn for NoteCraft in the same 24px style | Drawn for this project | The project's own work, under its MIT OR Apache-2.0 licence |

## OCR demo pictures

Expand Down
4 changes: 2 additions & 2 deletions crates/formats/tests/format_parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn the_full_demo_notebooks_have_matching_pages_and_blocks() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("..").join("docs").join("demo").join("DemoNotebook");
let html = pages(&root.join("html"));
let cmgfm = pages(&root.join("cmgfm"));
// The demo has 240 base pages, 182 OCR pages (13 per language with OCR content), and a menus page in each of its 14 languages.
assert_eq!(html.len(), 436, "expected every page from the 14-language demo");
// The demo has 268 base pages (including the Page templates and Page background pages in each of its 14 languages), 182 OCR pages (13 per language with OCR content), and a menus page in each of its 14 languages.
assert_eq!(html.len(), 464, "expected every page from the 14-language demo");
assert_eq!(html.len(), cmgfm.len(), "both notebooks must have the same number of pages");
assert_eq!(html.keys().collect::<Vec<_>>(), cmgfm.keys().collect::<Vec<_>>(), "page paths must match");
for language in ["10-en", "11-es", "12-fr", "13-de", "14-hi", "15-ru", "16-zh", "17-ja", "18-ko", "19-tr", "20-ar", "21-fa", "22-ur", "23-he"] {
Expand Down
93 changes: 88 additions & 5 deletions crates/model/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ pub struct Container {
pub width: f32,
/// How many of the page's blocks, in order, are in this box.
pub blocks: usize,
/// Whether this box is the page's background (Set Picture as Background): its picture is
/// drawn behind the page, where a normal click does not reach it. Cleared, the box is an
/// ordinary one again, in the same place.
pub background: bool,
}

/// The narrowest a container may be, so one cannot be dragged into nothing.
pub const MIN_WIDTH: f32 = 120.0;

impl Container {
pub fn new(x: f32, y: f32, width: f32, blocks: usize) -> Container {
Container { x: x.max(0.0), y: y.max(0.0), width: width.max(MIN_WIDTH), blocks }
Container { x: x.max(0.0), y: y.max(0.0), width: width.max(MIN_WIDTH), blocks, background: false }
}
}

/// Reads the line a page keeps its containers on: `x,y,width,blocks` per box, separated by
/// semicolons. Anything that does not parse is skipped rather than guessed at.
/// Reads the line a page keeps its containers on: `x,y,width,blocks[,background]` per box,
/// separated by semicolons. The fifth field is `1` for a background box and is left out
/// otherwise, so a page without one reads and writes as it always did. Anything that does not
/// parse is skipped rather than guessed at.
pub fn parse(text: &str) -> Vec<Container> {
text.split(';')
.filter_map(|part| {
Expand All @@ -44,10 +50,16 @@ pub fn parse(text: &str) -> Vec<Container> {
let y: f32 = fields.next()?.parse().ok()?;
let width: f32 = fields.next()?.parse().ok()?;
let blocks: usize = fields.next()?.parse().ok()?;
let background = match fields.next() {
None => false,
Some("1") => true,
Some("0") => false,
Some(_) => return None,
};
if fields.next().is_some() || !x.is_finite() || !y.is_finite() || !width.is_finite() {
return None;
}
Some(Container::new(x, y, width, blocks))
Some(Container { background, ..Container::new(x, y, width, blocks) })
})
.collect()
}
Expand All @@ -57,11 +69,44 @@ pub fn parse(text: &str) -> Vec<Container> {
pub fn write(containers: &[Container]) -> String {
containers
.iter()
.map(|c| format!("{},{},{},{}", c.x.round() as i64, c.y.round() as i64, c.width.round() as i64, c.blocks))
.map(|c| {
let base = format!("{},{},{},{}", c.x.round() as i64, c.y.round() as i64, c.width.round() as i64, c.blocks);
if c.background { format!("{base},1") } else { base }
})
.collect::<Vec<_>>()
.join("; ")
}

/// What Set Picture as Background did to a box.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BackgroundChange {
/// The box is now the page's background.
Set,
/// The box is an ordinary box again.
Cleared,
/// The box holds more than its picture, so it cannot be the background: the words and other
/// blocks in it would be hidden. Nothing changed.
NeedsOwnBox,
/// The block is not in any box. Nothing changed.
NoBox,
}

/// Set Picture as Background, toggled for the box that holds `block` (the picture). A box that
/// is the background is cleared; any other box becomes one, if it holds only its picture.
pub fn toggle_background(boxes: &mut [Container], block: usize) -> BackgroundChange {
let Some((at, _)) = place(boxes, block) else { return BackgroundChange::NoBox };
let b = &mut boxes[at];
if b.background {
b.background = false;
BackgroundChange::Cleared
} else if b.blocks != 1 {
BackgroundChange::NeedsOwnBox
} else {
b.background = true;
BackgroundChange::Set
}
}

/// The containers to use for a page with `blocks` blocks in it.
///
/// This is where honesty about a count-based layer lives. If the containers account for
Expand Down Expand Up @@ -145,6 +190,16 @@ mod tests {
assert_eq!(parse(&line), boxes);
}

#[test]
fn a_background_box_keeps_its_flag_and_an_ordinary_one_keeps_its_line() {
let back = Container { background: true, ..Container::new(10.0, 20.0, 300.0, 1) };
let line = write(&[back, Container::new(0.0, 0.0, 420.0, 2)]);
assert_eq!(line, "10,20,300,1,1; 0,0,420,2", "only a background box carries the extra field");
assert_eq!(parse(&line), vec![back, Container::new(0.0, 0.0, 420.0, 2)]);
assert!(!parse("1,2,3,4,0")[0].background);
assert!(parse("1,2,3,4,yes").is_empty(), "the flag is 1 or 0, nothing else");
}

#[test]
fn nonsense_is_skipped_not_guessed_at() {
assert!(parse("").is_empty());
Expand Down Expand Up @@ -182,6 +237,34 @@ mod tests {
assert_eq!(fit(&[Container::new(0.0, 0.0, 400.0, 0)], 0, 700.0).len(), 1);
}

#[test]
fn set_picture_as_background_toggles_a_box_that_holds_only_its_picture() {
let mut boxes = vec![Container::new(0.0, 0.0, 300.0, 1), Container::new(400.0, 0.0, 300.0, 2)];
// The first box holds one block, its picture: it becomes the background, and keeps its place.
assert_eq!(toggle_background(&mut boxes, 0), BackgroundChange::Set);
assert!(boxes[0].background);
assert_eq!((boxes[0].x, boxes[0].y, boxes[0].width), (0.0, 0.0, 300.0));
// Choosing it again clears it: an ordinary box, still in the same place.
assert_eq!(toggle_background(&mut boxes, 0), BackgroundChange::Cleared);
assert!(!boxes[0].background);
assert_eq!((boxes[0].x, boxes[0].y), (0.0, 0.0));
}

#[test]
fn a_box_with_words_in_it_cannot_become_the_background() {
// Block 1 shares its box with block 2: making the box a background would hide the words.
let mut boxes = vec![Container::new(0.0, 0.0, 300.0, 1), Container::new(400.0, 0.0, 300.0, 2)];
assert_eq!(toggle_background(&mut boxes, 1), BackgroundChange::NeedsOwnBox);
assert!(boxes.iter().all(|c| !c.background), "nothing changed");
}

#[test]
fn a_block_in_no_box_changes_nothing() {
let mut boxes = vec![Container::new(0.0, 0.0, 300.0, 1)];
assert_eq!(toggle_background(&mut boxes, 9), BackgroundChange::NoBox);
assert!(!boxes[0].background);
}

#[test]
fn a_block_knows_which_box_it_is_in() {
let boxes = vec![Container::new(0.0, 0.0, 400.0, 2), Container::new(420.0, 0.0, 200.0, 3)];
Expand Down
45 changes: 44 additions & 1 deletion crates/store/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,16 @@ pub fn appearance(dir: &Path) -> Result<(Option<String>, Option<String>)> {
.map(|v| v.trim().to_string())
.filter(|v| !v.is_empty())
};
Ok((read(PAPER_META, PAPER_KEY), read(COLOUR_META, COLOUR_KEY)))
// A hex colour is written without its `#` (in front matter a `#` starts a comment), so it is
// given back with one.
let colour = read(COLOUR_META, COLOUR_KEY).map(|c| if c.len() == 6 && c.chars().all(|x| x.is_ascii_hexdigit()) { format!("#{c}") } else { c });
Ok((read(PAPER_META, PAPER_KEY), colour))
}

/// Writes them into the page's own file. `None` takes the line out again.
pub fn set_appearance(dir: &Path, paper: Option<&str>, colour: Option<&str>) -> Result<()> {
// A hex colour is written without its `#`: see `appearance`.
let colour = colour.map(|c| c.trim_start_matches('#'));
let writer = crate::coordination::page_writer(dir)?;
let _guard = writer.lock().map_err(|_| StoreError::invalid("the page writer is unavailable"))?;
let (format, file) = page_file(dir).ok_or_else(|| StoreError::NotFound(format!("{} is not a page", dir.display())))?;
Expand Down Expand Up @@ -800,6 +805,44 @@ pub fn set_appearance(dir: &Path, paper: Option<&str>, colour: Option<&str>) ->
write_atomic(&file, &out)
}

const BACKGROUND_KEY: &str = "background";
const BACKGROUND_META: &str = "notecraft:background";

/// The background picture a page is drawn over, as it is written (a name such as `leaves`), or
/// `None` when the page has none.
pub fn background(dir: &Path) -> Result<Option<String>> {
let (format, file) = page_file(dir).ok_or_else(|| StoreError::NotFound(format!("{} is not a page", dir.display())))?;
let text = fs::read_to_string(&file).map_err(|e| StoreError::io("read", &file, e))?;
let raw = match format {
PageFormat::Html => html::meta(&text, BACKGROUND_META),
PageFormat::Cmgfm => frontmatter::value(&frontmatter::split_front(&text).0, BACKGROUND_KEY),
};
Ok(raw.map(|v| v.trim().to_string()).filter(|v| !v.is_empty()))
}

/// Writes the background picture into the page's own file. `None` takes the line out again.
pub fn set_background(dir: &Path, name: Option<&str>) -> Result<()> {
let writer = crate::coordination::page_writer(dir)?;
let _guard = writer.lock().map_err(|_| StoreError::invalid("the page writer is unavailable"))?;
let (format, file) = page_file(dir).ok_or_else(|| StoreError::NotFound(format!("{} is not a page", dir.display())))?;
let text = fs::read_to_string(&file).map_err(|e| StoreError::io("read", &file, e))?;
if read_only_in(format, &text) {
return Err(StoreError::invalid("this page is locked read only"));
}
let out = match format {
PageFormat::Html => html::set_meta(&text, BACKGROUND_META, name.unwrap_or_default()),
PageFormat::Cmgfm => {
let (front, rest) = frontmatter::split_front(&text);
let front = match name {
Some(n) => frontmatter::set_value(&front, BACKGROUND_KEY, n),
None => frontmatter::remove_value(&front, BACKGROUND_KEY),
};
format!("{front}{rest}")
}
};
write_atomic(&file, &out)
}

const RULES_KEY: &str = "rule-color";
const RULES_META: &str = "notecraft:rule-color";

Expand Down
Loading
Loading