Merge main into 3498

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-07 21:08:48 +01:00
commit b6ab68ea3b
17 files changed
+5560 -84

No files matched your search

+1
View File
@@ -38,6 +38,7 @@ next to them.
| `crates/ui-egui/src/i18n/ro.tsv` | Romanian UI translations | @tronicum with Claude Code, AI-assisted (machine-translated); not yet reviewed by a native speaker | Original translations of PhotoCraft's English labels | MIT OR Apache-2.0, [`LICENSE-translations.txt`](crates/ui-egui/src/i18n/LICENSE-translations.txt) |
| `crates/ui-egui/src/i18n/th.tsv` | Thai UI translations | @Thanawatttt and PhotoCraft contributors, with opencode (DeepSeek) as an AI contributor | Machine-assisted first draft from PhotoCraft's English labels, reviewed for UI terminology | MIT OR Apache-2.0, [`LICENSE-translations.txt`](crates/ui-egui/src/i18n/LICENSE-translations.txt) |
| `crates/ui-egui/src/i18n/ta.tsv` | Tamil UI translations | @newsbaba24x7 and PhotoCraft contributors | Original translations of PhotoCraft's English labels | MIT OR Apache-2.0, [`LICENSE-translations.txt`](crates/ui-egui/src/i18n/LICENSE-translations.txt) |
| `crates/ui-egui/src/i18n/ka.tsv` | Georgian UI translations | @devius with Claude Code, AI-assisted | Original translations of PhotoCraft's English labels | MIT OR Apache-2.0, [`LICENSE-translations.txt`](crates/ui-egui/src/i18n/LICENSE-translations.txt) |
| `epaint_default_fonts::EGUI_ICONS` (build input; deflated into `OUT_DIR/egui_fonts/egui-icons.ttf.deflate`, registered by `crates/ui-egui/src/egui_fonts.rs`) | egui-icons, five-glyph subset of emoji-icon-font | John Slegers | [egui fork at 6d518fc](https://github.com/storytold/egui/tree/6d518fc799681571963842f95b55a6b68431b15a/crates/epaint_default_fonts/fonts), [original](https://github.com/jslegers/emoji-icon-font); egui subset, unmodified here | MIT; Copyright (c) 2014 John Slegers; full upstream notice in [NOTICE](NOTICE) |
| `assets/fonts/Inter-Regular.ttf`, `Inter-Medium.ttf`, `Inter-SemiBold.ttf` | Inter 4.001 (UI font) | The Inter Project Authors (Rasmus Andersson) | <https://github.com/rsms/inter> | SIL OFL 1.1, [`assets/fonts/OFL-Inter.txt`](assets/fonts/OFL-Inter.txt) |
| `assets/fonts/JetBrainsMono-Regular.ttf` | JetBrains Mono 2.305 (numeric font) | The JetBrains Mono Project Authors | <https://github.com/JetBrains/JetBrainsMono> | SIL OFL 1.1, [`assets/fonts/OFL-JetBrainsMono.txt`](assets/fonts/OFL-JetBrainsMono.txt) |
+41 -2
View File
@@ -18,13 +18,17 @@ pub fn document_area(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
crate::brush_mode_menu::show(app, ui.ctx());
}
/// Where each docked document is drawn under Window › Arrange: its index and the cell it gets,
/// at the border positions the user has dragged them to. `None` with no docked document, or when
/// the arrangement is the plain single canvas. With more documents than the layout has cells, the
/// shown run starts at [`PhotocraftApp::arrange_start`] and always includes the active one.
pub(crate) fn arranged_cells(app: &PhotocraftApp, rect: Rect) -> Option<Vec<(usize, Rect)>> {
let documents = docked_document_indices(app);
let n = documents.len();
if n == 0 {
return None;
}
let cells = crate::view_cmds::cells(&app.ui.view.arrange, rect, n)?;
let cells = crate::view_cmds::cells(&app.ui.view.arrange, rect, n, &app.ui.view.arrange_splits)?;
// Keep stable tiles, expressing the remembered document index in the filtered docked list.
let start = documents.partition_point(|&d| d < app.arrange_start).min(n.saturating_sub(cells.len()));
let idx = app.session.active_index().and_then(|d| documents.iter().position(|&p| p == d));
@@ -109,19 +113,27 @@ fn documents(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
if let Some(shown) = arranged_cells(app, rect) {
app.arrange_start = shown.first().map_or(0, |(d, _)| *d);
let t = crate::theme::Tokens::get(ui.ctx());
// A press on a border grip drags the border (`drag_borders`); it activates no document.
// The grips are laid out after the canvases, so egui gives them the press (#10101).
let grips: Vec<Rect> = border_grips(app, rect).into_iter().map(|(_, grip)| grip).collect();
for (d, cell) in shown {
let cell = cell.shrink(1.0);
let view = app.ui.views[d].clone();
let v = canvas_view(app, ui, d, cell, view, d == active_doc);
if d != active_doc {
app.ui.views[d] = v;
if main_focused && ui.input(|i| i.pointer.primary_pressed() && i.pointer.interact_pos().is_some_and(|p| cell.contains(p))) {
if main_focused
&& ui.input(|i| {
i.pointer.primary_pressed() && i.pointer.interact_pos().is_some_and(|p| cell.contains(p) && !grips.iter().any(|g| g.contains(p)))
})
{
app.session.set_active(d);
}
}
let stroke = if d == active_doc { Stroke::new(1.5, t.accent) } else { Stroke::new(1.0, Color32::from_black_alpha(160)) };
ui.painter().rect_stroke(cell, 0, stroke, egui::StrokeKind::Inside);
}
drag_borders(app, ui, rect);
return;
}
if idx != active_doc && main_focused && ui.input(|i| i.pointer.primary_pressed() && i.pointer.interact_pos().is_some_and(|p| rect.contains(p))) {
@@ -131,6 +143,33 @@ fn documents(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
canvas_view(app, ui, idx, rect, view, app.session.active_index() == Some(idx));
}
/// Window › Arrange: the borders between the documents are dragged to give one more room, as in
/// Photoshop (#10101). Laid out after the canvases, so a grip over a cell's edge takes the press.
fn drag_borders(app: &mut PhotocraftApp, ui: &egui::Ui, rect: Rect) {
let n = docked_document_indices(app).len();
let layout = app.ui.view.arrange.clone();
for (border, grip) in border_grips(app, rect) {
let response = ui.interact(grip, ui.scope_id().with(("arrange-border", border.split)), Sense::drag());
if response.hovered() || response.dragged() {
ui.ctx().set_cursor_icon(if border.vertical { egui::CursorIcon::ResizeHorizontal } else { egui::CursorIcon::ResizeVertical });
}
if response.dragged()
&& let Some(p) = response.interact_pointer_pos()
{
crate::view_cmds::drag_border(&layout, rect, n, &mut app.ui.view.arrange_splits, border.split, p);
}
}
}
/// The arrangement's borders, each with the strip either side of it that grabs it.
fn border_grips(app: &PhotocraftApp, rect: Rect) -> Vec<(crate::view_cmds::Border, Rect)> {
let n = docked_document_indices(app).len();
crate::view_cmds::borders(&app.ui.view.arrange, rect, n, &app.ui.view.arrange_splits)
.into_iter()
.map(|b| (b, b.line.expand2(if b.vertical { egui::vec2(3.0, 0.0) } else { egui::vec2(0.0, 3.0) })))
.collect()
}
/// The tab strip; returns where its document tabs are.
pub(super) fn tabs(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> TabStrip {
let t = crate::theme::Tokens::get(ui.ctx());
+3 -1
View File
@@ -216,7 +216,7 @@ fn expand(packed: &str, keys: &[&str]) -> Result<String, String> {
}
/// The registry. English first: it is the fallback and the source language.
pub static LANGUAGES: [LangInfo; 34] = [
pub static LANGUAGES: [LangInfo; 35] = [
LangInfo { code: "en", name: "English", source: b"", plural: plural_one_other, complete_menus: false, catalog: OnceLock::new() },
LangInfo { code: "ja", name: "日本語", source: catalog!("ja"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
LangInfo { code: "zh-hans", name: "简体中文", source: catalog!("zh-hans"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
@@ -284,6 +284,8 @@ pub static LANGUAGES: [LangInfo; 34] = [
LangInfo { code: "ro", name: "Română", source: catalog!("ro"), plural: plural_romanian, complete_menus: true, catalog: OnceLock::new() },
// Tamil; `ta-IN`, `ta-LK` and `ta_IN.UTF-8` resolve here. CLDR plural: one|other.
LangInfo { code: "ta", name: "தமிழ்", source: catalog!("ta"), plural: plural_one_other, complete_menus: true, catalog: OnceLock::new() },
// Georgian: nouns stay singular after a numeral (`შრე: 5`, `5 შრე`), so one form serves every count.
LangInfo { code: "ka", name: "ქართული", source: catalog!("ka"), plural: plural_none, complete_menus: true, catalog: OnceLock::new() },
];
impl LangInfo {
File diff suppressed because it is too large. Load diff
+1
View File
@@ -172,6 +172,7 @@ mod tests {
(vec!["nb-NO", "en-US"], "nb"),
(vec!["nn_NO.UTF-8", "en-US"], "nb"),
(vec!["is-IS", "no-NO"], "nb"),
(vec!["ka-GE", "ru-RU"], "ka"),
(vec![], "en"),
] {
with_system_tags(&tags, || assert_eq!(system_lang().code(), expected));
+15
View File
@@ -7,6 +7,7 @@ const CS: fn() -> Lang = || Lang::from_code("cs").expect("cs registered");
const ID: fn() -> Lang = || Lang::from_code("id").expect("id registered");
const VI: fn() -> Lang = || Lang::from_code("vi").expect("vi registered");
const HI: fn() -> Lang = || Lang::from_code("hi").expect("hi registered");
const KA: fn() -> Lang = || Lang::from_code("ka").expect("ka registered");
#[test]
fn hindi_has_the_reveal_and_camera_raw_rows() {
@@ -28,6 +29,20 @@ fn hindi_tags_resolve() {
assert_eq!(Lang::from_pref("HI"), HI());
}
#[test]
fn georgian_tags_resolve() {
for tag in ["ka", "ka-GE", "ka_GE", "ka_GE.UTF-8"] {
assert_eq!(lang_from_tag(tag), Some(KA()), "{tag}");
}
assert_eq!(KA().name(), "ქართული");
assert_eq!(Lang::from_pref("ka"), KA());
assert_eq!(Lang::from_pref("KA"), KA());
assert_eq!(tr(KA(), "Layer"), "შრე");
assert_eq!(tr(KA(), "File"), "ფაილი");
assert_eq!(trn(KA(), 1, "{n} layer", "{n} layers"), "შრე: 1");
assert_eq!(trn(KA(), 3, "{n} layer", "{n} layers"), "შრე: 3");
}
#[test]
fn indonesian_tags_resolve() {
for tag in ["id", "id-ID", "id_ID", "id_ID.UTF-8"] {
+5 -1
View File
@@ -18,7 +18,7 @@ mod dialogs;
mod dispatch;
mod options;
pub use arrange::cells;
pub use arrange::{Border, borders, cells, drag_border};
pub(crate) use arrange::{document_is_floating, float_window};
pub(crate) use dialogs::write_copy;
#[cfg(test)]
@@ -106,6 +106,9 @@ pub struct ViewOptions {
pub pixel_art_preview: bool,
/// Window › Arrange layout of the document area: "tabs" or a tile/n-up layout id.
pub arrange: String,
/// Where the borders between arranged documents were dragged (#10101): fractions of the
/// area, column borders then row borders; empty (or not fitting the layout) is even cells.
pub arrange_splits: Vec<f32>,
/// Type › Font Preview Size: "small" | "medium" | "large" | "extraLarge" | "huge".
pub font_preview_size: String,
/// Type › Language Options: "defaultFeatures" | "eastAsianFeatures" | "middleEasternFeatures",
@@ -138,6 +141,7 @@ impl Default for ViewOptions {
pattern_preview: false,
pixel_art_preview: false,
arrange: "tabs".into(),
arrange_splits: Vec::new(),
font_preview_size: "medium".into(),
language_features: "defaultFeatures".into(),
middle_eastern_composer: false,
+163 -37
View File
@@ -48,9 +48,14 @@ pub(crate) fn float_window(app: &mut PhotocraftApp, doc: usize, offset: usize, f
wid
}
/// The Window › Arrange items: a layout (2-up, 4-up, Tiled…), which starts from even cells and
/// refits every document, or one of the window commands beside them — Consolidate All to Tabs,
/// New Window, Float in Window, Float All in Windows, Match Zoom and the rest.
pub(super) fn arrange(app: &mut PhotocraftApp, k: &str, p: &Value) -> Result<Value, String> {
if LAYOUTS.contains(&k) {
app.ui.view.arrange = k.to_string();
// A new arrangement starts from even cells.
app.ui.view.arrange_splits.clear();
// Each document fits its new cell.
app.ui.views.iter_mut().for_each(|v| v.fit_pending = true);
return Ok(json!({"arrange": k}));
@@ -137,43 +142,164 @@ pub(crate) fn document_is_floating(app: &PhotocraftApp, doc: usize) -> bool {
app.ui.windows.iter().any(|w| w.open && w.floating && w.document == doc)
}
/// Screen rectangles for `n` documents in an arrangement (`None` = tabs). The active document
/// always gets a cell; n-up layouts show that many documents starting from the active one.
pub fn cells(layout: &str, rect: egui::Rect, n: usize) -> Option<Vec<egui::Rect>> {
use craft_ui::layout::{SplitAxis, SplitSize, split_rect};
if n < 2 || !LAYOUTS.contains(&layout) {
return None;
}
let grid = |cols: usize, rows: usize, count: usize| -> Vec<egui::Rect> {
let (w, h) = (rect.width() / cols as f32, rect.height() / rows as f32);
(0..count.min(cols * rows))
.map(|i| egui::Rect::from_min_size(rect.min + egui::vec2((i % cols) as f32 * w, (i / cols) as f32 * h), egui::vec2(w, h)))
.collect()
};
Some(match layout {
"tileAllVertically" => grid(n, 1, n),
"tileAllHorizontally" => grid(1, n, n),
"twoUpVertical" => {
let panes = split_rect(rect, SplitAxis::Horizontal, SplitSize::Ratio(0.5), 0.0, 0.0)?;
vec![panes.first, panes.second]
}
"twoUpHorizontal" => {
let panes = split_rect(rect, SplitAxis::Vertical, SplitSize::Ratio(0.5), 0.0, 0.0)?;
vec![panes.first, panes.second]
}
"threeUpVertical" => grid(3, 1, 3),
"threeUpHorizontal" => grid(1, 3, 3),
"threeUpStacked" => {
let columns = split_rect(rect, SplitAxis::Horizontal, SplitSize::Ratio(0.5), 0.0, 0.0)?;
let rows = split_rect(columns.second, SplitAxis::Vertical, SplitSize::Ratio(0.5), 0.0, 0.0)?;
vec![columns.first, rows.first, rows.second]
}
"fourUp" => grid(2, 2, 4),
"sixUp" => grid(3, 2, 6),
_ => {
let cols = (n as f32).sqrt().ceil() as usize;
grid(cols, n.div_ceil(cols), n)
/// Screen rectangles for `n` documents in an arrangement (`None` = tabs), with the borders
/// where they were left (`splits`, [`ViewOptions::arrange_splits`](super::ViewOptions)). The
/// active document always gets a cell; n-up layouts show that many documents starting from the
/// active one.
pub fn cells(layout: &str, rect: egui::Rect, n: usize, splits: &[f32]) -> Option<Vec<egui::Rect>> {
let shape = Shape::of(layout, n)?;
let (xs, ys) = shape.lines(rect, splits);
Some(match shape {
Shape::Grid { cols, rows, count } => (0..count.min(cols * rows))
.filter_map(|i| {
let (c, r) = (i % cols, i / cols);
Some(egui::Rect::from_min_max(egui::pos2(*xs.get(c)?, *ys.get(r)?), egui::pos2(*xs.get(c + 1)?, *ys.get(r + 1)?)))
})
.collect(),
// One tall cell on the left; the right column is cut in two.
Shape::Stacked => {
let (x, y) = (xs.get(1).copied().unwrap_or(rect.center().x), ys.get(1).copied().unwrap_or(rect.center().y));
vec![
egui::Rect::from_min_max(rect.min, egui::pos2(x, rect.max.y)),
egui::Rect::from_min_max(egui::pos2(x, rect.min.y), egui::pos2(rect.max.x, y)),
egui::Rect::from_min_max(egui::pos2(x, y), rect.max),
]
}
})
}
/// A border between arranged documents that can be dragged, as in Photoshop (#10101).
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Border {
/// Which of the arrangement's splits it is: the index for [`drag_border`].
pub split: usize,
/// It runs top to bottom (and moves left and right).
pub vertical: bool,
/// Its line on screen: zero wide (or tall) across the cells it divides.
pub line: egui::Rect,
}
/// The borders of an arrangement, as laid out by [`cells`].
pub fn borders(layout: &str, rect: egui::Rect, n: usize, splits: &[f32]) -> Vec<Border> {
let Some(shape) = Shape::of(layout, n) else { return Vec::new() };
let (xs, ys) = shape.lines(rect, splits);
let inner = |v: &[f32]| v.get(1..v.len().saturating_sub(1)).unwrap_or_default().to_vec();
let (inner_x, inner_y) = (inner(&xs), inner(&ys));
let vertical = inner_x.iter().enumerate().map(|(i, &x)| Border {
split: i,
vertical: true,
line: egui::Rect::from_min_max(egui::pos2(x, rect.min.y), egui::pos2(x, rect.max.y)),
});
// 3-up Stacked's row border spans only the right column.
let left = match shape {
Shape::Stacked => inner_x.first().copied().unwrap_or(rect.min.x),
Shape::Grid { .. } => rect.min.x,
};
let horizontal = inner_y.iter().enumerate().map(|(i, &y)| Border {
split: inner_x.len() + i,
vertical: false,
line: egui::Rect::from_min_max(egui::pos2(left, y), egui::pos2(rect.max.x, y)),
});
vertical.chain(horizontal).collect()
}
/// Move border `split` of the arrangement to `pointer` (screen points), keeping every cell at
/// least [`MIN_CELL`] points across where the area allows. `splits` is rewritten in full, so a
/// stale or damaged list starts again from even cells.
pub fn drag_border(layout: &str, rect: egui::Rect, n: usize, splits: &mut Vec<f32>, split: usize, pointer: egui::Pos2) {
let Some(shape) = Shape::of(layout, n) else { return };
let (cols, rows) = shape.counts();
let mut fractions = shape.fractions(splits);
// The borders on the dragged one's axis are `fractions[first..first + count]`.
let (axis_start, axis_len, first, count, pos) = if split < cols - 1 {
(rect.min.x, rect.width(), 0, cols - 1, pointer.x)
} else if split < (cols - 1) + (rows - 1) {
(rect.min.y, rect.height(), cols - 1, rows - 1, pointer.y)
} else {
return;
};
if !(axis_len > 0.0 && pos.is_finite()) {
return;
}
let own = fractions.get(first..first + count).map(<[f32]>::to_vec).unwrap_or_default();
let k = split - first;
// [`MIN_CELL`] in fractions of this axis, whatever the number of cells: capping it by the
// even spacing would let a cell fall under the minimum on a long axis (#10101 review).
let gap = MIN_CELL / axis_len;
let lo = if k == 0 { 0.0 } else { own.get(k - 1).copied().unwrap_or(0.0) } + gap;
let hi = own.get(k + 1).copied().unwrap_or(1.0) - gap;
// The neighbours leave no room for a cell of the minimum width: the border stays where it is,
// rather than taking a value out of order that would invalidate the whole list.
if lo > hi {
return;
}
if let Some(f) = fractions.get_mut(split) {
*f = ((pos - axis_start) / axis_len).clamp(lo, hi);
}
*splits = fractions;
}
/// The narrowest a cell is dragged to, in points.
pub const MIN_CELL: f32 = 80.0;
/// An arrangement as columns and rows of cells.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Shape {
/// `cols` × `rows` even cells, the first `count` of them used.
Grid { cols: usize, rows: usize, count: usize },
/// 3-up Stacked: two columns, the right one in two rows.
Stacked,
}
impl Shape {
fn of(layout: &str, n: usize) -> Option<Shape> {
if n < 2 || !LAYOUTS.contains(&layout) {
return None;
}
let grid = |cols: usize, rows: usize, count: usize| Shape::Grid { cols, rows, count };
Some(match layout {
"tileAllVertically" => grid(n, 1, n),
"tileAllHorizontally" => grid(1, n, n),
"twoUpVertical" => grid(2, 1, 2),
"twoUpHorizontal" => grid(1, 2, 2),
"threeUpVertical" => grid(3, 1, 3),
"threeUpHorizontal" => grid(1, 3, 3),
"threeUpStacked" => Shape::Stacked,
"fourUp" => grid(2, 2, 4),
"sixUp" => grid(3, 2, 6),
_ => {
let cols = (n as f32).sqrt().ceil() as usize;
grid(cols, n.div_ceil(cols), n)
}
})
}
fn counts(self) -> (usize, usize) {
match self {
Shape::Grid { cols, rows, .. } => (cols, rows),
Shape::Stacked => (2, 2),
}
}
/// The split positions as fractions: the column borders, then the row borders. `splits`
/// is used only when it fits this shape (as many values, each axis increasing within 0–1);
/// otherwise the cells are even.
fn fractions(self, splits: &[f32]) -> Vec<f32> {
let (cols, rows) = self.counts();
let even = |k: usize| (1..k).map(move |i| i as f32 / k as f32);
let ordered = |v: &[f32]| v.iter().all(|f| f.is_finite() && *f > 0.0 && *f < 1.0) && v.windows(2).all(|w| matches!(w, [a, b] if a < b));
let fit = splits.len() == (cols - 1) + (rows - 1) && splits.get(..cols - 1).is_some_and(ordered) && splits.get(cols - 1..).is_some_and(ordered);
if fit { splits.to_vec() } else { even(cols).chain(even(rows)).collect() }
}
/// Every column line's x and every row line's y on screen, the area's edges included.
fn lines(self, rect: egui::Rect, splits: &[f32]) -> (Vec<f32>, Vec<f32>) {
let (cols, _) = self.counts();
let fractions = self.fractions(splits);
let (fx, fy) = fractions.split_at((cols - 1).min(fractions.len()));
let at = |start: f32, len: f32, inner: &[f32]| {
std::iter::once(start).chain(inner.iter().map(|f| start + len * f)).chain(std::iter::once(start + len)).collect::<Vec<f32>>()
};
(at(rect.min.x, rect.width(), fx), at(rect.min.y, rect.height(), fy))
}
}
+196 -7
View File
@@ -183,14 +183,14 @@ fn print_size_uses_the_screen_resolution_preference() {
#[test]
fn arrange_layouts_floating_windows_and_matching() {
let (mut app, ctx) = app_with(3);
assert!(cells("tabs", egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3).is_none());
assert!(cells("tabs", egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3, &[]).is_none());
menu(&mut app, &ctx, "window.arrange.threeUpStacked", json!({})).unwrap();
assert_eq!(checked(&app, "window.arrange.threeUpStacked"), Some(true));
let c = cells(&app.ui.view.arrange, egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3).unwrap();
let c = cells(&app.ui.view.arrange, egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3, &[]).unwrap();
assert_eq!(c.len(), 3);
assert_eq!(c[0].height(), 600.0);
assert_eq!(c[1].height(), 300.0);
let six = cells("sixUp", egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3).unwrap();
let six = cells("sixUp", egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3, &[]).unwrap();
assert_eq!((six.len(), six[1].min.x), (6, 300.0));
menu(&mut app, &ctx, "window.arrange.floatAllInWindows", json!({})).unwrap();
assert_eq!(app.ui.windows.len(), 3);
@@ -232,13 +232,109 @@ fn match_zoom_clamps_to_each_documents_zoom_range() {
fn two_up_and_stacked_cells_keep_their_existing_boundaries() {
let rect = egui::Rect::from_min_max(egui::pos2(40.0, 75.0), egui::pos2(940.0, 675.0));
let region = |left, top, right, bottom| egui::Rect::from_min_max(egui::pos2(left, top), egui::pos2(right, bottom));
assert_eq!(cells("twoUpVertical", rect, 2).unwrap(), vec![region(40.0, 75.0, 490.0, 675.0), region(490.0, 75.0, 940.0, 675.0)]);
assert_eq!(cells("twoUpHorizontal", rect, 2).unwrap(), vec![region(40.0, 75.0, 940.0, 375.0), region(40.0, 375.0, 940.0, 675.0)]);
assert_eq!(cells("twoUpVertical", rect, 2, &[]).unwrap(), vec![region(40.0, 75.0, 490.0, 675.0), region(490.0, 75.0, 940.0, 675.0)]);
assert_eq!(cells("twoUpHorizontal", rect, 2, &[]).unwrap(), vec![region(40.0, 75.0, 940.0, 375.0), region(40.0, 375.0, 940.0, 675.0)]);
assert_eq!(
cells("threeUpStacked", rect, 3).unwrap(),
cells("threeUpStacked", rect, 3, &[]).unwrap(),
vec![region(40.0, 75.0, 490.0, 675.0), region(490.0, 75.0, 940.0, 375.0), region(490.0, 375.0, 940.0, 675.0)]
);
assert!(cells("twoUpVertical", rect, 1).is_none());
assert!(cells("twoUpVertical", rect, 1, &[]).is_none());
}
#[test]
fn dragged_arrange_borders_resize_the_cells_beside_them() {
// #10101: in 2-up and the other arrangements the border between documents drags, as in
// Photoshop, and the documents on either side take the new sizes.
use super::arrange::{Border, MIN_CELL};
let near = |a: &[egui::Rect], b: &[egui::Rect]| {
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| (a.min - b.min).length() < 0.01 && (a.max - b.max).length() < 0.01)
};
let rect = egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(900.0, 600.0));
let region = |left, top, right, bottom| egui::Rect::from_min_max(egui::pos2(left, top), egui::pos2(right, bottom));
let mut splits = Vec::new();
let b = borders("twoUpVertical", rect, 2, &splits);
assert_eq!(b, vec![Border { split: 0, vertical: true, line: region(450.0, 0.0, 450.0, 600.0) }]);
drag_border("twoUpVertical", rect, 2, &mut splits, 0, egui::pos2(300.0, 250.0));
assert!(near(&cells("twoUpVertical", rect, 2, &splits).unwrap(), &[region(0.0, 0.0, 300.0, 600.0), region(300.0, 0.0, 900.0, 600.0)]));
assert!((borders("twoUpVertical", rect, 2, &splits)[0].line.min.x - 300.0).abs() < 0.01);
// No cell is dragged narrower than MIN_CELL, nor past the area.
drag_border("twoUpVertical", rect, 2, &mut splits, 0, egui::pos2(-500.0, 0.0));
assert!((cells("twoUpVertical", rect, 2, &splits).unwrap()[0].width() - MIN_CELL).abs() < 0.01);
drag_border("twoUpVertical", rect, 2, &mut splits, 0, egui::pos2(899.0, 0.0));
assert!((cells("twoUpVertical", rect, 2, &splits).unwrap()[1].width() - MIN_CELL).abs() < 0.01);
// 4-up: a column border and a row border, each across the whole area.
let mut splits = Vec::new();
let b = borders("fourUp", rect, 4, &splits);
assert_eq!(b.iter().map(|b| (b.split, b.vertical)).collect::<Vec<_>>(), vec![(0, true), (1, false)]);
drag_border("fourUp", rect, 4, &mut splits, 1, egui::pos2(10.0, 450.0));
let c = cells("fourUp", rect, 4, &splits).unwrap();
assert!(near(&[c[0], c[3]], &[region(0.0, 0.0, 450.0, 450.0), region(450.0, 450.0, 900.0, 600.0)]));
// 3-up Stacked: the row border is only across the right column, and follows the column.
let mut splits = Vec::new();
drag_border("threeUpStacked", rect, 3, &mut splits, 0, egui::pos2(600.0, 0.0));
drag_border("threeUpStacked", rect, 3, &mut splits, 1, egui::pos2(700.0, 200.0));
assert!(near(
&cells("threeUpStacked", rect, 3, &splits).unwrap(),
&[region(0.0, 0.0, 600.0, 600.0), region(600.0, 0.0, 900.0, 200.0), region(600.0, 200.0, 900.0, 600.0)]
));
assert!(near(&[borders("threeUpStacked", rect, 3, &splits)[1].line], &[region(600.0, 200.0, 900.0, 200.0)]));
// Tiled: a border stops short of its neighbours, so the cells keep their order.
let mut splits = Vec::new();
drag_border("threeUpVertical", rect, 3, &mut splits, 0, egui::pos2(800.0, 0.0));
let c = cells("threeUpVertical", rect, 3, &splits).unwrap();
assert!((c[0].max.x - (600.0 - MIN_CELL)).abs() < 0.01 && (c[1].width() - MIN_CELL).abs() < 0.01);
// #10101 review: the limit is MIN_CELL itself, not the even spacing. On a 300 pt axis a
// 2-up cell may still be dragged down to 80 pt, where capping the gap at 0.5/(n+1) would
// have stopped it at 75.
let narrow = egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(300.0, 200.0));
let mut splits = Vec::new();
drag_border("twoUpVertical", narrow, 2, &mut splits, 0, egui::pos2(-100.0, 0.0));
assert!((cells("twoUpVertical", narrow, 2, &splits).unwrap()[0].width() - MIN_CELL).abs() < 0.01);
// And when the neighbours leave no room for a cell of that width, the border stays put and
// the list keeps its order rather than taking a value from the wrong side of them.
let tight = egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(200.0, 200.0));
let mut splits = vec![0.45, 0.55];
drag_border("threeUpVertical", tight, 3, &mut splits, 1, egui::pos2(10.0, 0.0));
assert_eq!(splits, vec![0.45, 0.55], "no room: unchanged");
let mut splits = vec![0.45, 0.55];
drag_border("threeUpVertical", tight, 3, &mut splits, 0, egui::pos2(190.0, 0.0));
assert_eq!(splits, vec![0.45, 0.55], "and from the other side too");
}
#[test]
fn damaged_or_stale_arrange_splits_lay_out_even_cells() {
let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0));
let even = cells("threeUpVertical", rect, 3, &[]).unwrap();
// From a settings file or another layout: wrong count, out of order, outside 0–1, NaN.
for bad in [vec![0.5], vec![0.6, 0.3], vec![0.0, 0.5], vec![0.3, 1.5], vec![f32::NAN, 0.7], vec![0.2, 0.4, 0.6]] {
assert_eq!(cells("threeUpVertical", rect, 3, &bad).unwrap(), even, "{bad:?}");
assert_eq!(borders("threeUpVertical", rect, 3, &bad).len(), 2);
// A drag starts again from even cells.
let mut splits = bad.clone();
drag_border("threeUpVertical", rect, 3, &mut splits, 1, egui::pos2(700.0, 0.0));
assert_eq!(cells("threeUpVertical", rect, 3, &splits).unwrap()[0], even[0], "{bad:?}");
}
// A split that isn't the layout's, or a pointer off the numbers, changes nothing.
let mut splits = vec![0.25, 0.5];
drag_border("threeUpVertical", rect, 3, &mut splits, 2, egui::pos2(700.0, 0.0));
drag_border("threeUpVertical", rect, 3, &mut splits, 0, egui::pos2(f32::NAN, 0.0));
drag_border("threeUpVertical", egui::Rect::NOTHING, 3, &mut splits, 0, egui::pos2(10.0, 0.0));
assert_eq!(splits, vec![0.25, 0.5]);
assert!(borders("tabs", rect, 3, &[]).is_empty());
}
#[test]
fn choosing_an_arrangement_starts_from_even_cells() {
let (mut app, ctx) = app_with(2);
menu(&mut app, &ctx, "window.arrange.twoUpVertical", json!({})).unwrap();
app.ui.view.arrange_splits = vec![0.3];
menu(&mut app, &ctx, "window.arrange.twoUpHorizontal", json!({})).unwrap();
assert!(app.ui.view.arrange_splits.is_empty());
}
#[test]
@@ -1014,6 +1110,50 @@ fn arranged_documents_keep_their_tiles() {
assert_eq!(docs(&mut app, 1), vec![0, 1]);
}
/// #10101: dragging the border between two arranged documents moves it. Grabbed inside the
/// other document's edge, it doesn't make that document the active one.
#[test]
fn dragging_the_border_between_arranged_documents_resizes_them() {
use egui_kittest::Harness;
let (mut app, _) = app_with(2);
app.ui.view.arrange = "twoUpVertical".into();
app.ui.tool = crate::state::Tool::Brush;
// The right-hand document is active; the grab below is inside the left one's edge.
app.session.set_active(1);
let mut h = Harness::builder().with_size(egui::vec2(1000.0, 600.0)).build_ui_state(
|ui, app: &mut PhotocraftApp| {
if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
return;
}
egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
},
app,
);
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
h.run_steps(4);
let area = h.state().last_canvas_rect;
let n = h.state().session.documents().len();
let border = borders("twoUpVertical", area, n, &[])[0].line;
// On the grip, 2 pt inside the left document (its cell ends 1 pt short of the border).
let from = border.center() - egui::vec2(2.0, 0.0);
let to = from - egui::vec2(200.0, 0.0);
let ev = |h: &mut Harness<'_, PhotocraftApp>, e: egui::Event| h.input_mut().events.push(e);
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
ev(&mut h, egui::Event::PointerMoved(from));
h.run();
ev(&mut h, button(from, true));
h.run();
for step in 1..=10 {
ev(&mut h, egui::Event::PointerMoved(from + (to - from) * (step as f32 / 10.0)));
h.run();
}
ev(&mut h, button(to, false));
h.run_steps(2);
let cells = cells("twoUpVertical", area, n, &h.state().ui.view.arrange_splits).unwrap();
assert!((cells[0].max.x - to.x).abs() < 1.0, "the border follows the pointer: {cells:?}, pointer at {}", to.x);
assert_eq!(h.state().session.active_index(), Some(1), "grabbing the border activates no document");
}
/// #6017: rulers showed in the active tile only; the other tile had none and no room for them.
#[test]
fn every_arranged_tile_has_rulers() {
@@ -1108,3 +1248,52 @@ fn full_screen_modes_need_a_document() {
leave_full_screen_without_document(&mut app, &ctx);
assert_eq!(app.ui.view.screen_mode, "standard");
}
/// #10101 review: the grip overlaps the *active* document's edge too, and a press there must
/// drag the border without painting. The cells the canvases are actually drawn in follow.
#[test]
fn grabbing_the_border_inside_the_active_document_drags_it_without_painting() {
use egui_kittest::Harness;
let (mut app, _) = app_with(2);
app.ui.view.arrange = "twoUpVertical".into();
app.ui.tool = crate::state::Tool::Brush;
// The right-hand document is active, and the grab below is inside *its* edge.
app.session.set_active(1);
let mut h = Harness::builder().with_size(egui::vec2(1000.0, 600.0)).build_ui_state(
|ui, app: &mut PhotocraftApp| {
if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
return;
}
egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
},
app,
);
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
h.run_steps(4);
let area = h.state().last_canvas_rect;
let n = h.state().session.documents().len();
let border = borders("twoUpVertical", area, n, &[])[0].line;
let steps = |h: &Harness<'_, PhotocraftApp>| h.state().session.active().map_or(0, |d| d.history.entries().len());
let before = steps(&h);
// 2 pt into the right-hand (active) document, where its canvas would otherwise take the press.
let from = border.center() + egui::vec2(2.0, 0.0);
let to = from + egui::vec2(150.0, 0.0);
let ev = |h: &mut Harness<'_, PhotocraftApp>, e: egui::Event| h.input_mut().events.push(e);
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
ev(&mut h, egui::Event::PointerMoved(from));
h.run();
ev(&mut h, button(from, true));
h.run();
for step in 1..=10 {
ev(&mut h, egui::Event::PointerMoved(from + (to - from) * (step as f32 / 10.0)));
h.run();
}
ev(&mut h, button(to, false));
h.run_steps(2);
assert_eq!(steps(&h), before, "the press dragged the border and painted nothing");
assert_eq!(h.state().session.active_index(), Some(1), "the active document stays active");
// And the cells the documents are drawn in follow the border, not just the stored fractions.
let shown = crate::canvas::arranged_cells(h.state(), area).expect("two documents are arranged");
assert!((shown[0].1.max.x - to.x).abs() < 2.0, "the left cell ends at the border: {:?}, pointer at {}", shown[0].1, to.x);
assert!((shown[1].1.min.x - to.x).abs() < 2.0, "and the right one starts there: {:?}", shown[1].1);
}
+175
View File
@@ -210,6 +210,181 @@ fn the_pen_carries_on_an_open_path_from_either_end() {
assert_eq!((work.subpaths.len(), work.subpaths[1].closed, work.subpaths[1].knots.len()), (2, true, 3));
}
/// #10726: after another tool, the Curvature Pen carries an open path on as in Photoshop: a click on
/// its endpoint selects it, and the next click continues the path from there. The subpath is
/// extended in one History step, its segments keep their shape, and the new anchors take smooth
/// curvature handles.
#[test]
fn the_curvature_pen_carries_on_an_open_path() {
let mut app = app(Tool::Pen);
click(&mut app, 20.0, 20.0);
// A curve: the middle anchor's handles dragged out further than the Curvature Pen would set.
tool_event(&mut app, ToolEvent::Down { x: 80.0, y: 20.0, pressure: 1.0 }, Modifiers::NONE);
tool_event(&mut app, ToolEvent::Move { x: 130.0, y: 10.0, pressure: 1.0 }, Modifiers::NONE);
tool_event(&mut app, ToolEvent::Up { x: 130.0, y: 10.0 }, Modifiers::NONE);
click(&mut app, 80.0, 80.0);
crate::vector_ui::pen_commit(&mut app, false);
let before = work_path(&app).subpaths[0].knots.clone();
assert_ne!(before[1].out_ctrl, before[1].anchor, "the middle anchor has handles");
let steps = |app: &PhotocraftApp| app.session.active().unwrap().history.past_len();
let at = steps(&app);
app.ui.tool = Tool::CurvaturePen;
click(&mut app, 80.0, 80.0);
assert!(app.ui.pen.is_none(), "the click selects the endpoint, it draws nothing");
click(&mut app, 140.0, 120.0);
assert!(app.ui.pen.as_ref().is_some_and(|p| p.curvature && p.knots.len() == 4), "the next click carries the path on");
click(&mut app, 200.0, 80.0);
crate::vector_ui::pen_commit(&mut app, false);
let work = work_path(&app);
assert_eq!(work.subpaths.len(), 1, "the same subpath, extended");
let knots = &work.subpaths[0].knots;
let anchors: Vec<[f64; 2]> = knots.iter().map(|k| [k.anchor.x, k.anchor.y]).collect();
assert_eq!(anchors, [[20.0, 20.0], [80.0, 20.0], [80.0, 80.0], [140.0, 120.0], [200.0, 80.0]]);
assert_eq!(steps(&app), at + 1, "one History step");
// The Pen's straight segments keep their shape: the first knots are as they were, and the
// endpoint keeps its incoming handle.
assert_eq!((knots[0], knots[1]), (before[0], before[1]));
assert_eq!((knots[2].anchor, knots[2].in_ctrl), (before[2].anchor, before[2].in_ctrl));
// The new anchor in the middle is smooth: its handles lie either side of it.
let mid = &knots[3];
assert!(mid.in_ctrl != mid.anchor && mid.out_ctrl != mid.anchor, "{mid:?}");
assert!((mid.in_ctrl.x - mid.anchor.x) * (mid.out_ctrl.x - mid.anchor.x) < 0.0, "handles on either side: {mid:?}");
// While it draws on, the Curvature Pen moves only the new anchors: a press on an old corner
// adds an anchor there.
click(&mut app, 200.0, 80.0);
click(&mut app, 260.0, 40.0);
click(&mut app, 80.0, 20.0);
assert_eq!(app.ui.pen.as_ref().map(|p| p.knots.len()), Some(7), "a new anchor, the old one untouched");
assert_eq!(app.ui.pen.as_ref().map(|p| p.knots[1][0]), Some([80.0, 20.0]));
}
/// The work path set to `subpaths`, in one step.
fn set_work_path(app: &mut PhotocraftApp, subpaths: Vec<photocraft_doc::vector::Subpath>) {
app.session
.edit("path", |doc, _| {
doc.work_path = Some(Path::new(subpaths));
Ok(())
})
.unwrap();
}
/// Direct Selection's selection: anchor `[subpath, knot]` of `target`, alone.
fn select_anchor(app: &mut PhotocraftApp, target: crate::direct_select::PathRef, anchor: [usize; 2]) {
app.ui.direct_selection.target = Some(target);
app.ui.direct_selection.anchors = vec![anchor];
// Made now, on this document: not a stale selection the next press drops.
app.ui.direct_selection.owner = crate::direct_select::Owner::current(app);
}
/// CodeRabbit on #10744: two open subpaths end on the same point, and the Curvature Pen carries on
/// the one whose endpoint is selected, not the first one ending there.
#[test]
fn the_curvature_pen_carries_on_the_selected_subpath_of_two_that_end_together() {
use photocraft_doc::vector::Subpath;
let mut app = app(Tool::CurvaturePen);
set_work_path(&mut app, vec![Subpath::polyline(&[(20.0, 20.0), (80.0, 80.0)]), Subpath::polyline(&[(200.0, 20.0), (80.0, 80.0)])]);
select_anchor(&mut app, crate::direct_select::PathRef::Work, [1, 1]);
click(&mut app, 140.0, 150.0);
assert_eq!(app.ui.pen.as_ref().and_then(|p| p.resumes.as_ref()).map(|r| r.index), Some(1), "the selected subpath");
crate::vector_ui::pen_commit(&mut app, false);
let work = work_path(&app);
assert_eq!(work.subpaths.iter().map(|s| s.knots.len()).collect::<Vec<_>>(), [2, 3], "the second subpath grew");
}
/// Photoshop: an open Curvature Pen arc carried on from its endpoint goes on as a new Curvature
/// run from that endpoint. The old segments keep their shape, the endpoint keeps its incoming
/// handle, and its outgoing handle and the new knots are those of a path drawn from the endpoint
/// on, so the join is a cusp where both arcs meet, not bent smooth.
#[test]
fn a_carried_on_endpoint_starts_a_new_curvature_run() {
let draw = |points: &[(f64, f64)]| {
let mut app = app(Tool::CurvaturePen);
for &(x, y) in points {
click(&mut app, x, y);
}
assert!(crate::vector_ui::pen_commit(&mut app, false), "the commit goes through");
app
};
let fresh = work_path(&draw(&[(400.0, 300.0), (550.0, 150.0), (700.0, 300.0)])).subpaths[0].knots.clone();
let mut app = draw(&[(100.0, 300.0), (250.0, 150.0), (400.0, 300.0)]);
let before = work_path(&app).subpaths[0].knots.clone();
click(&mut app, 400.0, 300.0);
assert!(app.ui.pen.is_none(), "the click selects the endpoint, it draws nothing");
click(&mut app, 550.0, 150.0);
click(&mut app, 700.0, 300.0);
assert!(crate::vector_ui::pen_commit(&mut app, false), "the commit goes through");
let work = work_path(&app);
assert_eq!(work.subpaths.len(), 1, "the same subpath, extended");
let knots = &work.subpaths[0].knots;
assert_eq!(knots.len(), 5, "carried on by the new anchors");
assert_eq!((knots[0], knots[1]), (before[0], before[1]), "the old segments keep their shape");
assert_eq!((knots[2].anchor, knots[2].in_ctrl), (before[2].anchor, before[2].in_ctrl), "the endpoint keeps its incoming handle");
assert_eq!(knots[2].out_ctrl, fresh[0].out_ctrl, "the endpoint goes on as a new run's first knot: {knots:?}");
assert_eq!((knots[3], knots[4]), (fresh[1], fresh[2]), "the new knots are those of a new run");
// Both arcs meet at the endpoint from above: a cusp, as in Photoshop.
let k = &knots[2];
assert!(k.in_ctrl.y < k.anchor.y && k.out_ctrl.y < k.anchor.y, "{k:?}");
}
/// CodeRabbit on #10744: a curved path carried on from its first endpoint runs backwards, each
/// knot's handles swapped, and that endpoint keeps the handle it had towards the path.
#[test]
fn a_curved_path_carries_on_from_its_first_endpoint_with_its_handles_swapped() {
use photocraft_doc::vector::{Knot, Subpath};
use photocraft_geom::Point;
let mut app = app(Tool::CurvaturePen);
let start = Knot::smooth(Point::new(20.0, 20.0), Point::new(10.0, 30.0), Point::new(30.0, 10.0));
let middle = Knot::smooth(Point::new(50.0, 60.0), Point::new(40.0, 50.0), Point::new(60.0, 70.0));
set_work_path(&mut app, vec![Subpath { closed: false, knots: vec![start, middle, Knot::corner(80.0, 80.0)], op: Default::default() }]);
select_anchor(&mut app, crate::direct_select::PathRef::Work, [0, 0]);
click(&mut app, 0.0, 100.0);
let pen = app.ui.pen.as_ref().expect("the path is carried on");
assert_eq!(pen.resumes.as_ref().map(|r| r.index), Some(0));
let anchors: Vec<[f64; 2]> = pen.knots.iter().map(|k| k[0]).collect();
assert_eq!(anchors, [[80.0, 80.0], [50.0, 60.0], [20.0, 20.0], [0.0, 100.0]], "backwards, then the new anchor");
assert_eq!((pen.knots[1][1], pen.knots[1][2]), ([60.0, 70.0], [40.0, 50.0]), "the curved middle knot's handles are swapped");
assert_eq!(pen.knots[2][1], [30.0, 10.0], "the endpoint's handle towards the path: its old outgoing one");
}
/// CodeRabbit on #10744: a double-click on a knot of the path carried on (not the endpoint it
/// carries on from) changes nothing: those knots keep their handles.
#[test]
fn toggling_a_carried_knot_changes_nothing() {
use photocraft_doc::vector::Subpath;
let mut app = app(Tool::CurvaturePen);
set_work_path(&mut app, vec![Subpath::polyline(&[(20.0, 20.0), (80.0, 20.0), (80.0, 80.0)])]);
select_anchor(&mut app, crate::direct_select::PathRef::Work, [0, 2]);
click(&mut app, 140.0, 120.0);
let before = app.ui.pen.as_ref().map(|p| (p.unlinked.clone(), p.knots.clone()));
crate::vector_ui::curvature_toggle(&mut app, 80.0, 20.0);
assert_eq!(app.ui.pen.as_ref().map(|p| (p.unlinked.clone(), p.knots.clone())), before, "the old corner stays as it was, handles and all");
}
/// CodeRabbit on #10744: in Path mode the Pen carries on the work path, so an endpoint selected
/// on a shape layer, even one on the same point as the work path's, is not carried on: the
/// press starts a new path rather than carrying on the work path from there.
#[test]
fn an_endpoint_on_another_path_than_the_pen_draws_on_starts_a_new_one() {
use photocraft_doc::vector::Subpath;
let mut app = app(Tool::Pen);
app.ui.tool_options.vector_mode = "shape".into();
click(&mut app, 20.0, 20.0);
click(&mut app, 80.0, 80.0);
crate::vector_ui::pen_commit(&mut app, false);
let shape = app.session.active().and_then(|st| st.active_layer).expect("a shape layer").0;
app.ui.tool_options.vector_mode = "path".into();
// The Paths panel on no path: the Pen draws on the work path, not the layer's.
app.ui.selected_path = None;
set_work_path(&mut app, vec![Subpath::polyline(&[(200.0, 20.0), (80.0, 80.0)])]);
// The tool first: switching tools drops a Direct Selection selection.
app.ui.tool = Tool::CurvaturePen;
select_anchor(&mut app, crate::direct_select::PathRef::Layer(shape), [0, 1]);
assert!(crate::direct_select::selected_open_end(&app).is_some(), "the shape's endpoint is selected");
click(&mut app, 140.0, 150.0);
let pen = app.ui.pen.as_ref().expect("a new path");
assert!(pen.resumes.is_none() && pen.knots.len() == 1, "{pen:?}");
}
/// #6593 review: carrying on a subpath keeps its path operation, and a draft whose subpath changed
/// meanwhile refuses without overwriting newer work. The historical test name is retained
/// for reviewed-head provenance; captured-revision validation supersedes its stale fallback.
+12
View File
@@ -241,6 +241,18 @@ fn converting(tool: Tool, mods: Modifiers, pen_idle: bool) -> bool {
!mods.command && (tool == Tool::ConvertPoint || (tool == Tool::Pen && mods.alt && pen_idle))
}
/// The selected anchor when it is the only one and an endpoint of an open subpath of the active
/// path: where the Curvature Pen carries the path on from (#10726), as Photoshop does after a
/// click, or ⌘/Ctrl-click, on the last point. The path, the subpath's index and the knot's.
pub(crate) fn selected_open_end(app: &PhotocraftApp) -> Option<(PathRef, usize, usize)> {
let ds = &app.ui.direct_selection;
let ([[s, k]], Some(target)) = (ds.anchors.as_slice(), ds.target) else { return None };
let (_, path) = active_paths(app).into_iter().find(|(r, _)| *r == target)?;
let sub = path.subpaths.get(*s).filter(|sub| !sub.closed)?;
sub.knots.get(*k).filter(|_| *k == 0 || *k + 1 == sub.knots.len())?;
Some((target, *s, *k))
}
/// Is the Curvature Pen idle (no path being drawn, no ⌘/Ctrl)? Then it edits the active path in
/// place, as in Photoshop: a press on one of its anchors drags it, with no modifier.
fn curvature_idle(app: &PhotocraftApp, mods: Modifiers) -> bool {
+5
View File
@@ -169,6 +169,11 @@ pub struct PenPath {
/// commit replaces that subpath instead of adding one.
#[serde(default)]
pub resumes: Option<Resumed>,
/// The Curvature Pen carrying on a path: its knots as they were, which keep their shape while
/// the new anchors' handles follow them (`curvature_refresh`, #10726). The last one is the
/// endpoint drawing carries on from; only its outgoing handle bends into the new segment.
#[serde(default)]
pub fixed: Vec<[[f64; 2]; 3]>,
}
/// The subpath a Pen path carries on: where it is and what it was when drawing resumed. The
@@ -1,11 +1,58 @@
use super::pen::{cancel_stale, pen_commit};
use super::pen::{cancel_stale, pen_commit, resume_selected};
use super::{PenPath, PhotocraftApp};
/// Recompute a Curvature Pen path's handles from its anchors and corner points.
/// Recompute a Curvature Pen path's handles from its anchors and corner points. The knots of a
/// path it carries on (`PenPath::fixed`) keep theirs, but for the endpoint's outgoing handle
/// and, once the path closes, the first knot's incoming handle (#10726). As in Photoshop, an open
/// path carried on is a new Curvature run from the endpoint: the endpoint's outgoing handle and
/// the new knots are those of a path drawn from the endpoint on, so the join is not made smooth.
/// The first knot's incoming handle, bent into the closing segment, stays in line with its
/// outgoing one, so that knot stays smooth.
pub(super) fn curvature_refresh(pen: &mut PenPath, closed: bool) {
let anchors: Vec<[f64; 2]> = pen.knots.iter().map(|k| k[0]).collect();
let corners: Vec<bool> = (0..anchors.len()).map(|i| pen.unlinked.contains(&i)).collect();
pen.knots = photocraft_vector::edit::curvature_knots(&anchors, &corners, closed);
let last = pen.fixed.len().saturating_sub(1);
let extended = pen.knots.len() > pen.fixed.len();
if extended && !closed && !pen.fixed.is_empty() {
let run = photocraft_vector::edit::curvature_knots(anchors.get(last..).unwrap_or_default(), corners.get(last..).unwrap_or_default(), false);
for (k, r) in pen.knots.iter_mut().skip(last).zip(run) {
*k = r;
}
}
for (i, was) in pen.fixed.iter().enumerate() {
let Some(k) = pen.knots.get_mut(i) else { break };
let (keep_in, keep_out) = (!(closed && i == 0), !(extended && i == last));
k[0] = was[0];
if keep_in {
k[1] = was[1];
}
if keep_out {
k[2] = was[2];
}
if !keep_in && keep_out && !corners.get(i).copied().unwrap_or(false) {
// An outgoing handle on its anchor gives no direction: the kept segment leaves
// towards its next control point, else the next anchor, so the bent handle comes in
// from the far side and the knot is still smooth (CodeRabbit on #10744).
let across = pen.fixed.get(i + 1).map(|n| [n[1], n[0]]);
let toward = std::iter::once(k[2]).chain(across.into_iter().flatten());
if let Some(h) = toward.filter_map(|from| in_line(k[0], from, k[1])).next() {
k[1] = h;
}
}
}
}
/// A handle as long as `bent` from `anchor`, on the far side of it from `kept`: `None` when
/// `kept` lies on the anchor and gives no direction.
fn in_line(anchor: [f64; 2], kept: [f64; 2], bent: [f64; 2]) -> Option<[f64; 2]> {
let (dx, dy) = (anchor[0] - kept[0], anchor[1] - kept[1]);
let d = dx.hypot(dy);
if !(d > 1e-9 && d.is_finite()) {
return None;
}
let len = (bent[0] - anchor[0]).hypot(bent[1] - anchor[1]);
len.is_finite().then(|| [anchor[0] + dx / d * len, anchor[1] + dy / d * len])
}
/// The anchor of the Curvature Pen path being drawn under (x, y), for the cursor.
@@ -44,6 +91,19 @@ pub fn curvature_down(app: &mut PhotocraftApp, x: f64, y: f64) {
if app.ui.pen.is_none() {
app.ui.pen_doc = app.session.active().map(|st| st.doc.id);
}
// With an endpoint of an open path selected (a click, or ⌘/Ctrl-click, on it), the press
// carries that path on from there, as in Photoshop (#10726): its segments keep their shape,
// the press adds the next anchor and the commit extends that subpath.
if app.ui.pen.as_ref().is_none_or(|p| p.knots.is_empty())
&& let Some(mut resumed) = resume_selected(app)
{
resumed.curvature = true;
resumed.fixed = resumed.knots.clone();
app.ui.pen = Some(resumed);
}
// The anchors of the path carried on stay where they are; the new ones move.
let fixed = app.ui.pen.as_ref().map_or(0, |p| p.fixed.len());
let hit = hit.filter(|&i| i >= fixed);
let Some(owner) = capture_pen_owner(app) else { return };
let pen = app.ui.pen.get_or_insert_with(|| PenPath { curvature: true, ..Default::default() });
if pen.owner.is_none() {
@@ -86,6 +146,11 @@ pub fn curvature_toggle(app: &mut PhotocraftApp, x: f64, y: f64) {
cancel_stale_pen(app);
let Some(i) = curvature_hit(app, x, y) else { return };
let Some(pen) = app.ui.pen.as_mut() else { return };
// The knots of a path carried on keep their handles (`curvature_refresh`), but for the
// endpoint drawing carries on from: toggling one of the others would change nothing.
if i + 1 < pen.fixed.len() {
return;
}
if let Some(at) = pen.unlinked.iter().position(|&c| c == i) {
pen.unlinked.remove(at);
} else {
+65 -29
View File
@@ -509,28 +509,47 @@ fn doc_path<'a>(doc: &'a Document, name: &str) -> Option<&'a Path> {
if name == "work" { doc.work_path.as_ref() } else { doc.paths.iter().find(|p| p.name == name).map(|p| &p.path) }
}
/// The open subpath that has its first or last anchor at `(x, y)`, as a Pen path to carry on
/// drawing from there (#6593): of a targeted vector mask, else in Shape mode of the selected shape
/// layer, else of the path a new Pen path would join (the one selected in the Paths panel, else
/// the work path). Its knots run towards that anchor: reversed, handles swapped, when it is the
/// first.
fn resume_at(app: &PhotocraftApp, x: f64, y: f64, tol: f64) -> Option<PenPath> {
/// The path a Pen path carries on (#6593): a targeted vector mask, else in Shape mode the
/// selected shape layer's, else the path a new Pen path would join (the one selected in the Paths
/// panel, else the work path). Its Paths-panel name ("layer" for a layer's), layer and path.
fn resume_target(app: &PhotocraftApp) -> Option<(String, Option<u64>, Path)> {
let st = app.session.active()?;
let doc = st.doc.id.0;
let (name, layer, path) = if let Some((id, p)) = targeted_vector_mask(app) {
("layer".to_string(), Some(id), p)
} else if app.ui.tool_options.vector_mode == "shape" {
if let Some((id, p)) = targeted_vector_mask(app) {
return Some(("layer".to_string(), Some(id), p));
}
if app.ui.tool_options.vector_mode == "shape" {
let (id, p) = active_shape_path(app)?;
("layer".to_string(), Some(id), p)
} else {
let name = app.ui.selected_path.clone().filter(|n| path_exists(&st.doc, n)).unwrap_or_else(|| "work".into());
// A Work Path hidden by Make Selection isn't carried on: a new path replaces it (#6079).
if name == "work" && !work_path_shown(app) {
return None;
return Some(("layer".to_string(), Some(id), p));
}
let name = app.ui.selected_path.clone().filter(|n| path_exists(&st.doc, n)).unwrap_or_else(|| "work".into());
// A Work Path hidden by Make Selection isn't carried on: a new path replaces it (#6079).
if name == "work" && !work_path_shown(app) {
return None;
}
let p = doc_path(&st.doc, &name)?.clone();
Some((name, None, p))
}
/// Subpath `index` of the path a Pen path carries on, as a Pen path to carry on drawing from its
/// last anchor, or from its first when `reversed`: then its knots run backwards, handles swapped.
fn resumed(doc: u64, name: String, layer: Option<u64>, index: usize, sub: &photocraft_doc::vector::Subpath, reversed: bool) -> PenPath {
let mut knots: Vec<_> = sub.knots.iter().map(|k| (knot_points(k), k.smooth)).collect();
if reversed {
knots.reverse();
for (k, _) in &mut knots {
k.swap(1, 2);
}
let p = doc_path(&st.doc, &name)?.clone();
(name, None, p)
};
}
let unlinked = knots.iter().enumerate().filter(|(_, (_, smooth))| !smooth).map(|(i, _)| i).collect();
let resumes = Resumed { doc, path: name, layer, index, was: sub.clone() };
PenPath { knots: knots.into_iter().map(|(k, _)| k).collect(), unlinked, resumes: Some(resumes), ..Default::default() }
}
/// The open subpath that has its first or last anchor at `(x, y)` in the path a Pen path carries
/// on ([`resume_target`]), as a Pen path to carry on drawing from there (#6593).
pub(super) fn resume_at(app: &PhotocraftApp, x: f64, y: f64, tol: f64) -> Option<PenPath> {
let doc = app.session.active()?.doc.id.0;
let (name, layer, path) = resume_target(app)?;
let near = |k: &photocraft_doc::Knot| (k.anchor.x - x).hypot(k.anchor.y - y) < tol;
path.subpaths.iter().enumerate().filter(|(_, s)| !s.closed).find_map(|(i, s)| {
let reversed = if s.knots.last().is_some_and(near) {
@@ -540,19 +559,36 @@ fn resume_at(app: &PhotocraftApp, x: f64, y: f64, tol: f64) -> Option<PenPath> {
} else {
return None;
};
let mut knots: Vec<_> = s.knots.iter().map(|k| (knot_points(k), k.smooth)).collect();
if reversed {
knots.reverse();
for (k, _) in &mut knots {
k.swap(1, 2);
}
}
let unlinked = knots.iter().enumerate().filter(|(_, (_, smooth))| !smooth).map(|(i, _)| i).collect();
let resumes = Resumed { doc, path: name.clone(), layer, index: i, was: s.clone() };
Some(PenPath { knots: knots.into_iter().map(|(k, _)| k).collect(), unlinked, resumes: Some(resumes), ..Default::default() })
Some(resumed(doc, name.clone(), layer, i, s, reversed))
})
}
/// The endpoint Direct Selection has selected ([`crate::direct_select::selected_open_end`]), as
/// a Pen path carrying its very subpath on from it (#10726). `None` unless that endpoint is in
/// the path a Pen path carries on ([`resume_target`]): one in another path starts a new one.
pub(super) fn resume_selected(app: &PhotocraftApp) -> Option<PenPath> {
let (target, index, knot) = crate::direct_select::selected_open_end(app)?;
let st = app.session.active()?;
let (name, layer, path) = resume_target(app)?;
let carried = match layer {
Some(id) => crate::direct_select::PathRef::Layer(id),
None if name == "work" => crate::direct_select::PathRef::Work,
None => crate::direct_select::PathRef::Saved(st.doc.paths.iter().position(|p| p.name == name)?),
};
if carried != target {
return None;
}
let sub = path.subpaths.get(index).filter(|s| !s.closed)?;
let reversed = if knot + 1 == sub.knots.len() {
false
} else if knot == 0 {
true
} else {
return None;
};
Some(resumed(st.doc.id.0, name, layer, index, sub, reversed))
}
/// The resumed path with its subpath carried on: the one subpath of `drawn` takes the old one's
/// anchors and closing, which keeps its other settings (its path operation). `None` when the
/// subpath is no longer the one drawing resumed (another document, or the path changed).
+84
View File
@@ -0,0 +1,84 @@
# Georgian localization and terminology
This note goes with the Georgian catalog (`crates/ui-egui/src/i18n/ka.tsv`). It covers every key
`cargo xtask i18n-coverage` measures and the runtime labels the other complete catalogs carry
(filter and adjustment parameters, Camera Raw, panels, dialogs, status messages). Translations are
written from the meaning of PhotoCraft's English labels; no proprietary translation resources,
fonts, screenshots or user documents are included.
## Choosing Georgian
Open **Edit > Preferences > Interface > Language** (Georgian: **რედაქტირება › პარამეტრები ›
ინტერფეისი › ენა**) and choose **ქართული**. With `interface.language` set to `auto`, the system
locales `ka`, `ka-GE` and `ka_GE.UTF-8` resolve to Georgian.
## Register and style
Commands are verbal nouns (masdar: *შენახვა*, *გახსნა*, *შრის წაშლა*), not imperatives; prompts
and hints address the user politely (*დაწკაპეთ*, *გადაათრიეთ*). Product and technology names
(PhotoCraft, OpenType, CMYK, Lab) stay as they are, and the trailing `…` of dialog commands is kept.
## Georgian script
- Mkhedruli has no letter case, so nothing is capitalised and labels never use Mtavruli.
The text engine's **All Caps** maps Mkhedruli to Mtavruli through Unicode `to_uppercase`, which
is the Unicode-standard behaviour; there is no title-case feature that needs a Georgian guard.
- Nouns stay singular after a numeral, so the catalog uses one plural form and count-neutral
wording: `{n} layers` is `შრე: {n}` (`plural_none` in the registry).
- UI font: PhotoCraft bundles no Georgian face. The fallback list in `crates/text/src/scripts.rs`
uses system fonts: Noto Sans Georgian, Segoe UI, Sylfaen, DejaVu Sans and
FreeSans. The web build has no system fonts, so it needs a Georgian face before Georgian can render
there.
- PhotoCraft has no per-language date or number formatting, so nothing Georgian-specific applies.
## Terminology
Follow this table when adding or changing Georgian strings.
| English source | Georgian | Note |
|---|---|---|
| File / Edit / Select / View / Window | ფაილი / რედაქტირება / მონიშვნა / ხედი / ფანჯარა | menu bar |
| Image | გამოსახულება | the edited picture |
| Canvas / Canvas Size… | ტილო / ტილოს ზომა… | |
| Layer / Layers | შრე / შრეები | |
| Selection | მონიშნული | the selected area; the menu is მონიშვნა |
| Layer Mask / Vector Mask | შრის ნიღაბი / ვექტორული ნიღაბი | |
| Clipping Mask | მომჭრელი ნიღაბი | |
| Smart Object | ჭკვიანი ობიექტი | |
| Rasterize | რასტრირება | |
| Path / Work Path | ტრაექტორია / სამუშაო ტრაექტორია | not კონტური |
| Stroke | კონტური | outline of a shape or text |
| Channel / Alpha | არხი / ალფა | |
| Spot Color / Spot Channel | სპოტ-ფერი / სპოტ-ფერის არხი | |
| Adjustments | კორექცია | |
| Blend Mode / Blending Options | შერევის რეჟიმი / შერევის პარამეტრები | |
| Opacity | გაუმჭვირვალობა | |
| Preset / Presets | პრესეტი / პრესეტები | |
| Pattern | პატერნი | |
| Swatches | ფერის ნიმუშები | |
| Slice | ნაჭერი | |
| Crop | ჩამოჭრა | |
| Feather | კიდეების შერბილება | |
| Hue / Lightness | ფერის ტონი / სიღიავე | |
| Threshold | ზღვარი | |
| Brush / Eraser / Smudge | ფუნჯი / საშლელი / გადღაბნა | |
| Healing Brush | აღმდგენი ფუნჯი | |
| Reset | ჩამოყრა | |
| Paste | ჩასმა | |
| Workspace | სამუშაო სივრცე | |
| Foreground / Background Color | წინა პლანის ფერი / ფონის ფერი | |
## Not covered
Engine error and status messages, user document, layer and preset names, automation command IDs
and the default `Untitled` / `Background` names stay in English, as in every language.
## Maintenance
Add a row to `ka.tsv` for each new English label: `context<TAB>source<TAB>translation`, with
`@plural` rows holding one Georgian form and `@id` rows overriding a command id. Keep `{name}`
placeholders, `\n`, `…` and shortcut text exactly as in the source. Checks:
- `cargo test -p photocraft-ui-egui --lib i18n`: registry, locale tags, placeholders and catalog
consistency.
- `cargo xtask i18n-coverage`: measured key coverage for `ka`.
+7 -5
View File
@@ -1,10 +1,10 @@
# Localization parity
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-11-06 · **Change:** minor (Azerbaijani UI catalog merged with current languages; native review pending; Bosnian UI catalog; previously minor: Swedish, Finnish, Danish and Norwegian Bokmål UI catalogs; previously minor: Arabic UI catalog) · **Target:** Adobe Photoshop 2026
> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-11-06 · **Change:** minor (Georgian interface catalog; previously minor: Azerbaijani UI catalog merged with current languages; native review pending; Bosnian UI catalog; previously minor: Swedish, Finnish, Danish and Norwegian Bokmål UI catalogs; previously minor: Arabic UI catalog) · **Target:** Adobe Photoshop 2026
Per-language status of PhotoCraft's UI. How catalogs work and how to add one:
[`localization.md`](localization.md). Language notes: [Korean](localization-ko.md), [Spanish](localization-es.md),
[Simplified Chinese](localization-zh-hans.md), [Italian](localization-it.md), [Russian](localization-ru.md).
[Simplified Chinese](localization-zh-hans.md), [Italian](localization-it.md), [Russian](localization-ru.md), [Georgian](localization-ka.md).
**How measured.** `cargo xtask i18n-coverage` (`xtask/src/i18n_coverage.rs`) defines the key
universe: `tl!("…")` literals and `trn(` plurals in `ui-egui` (tests excluded), menu-catalog
@@ -24,7 +24,7 @@ Vietnamese UI; Arabic and Hebrew users get English "Middle East" builds with the
composer, and its text engine handles RTL, Devanagari and Indic scripts.
**Summary.** 7 of the 12 key languages at 100% of measured keys (status `partial` because of the
engine messages), 2 absent (Hindi, Vietnamese), plus 17 other registered languages. Weighted by
engine messages), 2 absent (Hindi, Vietnamese), plus 18 other registered languages. Weighted by
speakers, ~55% ready. Remaining: 80–140 h, plus native-speaker review (recorded only for Italian,
2026-10-12).
@@ -47,13 +47,14 @@ speakers, ~55% ready. Remaining: 80–140 h, plus native-speaker review (recorde
## Other shipped languages
17 registered languages are outside the twelve-language table. The following eight have
18 registered languages are outside the twelve-language table. The following nine have
1,608 / 1,608 measured keys, status `partial` for the same reason: Traditional
Chinese `zh-hant` (2,329 rows), Russian `ru` (4,227 keys; also every dynamic label the
other catalogs translate, [notes](localization-ru.md)), Ukrainian `uk` (3,375), Czech `cs` (3,522),
Polish `pl` (3,366), Greek `el` (3,481), Dutch `nl` (3,568), Italian `it` (4,164; also every dynamic label the
other catalogs translate; reviewed by a native speaker, [notes](localization-it.md)). Hungarian
`hu` (4,347 rows) is also registered. Turkish `tr`
`hu` (4,347 rows) is also registered. Georgian `ka` (4,530 rows; every measured key on 2026-10-31;
Georgian UI fallback font: Noto Sans Georgian, Segoe UI, Sylfaen, SF Georgian, DejaVu Sans; on the web the first served font for `Geor`). Turkish `tr`
(3,731 rows) also covers every measured key. Serbian `sr` (4,022 rows, Latin script, Ekavian, added 2026-10-12) covers every
measured key and the union of the other catalogs' dynamic labels; its one/few/many plurals reuse
the Russian rule. Swedish `sv` (4,552 rows, added 2026-10-28) covers every measured key and the
@@ -113,6 +114,7 @@ engine localization or native review is complete.
| 2026-10-13 | minor | Italian: the `Screen` blend mode read *Schermo* (the display) and is now *Scherma*; the Dodge/Burn/Sponge tool names were already Adobe's (*Scherma*, *Brucia*, *Spugna*) and stay. Pinned by a test |
| 2026-10-18 | minor | Russian: 1,229 dynamic labels added (filter and adjustment parameters, Camera Raw, lighting, History/Layers/paths menus, metadata, System Info, status templates, dialogs) with a terminology note ([localization-ru](localization-ru.md)) |
| 2026-10-22 | minor | Arabic row: paragraph direction has Auto / Left-to-right / Right-to-left buttons in the Paragraph panel and Type options bar (#6793); the visual RTL caret is still missing (TYPE-218-2 partial) |
| 2026-10-22 | minor | Georgian (`ka`) catalog |
| 2026-10-28 | minor | Arabic (`ar`) UI catalog: every measured key, six plural forms; layer names and the title bar no longer reversed on egui 0.37 |
| 2026-10-29 | minor | Swedish (`sv`) UI catalog: every measured key plus the dynamic labels, combined from #5985 and #9536 |
| 2026-10-29 | minor | Finnish (`fi`), Danish (`da`) and Norwegian Bokmål (`nb`) UI catalogs: every measured key plus the dynamic labels, combined from #5666, #6961, #7267, #8072 and #9025 |
+1
View File
@@ -36,6 +36,7 @@ contextual, command-ID and plural translations; missing entries fall back to Eng
| Suomi | `fi` | one / other (partitive after every count but 1) |
| Dansk | `da` | one / other |
| Norsk bokmål | `nb` | one / other |
| ქართული | `ka` | one form (count-neutral: `შრე: {n}`) |
| עברית | `he` | one / other |
| اردو | `ur` | one / other |
| Română | `ro` | one / few (0, 2–19, 101–119 …) / other (20–100, 120 …) |