Merge upstream/main into cs-ui
Keep every entry in contributors/people.toml, and translate the new menu item (Copy Frame to Clipboard) and the five gradient-editor strings into Czech. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,8 @@ pub fn color_popup(ui: &mut Ui, id: egui::Id, pos: egui::Pos2, c: &mut [f32; 3])
|
||||
let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).fixed_pos(pos + vec2(0.0, 4.0)).show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| out = color_picker(ui, id, c, original));
|
||||
});
|
||||
if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
// Escape is the picker's: consume it, so nothing later this pass takes it too.
|
||||
if ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
|
||||
out.close = Some(false);
|
||||
}
|
||||
if pressed_outside(ui.ctx(), &area.response) {
|
||||
@@ -55,11 +56,30 @@ pub fn color_popup(ui: &mut Ui, id: egui::Id, pos: egui::Pos2, c: &mut [f32; 3])
|
||||
ui.data_mut(|d| {
|
||||
d.insert_temp(id.with("open"), false);
|
||||
d.remove::<[f32; 3]>(orig_id);
|
||||
// Closed: the next Escape is the dialog's again.
|
||||
d.remove::<u64>(open_pass_id());
|
||||
});
|
||||
} else {
|
||||
// Still open after this pass: dialogs leave Escape to the picker (see `open_recently`).
|
||||
let pass = ui.ctx().cumulative_pass_nr();
|
||||
ui.data_mut(|d| d.insert_temp(open_pass_id(), pass));
|
||||
}
|
||||
out.changed
|
||||
}
|
||||
|
||||
fn open_pass_id() -> egui::Id {
|
||||
egui::Id::new("color-picker-open-pass")
|
||||
}
|
||||
|
||||
/// A colour picker is open: it was drawn, and stayed open, in this pass or the last one (so one
|
||||
/// that stops being drawn without closing, its dialog gone, doesn't count for long). Escape then
|
||||
/// belongs to the picker (it goes back to the original colour and closes), not to the dialog it
|
||||
/// was opened from. Closing clears this at once, so the next Escape reaches the dialog.
|
||||
pub fn open_recently(ctx: &egui::Context) -> bool {
|
||||
let pass: Option<u64> = ctx.data(|d| d.get_temp(open_pass_id()));
|
||||
pass.is_some_and(|p| p.saturating_add(1) >= ctx.cumulative_pass_nr())
|
||||
}
|
||||
|
||||
/// What the picker did this frame.
|
||||
#[derive(Default)]
|
||||
struct Outcome {
|
||||
|
||||
@@ -133,13 +133,15 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.session.state.selected_layers.iter().filter(|id| c.layer(**id).is_some_and(|l| matches!(l.source, LayerSource::Shape))).map(|id| id.0).collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let layer_paint = shape_layers
|
||||
.first()
|
||||
.and_then(|id| app.session.active_comp()?.layer(LayerId(*id)))
|
||||
.map(|l| effectcraft_engine::commands::shape_stroke::first_paint(l, l.layer_time(app.session.time())));
|
||||
if let Some((fill, stroke, width)) = layer_paint {
|
||||
let layer_paint = shape_layers.first().and_then(|id| app.session.active_comp()?.layer(LayerId(*id))).map(|l| {
|
||||
let lt = l.layer_time(app.session.time());
|
||||
(effectcraft_engine::commands::shape_stroke::first_paint(l, lt), effectcraft_engine::commands::shape_stroke::first_paint_kinds(l, lt))
|
||||
});
|
||||
if let Some(((fill, stroke, width), (fill_kind, stroke_kind))) = layer_paint {
|
||||
let rgb = |c: [f64; 4]| [c[0] as f32, c[1] as f32, c[2] as f32];
|
||||
let tool = &mut app.session.state.shape_tool;
|
||||
tool.fill.kind = fill_kind;
|
||||
tool.stroke.kind = stroke_kind;
|
||||
if let Some(c) = fill {
|
||||
tool.fill.color = rgb(c);
|
||||
}
|
||||
@@ -363,8 +365,7 @@ fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Pa
|
||||
if ui.input(|i| i.modifiers.alt) {
|
||||
let at = PaintKind::ALL.iter().position(|k| *k == tp.kind).unwrap_or(0);
|
||||
let next = PaintKind::ALL.get((at + 1) % PaintKind::ALL.len()).copied().unwrap_or_default();
|
||||
let k = format!("{key}Type");
|
||||
tool_options(app, json!({k: next.id()}));
|
||||
paint_kind(app, shape_layers, key, next);
|
||||
} else if tp.kind == PaintKind::Solid {
|
||||
widgets::open_popup(ui, picker_id(key));
|
||||
} else {
|
||||
@@ -376,7 +377,7 @@ fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Pa
|
||||
tool_options(app, json!({key: c}));
|
||||
paint(app, key, json!(c));
|
||||
}
|
||||
paint_options_popup(app, ui, key, &options, wr.left_bottom());
|
||||
paint_options_popup(app, ui, shape_layers, key, &options, wr.left_bottom());
|
||||
x = sr.max.x + 12.0;
|
||||
}
|
||||
let width = app.session.state.shape_tool.stroke_width;
|
||||
@@ -389,9 +390,28 @@ fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Pa
|
||||
r.max.x + 14.0
|
||||
}
|
||||
|
||||
/// A Fill or Stroke kind: for new shapes, and (as in After Effects) for the selected shape
|
||||
/// layers' fills or strokes, which None switches off (#732).
|
||||
fn paint_kind(app: &mut EffectcraftApp, shape_layers: &[u64], key: &str, kind: PaintKind) {
|
||||
let k_type = format!("{key}Type");
|
||||
tool_options(app, json!({&k_type: kind.id()}));
|
||||
if shape_layers.is_empty() {
|
||||
return;
|
||||
}
|
||||
let mut v = json!({"layers": shape_layers, k_type: kind.id()});
|
||||
// A Solid Color takes the swatch's colour.
|
||||
let color = if key == "fill" { app.session.state.shape_tool.fill.color } else { app.session.state.shape_tool.stroke.color };
|
||||
if let (PaintKind::Solid, Some(o)) = (kind, v.as_object_mut()) {
|
||||
o.insert(key.to_string(), json!(color));
|
||||
}
|
||||
if let Err(e) = app.session.execute("shape.fillStroke", v) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
/// Fill Options / Stroke Options: None, Solid Color, Linear Gradient or Radial Gradient, and the
|
||||
/// blend mode and opacity new shapes get (After Effects' dialogs, applied as they change).
|
||||
fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, key: &str, title: &str, pos: egui::Pos2) {
|
||||
fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, shape_layers: &[u64], key: &str, title: &str, pos: egui::Pos2) {
|
||||
let id = egui::Id::new(("tool-paint-options", key));
|
||||
if !widgets::popup_is_open(ui, id) {
|
||||
return;
|
||||
@@ -400,6 +420,7 @@ fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, key: &str, t
|
||||
let tp = if key == "fill" { &app.session.state.shape_tool.fill } else { &app.session.state.shape_tool.stroke }.clone();
|
||||
let blend_pop = id.with("blend");
|
||||
let mut set = None;
|
||||
let mut kind = None;
|
||||
let mut blend_rect = Rect::NOTHING;
|
||||
let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).fixed_pos(pos + vec2(0.0, 4.0)).show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| {
|
||||
@@ -416,8 +437,7 @@ fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, key: &str, t
|
||||
paint_swatch(&p, r.shrink(3.0), &ToolPaint { kind: k, ..tp.clone() }, resp.hovered(), &t);
|
||||
app.auto.add(&format!("header.{key}Options.{}", k.id()), r, k.label());
|
||||
if resp.clicked() {
|
||||
let k_type = format!("{key}Type");
|
||||
set = Some(json!({k_type: k.id()}));
|
||||
kind = Some(k);
|
||||
}
|
||||
}
|
||||
p.text(row(33.0) + vec2(134.0, 0.0), Align2::LEFT_CENTER, tp.kind.label(), Tokens::ui(11.5), t.text_dim);
|
||||
@@ -451,6 +471,9 @@ fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, key: &str, t
|
||||
if let Some(v) = set {
|
||||
tool_options(app, v);
|
||||
}
|
||||
if let Some(k) = kind {
|
||||
paint_kind(app, shape_layers, key, k);
|
||||
}
|
||||
}
|
||||
|
||||
/// A Fill or Stroke swatch: its colour, a gradient (white to black), or None's red slash.
|
||||
|
||||
@@ -426,6 +426,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "文件..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Photoshop 图层..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "将帧复制到剪贴板"),
|
||||
("render.preRender", "Pre-render...", "预渲染..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "保存当前预览..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "在基本图形中打开"),
|
||||
@@ -1050,6 +1051,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "檔案..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Photoshop 圖層..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "將影格拷貝到剪貼簿"),
|
||||
("render.preRender", "Pre-render...", "預先渲染..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "儲存目前預覽..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "在基本圖形中開啟"),
|
||||
@@ -1671,6 +1673,7 @@ const JAPANESE: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "ファイル..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Photoshopレイヤー..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "フレームをクリップボードにコピー"),
|
||||
("render.preRender", "Pre-render...", "プリレンダリング..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "現在のプレビューを保存..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "エッセンシャルグラフィックスで開く"),
|
||||
@@ -2295,6 +2298,7 @@ const UKRAINIAN: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "Файл..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Шари Photoshop..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "Копіювати кадр у буфер обміну"),
|
||||
("render.preRender", "Pre-render...", "Попередній рендеринг..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "Зберегти поточний попередній перегляд..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "Відкрити в основній графіці"),
|
||||
@@ -2920,6 +2924,7 @@ const SPANISH: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "Archivo..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Capas de Photoshop..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "Copiar fotograma al portapapeles"),
|
||||
("render.preRender", "Pre-render...", "Preprocesar..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "Guardar la previsualización actual..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "Abrir en Gráficos esenciales"),
|
||||
@@ -3543,6 +3548,7 @@ const PORTUGUESE: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "Arquivo..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Camadas do Photoshop..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "Copiar quadro para a área de transferência"),
|
||||
("render.preRender", "Pre-render...", "Pré-renderização..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "Salvar pré-visualização atual..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "Abrir em Gráficos essenciais"),
|
||||
@@ -4165,6 +4171,7 @@ const CZECH: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "Soubor..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Vrstvy Photoshopu..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "Kopírovat snímek do schránky"),
|
||||
("render.preRender", "Pre-render...", "Předvykreslit..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "Uložit aktuální náhled..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "Otevřít v základní grafice"),
|
||||
|
||||
@@ -147,6 +147,10 @@ const JAPANESE: &[(&str, &str)] = &[
|
||||
("Clear", "消去"),
|
||||
("Clear list", "リストを消去"),
|
||||
("Click a key to see its commands.", "キーをクリックすると、割り当てられたコマンドが表示されます。"),
|
||||
(
|
||||
"Click above the bar to add an opacity stop, below it to add a color stop.",
|
||||
"バーの上をクリックすると不透明度の分岐点、下をクリックするとカラーの分岐点を追加します。",
|
||||
),
|
||||
("Click adds a point (½ height = no change)", "クリックでポイントを追加(高さの½=変化なし)"),
|
||||
("Click adds a point; drag one off to remove", "クリックでポイントを追加、外へドラッグで削除"),
|
||||
("Click to make this viewer active", "クリックしてこのビューアーをアクティブ化"),
|
||||
@@ -240,6 +244,7 @@ const JAPANESE: &[(&str, &str)] = &[
|
||||
("Frame Render Time {}ms", "フレームのレンダリング時間 {}ms"),
|
||||
("Frame Target:", "フレームターゲット:"),
|
||||
("Grab bag", "いろいろ"),
|
||||
("Gradient Editor", "グラデーションエディター"),
|
||||
("Grid", "グリッド"),
|
||||
("Guide Layers: {}", "ガイドレイヤー:{}"),
|
||||
("Guides", "ガイド"),
|
||||
@@ -276,6 +281,7 @@ const JAPANESE: &[(&str, &str)] = &[
|
||||
("Light Type", "ライトの種類"),
|
||||
("Lighter", "明るく"),
|
||||
("Link Selected Property", "選択したプロパティをリンク"),
|
||||
("Location:", "位置:"),
|
||||
("Lock Aspect Ratio to {}", "アスペクト比を{}に固定"),
|
||||
("Lock to Zoom", "ズームにロック"),
|
||||
("Locked: {} — {}", "ロック済み:{} — {}"),
|
||||
@@ -324,6 +330,7 @@ const JAPANESE: &[(&str, &str)] = &[
|
||||
("No layer selected", "レイヤーが選択されていません"),
|
||||
("No matching effects or presets", "一致するエフェクトまたはプリセットはありません"),
|
||||
("No matching fonts", "一致するフォントはありません"),
|
||||
("Variable fonts only", "可変フォントのみ"),
|
||||
("No model credits were built into this copy.", "このビルドにはモデルのクレジットが含まれていません。"),
|
||||
("No nested compositions", "ネストされたコンポジションはありません"),
|
||||
("No shortcut", "ショートカットなし"),
|
||||
@@ -463,6 +470,7 @@ const JAPANESE: &[(&str, &str)] = &[
|
||||
("The Media Browser is not available here (use File ▸ Import)", "ここではメディアブラウザーを使用できません(「ファイル ▸ 読み込み」を使ってください)"),
|
||||
("The OpenEXR layer shown in red, green, blue and alpha", "赤・緑・青・アルファとして表示するOpenEXRレイヤー"),
|
||||
("The render queue is empty.", "レンダーキューは空です。"),
|
||||
("These adjacent keyframes cannot interpolate because their stop counts differ.", "これらの隣接するキーフレームは分岐点の数が異なるため、補間できません。"),
|
||||
("This ScriptUI panel has closed", "このScriptUIパネルは閉じられました"),
|
||||
("This change will create a new solid for this layer.", "この変更により、このレイヤー用に新しい平面が作成されます。"),
|
||||
("Time", "時間"),
|
||||
@@ -579,6 +587,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
|
||||
("Clear", "清除"),
|
||||
("Clear list", "清空列表"),
|
||||
("Click a key to see its commands.", "单击某个按键以查看其命令。"),
|
||||
("Click above the bar to add an opacity stop, below it to add a color stop.", "点击渐变条上方添加不透明度色标,点击下方添加颜色色标。"),
|
||||
("Click adds a point (½ height = no change)", "单击可添加点(上下滑动高度的一半 = 无变化)"),
|
||||
("Click adds a point; drag one off to remove", "单击可添加点;拖出一个即可删除"),
|
||||
("Click to make this viewer active", "单击可激活此视图"),
|
||||
@@ -675,6 +684,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
|
||||
("Frame Target:", "帧目标:"),
|
||||
("Freeze", "冻结"),
|
||||
("Grab bag", "列表"),
|
||||
("Gradient Editor", "渐变编辑器"),
|
||||
("Grid", "网格"),
|
||||
("Guide Layers: {}", "参考图层:{}"),
|
||||
("Guides", "参考线"),
|
||||
@@ -713,6 +723,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
|
||||
("Light Type", "灯光类型"),
|
||||
("Lighter", "更浅"),
|
||||
("Link Selected Property", "链接所选属性"),
|
||||
("Location:", "位置:"),
|
||||
("Lock Aspect Ratio to {}", "锁定长宽比为 {}"),
|
||||
("Lock to Zoom", "锁定缩放"),
|
||||
("Locked: {} — {}", "已锁定:{} — {}"),
|
||||
@@ -758,6 +769,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
|
||||
("No layer selected", "未选择图层"),
|
||||
("No matching effects or presets", "没有匹配的效果或预设"),
|
||||
("No matching fonts", "没有匹配的字体"),
|
||||
("Variable fonts only", "仅可变字体"),
|
||||
("No model credits were built into this copy.", "此副本未内置模型致谢。"),
|
||||
("No nested compositions", "没有嵌套合成"),
|
||||
("No shortcut", "无快捷键"),
|
||||
@@ -901,6 +913,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
|
||||
("The Media Browser is not available here (use File ▸ Import)", "此处不支持媒体浏览器(请使用 文件 ▸ 导入)"),
|
||||
("The OpenEXR layer shown in red, green, blue and alpha", "以红、绿、蓝和 Alpha 显示的 OpenEXR 图层"),
|
||||
("The render queue is empty.", "渲染队列为空。"),
|
||||
("These adjacent keyframes cannot interpolate because their stop counts differ.", "这些相邻关键帧的色标数量不同,无法插值。"),
|
||||
("This ScriptUI panel has closed", "此 ScriptUI 面板已关闭"),
|
||||
("This change will create a new solid for this layer.", "此更改将为该图层创建新的纯色。"),
|
||||
("Time", "时间"),
|
||||
@@ -1104,6 +1117,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
|
||||
("Clear", "清除"),
|
||||
("Clear list", "清空清單"),
|
||||
("Click a key to see its commands.", "按一下某個按鍵以查看其命令。"),
|
||||
("Click above the bar to add an opacity stop, below it to add a color stop.", "按一下漸變條上方以新增不透明度色標,按一下下方以新增顏色色標。"),
|
||||
("Click adds a point (½ height = no change)", "按一下可添加點(上下滑動高度的一半 = 無變化)"),
|
||||
("Click adds a point; drag one off to remove", "按一下可添加點;拖出一個即可刪除"),
|
||||
("Click to make this viewer active", "按一下可激活此檢視"),
|
||||
@@ -1200,6 +1214,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
|
||||
("Frame Target:", "幀目標:"),
|
||||
("Freeze", "凍結"),
|
||||
("Grab bag", "清單"),
|
||||
("Gradient Editor", "漸變編輯器"),
|
||||
("Grid", "格點"),
|
||||
("Guide Layers: {}", "參考圖層:{}"),
|
||||
("Guides", "參考線"),
|
||||
@@ -1238,6 +1253,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
|
||||
("Light Type", "燈光類型"),
|
||||
("Lighter", "更淺"),
|
||||
("Link Selected Property", "鏈接所選屬性"),
|
||||
("Location:", "位置:"),
|
||||
("Lock Aspect Ratio to {}", "鎖定長寬比例為 {}"),
|
||||
("Lock to Zoom", "鎖定縮放"),
|
||||
("Locked: {} — {}", "已鎖定:{} — {}"),
|
||||
@@ -1283,6 +1299,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
|
||||
("No layer selected", "未選取圖層"),
|
||||
("No matching effects or presets", "沒有匹配的效果或預設集"),
|
||||
("No matching fonts", "沒有符合的字體"),
|
||||
("Variable fonts only", "僅可變字型"),
|
||||
("No model credits were built into this copy.", "此副本未內置模型致謝。"),
|
||||
("No nested compositions", "沒有嵌套合成"),
|
||||
("No shortcut", "無快速鍵"),
|
||||
@@ -1426,6 +1443,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
|
||||
("The Media Browser is not available here (use File ▸ Import)", "此處不支援媒體瀏覽器(請使用 文件 ▸ 匯入)"),
|
||||
("The OpenEXR layer shown in red, green, blue and alpha", "以紅、綠、藍和 Alpha 顯示的 OpenEXR 圖層"),
|
||||
("The render queue is empty.", "算圖佇列為空。"),
|
||||
("These adjacent keyframes cannot interpolate because their stop counts differ.", "這些相鄰關鍵影格的色標數量不同,無法內插。"),
|
||||
("This ScriptUI panel has closed", "此 ScriptUI 面板已關閉"),
|
||||
("This change will create a new solid for this layer.", "此更改將為該圖層創建新的純色。"),
|
||||
("Time", "時間"),
|
||||
@@ -1624,6 +1642,10 @@ const UKRAINIAN: &[(&str, &str)] = &[
|
||||
("Clear", "Очистити"),
|
||||
("Clear list", "Очистити список"),
|
||||
("Click a key to see its commands.", "Клацніть клавішу, щоб переглянути її команди."),
|
||||
(
|
||||
"Click above the bar to add an opacity stop, below it to add a color stop.",
|
||||
"Клацніть над смугою, щоб додати точку непрозорості, під нею — щоб додати точку кольору.",
|
||||
),
|
||||
("Click adds a point (½ height = no change)", "Клацніть, щоб додати точку (½ висоти = без змін)"),
|
||||
("Click adds a point; drag one off to remove", "Клацніть, щоб додати точку; перетягніть її за межі, щоб вилучити"),
|
||||
("Click to make this viewer active", "Клацніть, щоб зробити цю область перегляду активною"),
|
||||
@@ -1717,6 +1739,7 @@ const UKRAINIAN: &[(&str, &str)] = &[
|
||||
("Frame Render Time {}ms", "Час рендерингу кадру {} мс"),
|
||||
("Frame Target:", "Цільовий фрейм:"),
|
||||
("Grab bag", "Список"),
|
||||
("Gradient Editor", "Редактор градієнта"),
|
||||
("Grid", "Сітка"),
|
||||
("Guide Layers: {}", "Допоміжні шари: {}"),
|
||||
("Guides", "Напрямні"),
|
||||
@@ -1753,6 +1776,7 @@ const UKRAINIAN: &[(&str, &str)] = &[
|
||||
("Light Type", "Тип світла"),
|
||||
("Lighter", "Світліше"),
|
||||
("Link Selected Property", "Зв’язати виділену властивість"),
|
||||
("Location:", "Розташування:"),
|
||||
("Lock Aspect Ratio to {}", "Зафіксувати співвідношення сторін на {}"),
|
||||
("Lock to Zoom", "Прив’язати до масштабу"),
|
||||
("Locked: {} — {}", "Заблоковано: {} — {}"),
|
||||
@@ -1804,6 +1828,7 @@ const UKRAINIAN: &[(&str, &str)] = &[
|
||||
("No layer selected", "Шар не виділено"),
|
||||
("No matching effects or presets", "Не знайдено відповідних ефектів або наборів"),
|
||||
("No matching fonts", "Не знайдено відповідних шрифтів"),
|
||||
("Variable fonts only", "Лише змінні шрифти"),
|
||||
("No model credits were built into this copy.", "Ця копія не містить відомостей про моделі."),
|
||||
("No nested compositions", "Немає вкладених композицій"),
|
||||
("No shortcut", "Немає клавіатурного скорочення"),
|
||||
@@ -1943,6 +1968,10 @@ const UKRAINIAN: &[(&str, &str)] = &[
|
||||
("The Media Browser is not available here (use File ▸ Import)", "Браузер матеріалів тут недоступний (скористайтеся меню «Файл ▸ Імпорт»)"),
|
||||
("The OpenEXR layer shown in red, green, blue and alpha", "Шар OpenEXR, показаний у червоному, зеленому, синьому та альфа-каналі"),
|
||||
("The render queue is empty.", "Черга рендерингу порожня."),
|
||||
(
|
||||
"These adjacent keyframes cannot interpolate because their stop counts differ.",
|
||||
"Ці сусідні ключові кадри не можуть інтерполюватися, бо кількість точок у них різна.",
|
||||
),
|
||||
("This ScriptUI panel has closed", "Цю панель ScriptUI закрито"),
|
||||
("This change will create a new solid for this layer.", "Ця зміна створить новий матеріал суцільного кольору для цього шару."),
|
||||
("Time", "Час"),
|
||||
@@ -2517,6 +2546,14 @@ const CZECH: &[(&str, &str)] = &[
|
||||
("After Effects project", "Projekt After Effects"),
|
||||
("Lottie animation", "Animace Lottie"),
|
||||
("Project", "Projekt"),
|
||||
("Click above the bar to add an opacity stop, below it to add a color stop.", "Kliknutím nad pruh přidáte bod krytí, kliknutím pod něj bod barvy."),
|
||||
("Gradient Editor", "Editor přechodu"),
|
||||
("Location:", "Umístění:"),
|
||||
(
|
||||
"These adjacent keyframes cannot interpolate because their stop counts differ.",
|
||||
"Tyto sousední klíčové snímky nelze interpolovat, protože mají různý počet bodů přechodu.",
|
||||
),
|
||||
("Variable fonts only", "Jen proměnná písma"),
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -2536,6 +2573,7 @@ mod tests {
|
||||
("panels/comp_settings.rs", include_str!("../panels/comp_settings.rs")),
|
||||
("panels/content_fill_panel.rs", include_str!("../panels/content_fill_panel.rs")),
|
||||
("panels/delete_items.rs", include_str!("../panels/delete_items.rs")),
|
||||
("panels/gradient_editor.rs", include_str!("../panels/gradient_editor.rs")),
|
||||
("panels/dialogs.rs", include_str!("../panels/dialogs.rs")),
|
||||
("panels/dialogs_3d.rs", include_str!("../panels/dialogs_3d.rs")),
|
||||
("panels/effect_controls.rs", include_str!("../panels/effect_controls.rs")),
|
||||
|
||||
@@ -94,6 +94,8 @@ pub enum Dialog {
|
||||
UnsavedChanges,
|
||||
/// Delete Project items that compositions use? (`panels::delete_items`).
|
||||
DeleteItems,
|
||||
/// A gradient property's Gradient Editor (`panels::gradient_editor`, `prop.editGradient`).
|
||||
GradientEditor,
|
||||
}
|
||||
|
||||
/// The desktop's light or dark appearance where egui cannot see it (Wayland compositors that send
|
||||
@@ -544,6 +546,17 @@ impl EffectcraftApp {
|
||||
self.ui.saved_workspaces.keys().filter(|k| !dock::WORKSPACES.contains(&k.as_str())).cloned().collect()
|
||||
}
|
||||
|
||||
/// The open Gradient Editor's draft (`panels::gradient_editor`): what OK would set.
|
||||
pub fn gradient_draft(&self) -> &panels::gradient_editor::Draft {
|
||||
&self.dialog_state.gradient
|
||||
}
|
||||
|
||||
/// The open Gradient Editor's draft, to edit (tests and automation; the editor's own fields
|
||||
/// do the same).
|
||||
pub fn gradient_draft_mut(&mut self) -> &mut panels::gradient_editor::Draft {
|
||||
&mut self.dialog_state.gradient
|
||||
}
|
||||
|
||||
/// Show panel `p` (opening it in its usual place if it is closed), bring it to the front and
|
||||
/// give it the focus: Window ▸ <panel>.
|
||||
pub fn show_panel(&mut self, p: PanelKind) {
|
||||
@@ -1542,6 +1555,11 @@ impl EffectcraftApp {
|
||||
}
|
||||
}
|
||||
effectcraft_engine::Event::PurgeCaches => self.frames.clear(),
|
||||
effectcraft_engine::Event::CopyImage { width, height, rgba } => {
|
||||
if let Err(e) = copy_image(ctx, width, height, &rgba) {
|
||||
self.ui.status = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1585,6 +1603,7 @@ impl EffectcraftApp {
|
||||
self.session.poll_camera(true);
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(100));
|
||||
}
|
||||
self.run_script_tasks(&ctx);
|
||||
self.apply_prefs(&ctx);
|
||||
self.handle_events(&ctx);
|
||||
panels::unsaved::on_close_requested(self, &ctx);
|
||||
@@ -1696,6 +1715,24 @@ impl EffectcraftApp {
|
||||
}
|
||||
|
||||
impl EffectcraftApp {
|
||||
/// Scripts' `app.scheduleTask` tasks that are due (repeating ones keep a ScriptUI panel
|
||||
/// fresh): errors as a toast, the last line printed in the status bar, and a repaint when
|
||||
/// the next one is due.
|
||||
fn run_script_tasks(&mut self, ctx: &egui::Context) {
|
||||
if self.session.script_ui.task_hosts.is_empty() {
|
||||
return;
|
||||
}
|
||||
let Some(r) = effectcraft_engine::scriptui::ScriptUi::run_tasks(&mut self.session) else { return };
|
||||
if let Some(msg) = r["errors"].as_array().and_then(|e| e.first()).and_then(|e| e["message"].as_str()) {
|
||||
self.toast = Some((format!("Scheduled script task: {msg}"), ctx.input(|i| i.time)));
|
||||
} else if let Some(line) = r["output"].as_array().and_then(|o| o.last()).and_then(|l| l.as_str()) {
|
||||
self.ui.status = line.to_string();
|
||||
}
|
||||
if let Some(next) = r["next"].as_u64() {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(next));
|
||||
}
|
||||
}
|
||||
|
||||
/// Auto-save a dirty project when the interval has passed (Settings ▸ Project ▸ Auto-Save).
|
||||
fn tick_autosave(&mut self, ctx: &egui::Context) {
|
||||
let now = web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).map(|d| d.as_secs_f64()).unwrap_or(0.0);
|
||||
@@ -1862,6 +1899,18 @@ pub(crate) fn tick_playback(app: &mut EffectcraftApp, ctx: &egui::Context, scale
|
||||
app.advance_playback(ctx, scale);
|
||||
}
|
||||
|
||||
/// Put `width` × `height` straight-alpha RGBA8 pixels on the system clipboard (Composition ▸ Copy
|
||||
/// Frame to Clipboard). The pixel count is checked first: egui's image constructor panics on a
|
||||
/// size that doesn't match its buffer.
|
||||
fn copy_image(ctx: &egui::Context, width: u32, height: u32, rgba: &[u8]) -> Result<(), String> {
|
||||
let (w, h) = (width as usize, height as usize);
|
||||
if w == 0 || h == 0 || w.checked_mul(h).and_then(|n| n.checked_mul(4)) != Some(rgba.len()) {
|
||||
return Err(format!("cannot copy a malformed {width}×{height} image to the clipboard"));
|
||||
}
|
||||
ctx.copy_image(egui::ColorImage::from_rgba_unmultiplied([w, h], rgba));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Maximize a first window that doesn't fit the screen, which fits it to the space beside the
|
||||
/// taskbar or dock. The 1680 × 1020 window on a smaller screen is only shrunk to the monitor's
|
||||
/// size, so with its title bar it ran under the taskbar and cut menus off at the bottom of the
|
||||
@@ -1895,6 +1944,55 @@ mod fit_window_tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod copy_frame_tests {
|
||||
use super::*;
|
||||
|
||||
fn copied(output: &egui::FullOutput) -> Vec<&egui::ColorImage> {
|
||||
output
|
||||
.platform_output
|
||||
.commands
|
||||
.iter()
|
||||
.filter_map(|c| match c {
|
||||
egui::OutputCommand::CopyImage(image) => Some(image),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Composition ▸ Copy Frame to Clipboard puts the rendered frame on the system clipboard.
|
||||
#[test]
|
||||
fn copy_frame_puts_the_frame_on_the_clipboard() {
|
||||
let mut session = Session::default();
|
||||
session.execute("comp.new", json!({"name": "Copy", "width": 8, "height": 6, "duration": 1})).unwrap();
|
||||
session.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap();
|
||||
let mut app = EffectcraftApp::new(session);
|
||||
let ctx = egui::Context::default();
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
crate::menus::invoke(&mut app, ui.ctx(), "comp.copyFrame", json!({})).unwrap();
|
||||
app.handle_events(ui.ctx());
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
let images = copied(&output);
|
||||
assert_eq!(images.len(), 1);
|
||||
assert_eq!(images[0].size, [8, 6]);
|
||||
assert!(images[0].pixels.iter().all(|p| *p == egui::Color32::from_rgb(255, 0, 0)));
|
||||
}
|
||||
|
||||
/// A malformed image never reaches egui's panicking constructor.
|
||||
#[test]
|
||||
fn a_malformed_image_is_an_error_not_a_crash() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
assert!(copy_image(ui.ctx(), 4, 4, &[0; 10]).is_err());
|
||||
assert!(copy_image(ui.ctx(), 0, 4, &[]).is_err());
|
||||
assert!(copy_image(ui.ctx(), u32::MAX, u32::MAX, &[0; 4]).is_err());
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
assert!(copied(&output).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod gpu_failure_tests {
|
||||
use super::*;
|
||||
|
||||
@@ -291,6 +291,15 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
// Edit ▸ Paste with SVG markup on the system clipboard pastes it as a shape layer (After
|
||||
// Effects 26.3). Copying in the app replaces the system clipboard with a note naming what
|
||||
// was copied, so SVG there was copied after anything copied in the app.
|
||||
if id == "edit.paste" && no_params(¶ms) && app.session.state.text_edit.is_none() {
|
||||
let text = ctx.data_mut(|d| d.remove_temp::<String>(system_paste_id())).or_else(|| app.hooks.clipboard_text.as_ref().and_then(|f| f()));
|
||||
if let Some(svg) = text.filter(|t| effectcraft_engine::vector::is_svg_text(t)) {
|
||||
return run_engine(app, ctx, "edit.pasteSvg", json!({"svg": svg}));
|
||||
}
|
||||
}
|
||||
// Clear follows panel focus, including the Edit menu and keyboard shortcut.
|
||||
if id == "edit.clear" && params.as_object().is_some_and(|p| p.is_empty()) && app.ui.focused == PanelKind::Project {
|
||||
// Through `invoke`, so deleting items that compositions use still asks first (M3.16).
|
||||
@@ -758,6 +767,8 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
"view.newViewer" => json!({"viewer": crate::panels::viewers::new_viewer(app)}),
|
||||
// Run by id (control channel, MCP): the Project panel's selection, whatever has focus.
|
||||
"project.deleteWithoutConfirmation" => crate::panels::delete_items::delete_confirmed(app, ctx, json!({}))?,
|
||||
// A gradient property's "Edit Gradient…" (the Timeline's value): the Gradient Editor.
|
||||
"prop.editGradient" => crate::panels::gradient_editor::open(app, &p)?,
|
||||
"window.scriptPanel" => {
|
||||
let id = p.get("window").and_then(Value::as_u64).ok_or("no ScriptUI panel window")? as u32;
|
||||
app.show_panel(PanelKind::ScriptPanel(id));
|
||||
@@ -773,12 +784,12 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
Value::Null
|
||||
}
|
||||
"app.gpuInfo" => {
|
||||
let threads = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1);
|
||||
crate::panels::dialogs::info(
|
||||
app,
|
||||
"GPU Information",
|
||||
&format!(
|
||||
"Compositing: CPU, {threads} threads (pure Rust, rayon).\nDisplay: egui on wgpu.\nLayer cache: {} MB • Preview cache: {} MB.",
|
||||
"{}Layer cache: {} MB • Preview cache: {} MB.",
|
||||
effectcraft_engine::sysinfo::gpu_summary(&app.session),
|
||||
app.session.layer_cache.budget() >> 20,
|
||||
app.frames.budget() >> 20
|
||||
),
|
||||
@@ -1226,7 +1237,7 @@ fn file_dialog(app: &mut EffectcraftApp, id: &str, params: &Value) -> Option<Res
|
||||
}
|
||||
const MEDIA: &[&str] = &[
|
||||
"mp4", "mov", "m4v", "mkv", "webm", "png", "jpg", "jpeg", "gif", "webp", "tif", "tiff", "bmp", "exr", "wav", "aif", "aiff", "mp3", "flac", "ogg",
|
||||
"opus", "svg", "pdf", "ai", "eps", "psd", "psb", "gltf", "glb", "obj", "json", "csv", "tsv",
|
||||
"opus", "svg", "pdf", "ai", "eps", "psd", "psb", "gltf", "glb", "obj", "stl", "json", "csv", "tsv",
|
||||
];
|
||||
// A host whose modal dialogs would run a nested event loop inside this frame (macOS: a
|
||||
// drag over the window then re-entered winit's event handler and aborted, #511) shows the
|
||||
@@ -1561,6 +1572,11 @@ fn mods_match(want: egui::Modifiers, got: egui::Modifiers) -> bool {
|
||||
|
||||
/// Set (egui temp data) from a plain Spacebar press until its release while a tap would still
|
||||
/// run the Spacebar shortcut.
|
||||
/// The system clipboard's text of this frame's paste event, for the Edit ▸ Paste it runs.
|
||||
fn system_paste_id() -> egui::Id {
|
||||
egui::Id::new("menus-system-paste")
|
||||
}
|
||||
|
||||
fn space_tap_id() -> egui::Id {
|
||||
egui::Id::new("spacebar-tap")
|
||||
}
|
||||
@@ -1606,7 +1622,8 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
let start = modifiers_at_start(ctx);
|
||||
// Dialog cancellation owns Escape even when a text field has keyboard focus.
|
||||
if !tab_only && app.dialog.is_some() && ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
if crate::panels::shortcut_editor::recording(app) || egui::Popup::is_any_open(ctx) {
|
||||
// A popup or colour picker takes Escape first (the picker goes back to its original colour).
|
||||
if crate::panels::shortcut_editor::recording(app) || egui::Popup::is_any_open(ctx) || crate::color_picker::open_recently(ctx) {
|
||||
return;
|
||||
}
|
||||
ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape));
|
||||
@@ -1641,6 +1658,9 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
// Text editing in the viewer takes the clipboard events itself.
|
||||
let clipboard = app.session.state.text_edit.is_none();
|
||||
let project = app.ui.focused == PanelKind::Project;
|
||||
// The paste event's text: Edit ▸ Paste pastes SVG markup as a shape layer.
|
||||
let pasted =
|
||||
if clipboard { ctx.input(|i| i.events.iter().rev().find_map(|e| if let egui::Event::Paste(t) = e { Some(t.clone()) } else { None })) } else { None };
|
||||
let mut events: Vec<(egui::Key, egui::Modifiers, bool)> = ctx.input(|i| {
|
||||
// The windowing layer turns Ctrl+C / Ctrl+X / Ctrl+V into clipboard events instead of
|
||||
// key presses: map them back to the keys (with the modifiers held) so Edit ▸ Copy, Cut,
|
||||
@@ -1756,9 +1776,15 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
}
|
||||
if let Some((_, _, id, params)) = binds.iter().find(|(m, k, ..)| *k == key && mods_match(*m, mods)) {
|
||||
let (id, params) = (id.clone(), if params.is_null() { json!({}) } else { params.clone() });
|
||||
if id == "edit.paste"
|
||||
&& let Some(t) = &pasted
|
||||
{
|
||||
ctx.data_mut(|d| d.insert_temp(system_paste_id(), t.clone()));
|
||||
}
|
||||
if let Err(e) = invoke(app, ctx, &id, params) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
ctx.data_mut(|d| d.remove_temp::<String>(system_paste_id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ pub struct DialogState {
|
||||
pub unsaved: super::unsaved::Pending,
|
||||
/// Deleting Project items in use: the deletion waiting on the prompt.
|
||||
pub delete_items: super::delete_items::Pending,
|
||||
/// The Gradient Editor's draft and the property it edits.
|
||||
pub gradient: super::gradient_editor::Draft,
|
||||
}
|
||||
|
||||
pub fn open_new_comp(app: &mut EffectcraftApp) {
|
||||
@@ -149,9 +151,23 @@ pub fn route_layer_settings(app: &mut EffectcraftApp, id: &str, params: &Value)
|
||||
}
|
||||
}
|
||||
|
||||
/// The room a modal dialog may take: the window less a margin.
|
||||
fn modal_space(ctx: &egui::Context) -> egui::Vec2 {
|
||||
(ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0))
|
||||
}
|
||||
|
||||
pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
|
||||
let available = (ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0));
|
||||
let size = size.min(available);
|
||||
let max_height = (modal_space(ctx).y - 84.0).max(40.0);
|
||||
modal_fit(ctx, title, size, t, |ui, _| {
|
||||
egui::ScrollArea::both().max_height(max_height).auto_shrink([false, true]).show(ui, body);
|
||||
});
|
||||
}
|
||||
|
||||
/// [`modal`] without its scroll area, for a dialog that keeps its buttons in view and scrolls
|
||||
/// only its content: `body` gets the height left under the title, with `size` kept within the
|
||||
/// window.
|
||||
pub(crate) fn modal_fit(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui, f32)) {
|
||||
let size = size.min(modal_space(ctx));
|
||||
egui::Modal::new(egui::Id::new(("modal", title)))
|
||||
.backdrop_color(Color32::from_black_alpha(120))
|
||||
.frame(egui::Frame::window(&ctx.style_of(ctx.theme())).fill(t.panel_bg).inner_margin(egui::Margin::same(18)))
|
||||
@@ -161,7 +177,8 @@ pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Toke
|
||||
// The id stays keyed on the untranslated source, so switching language cannot move it.
|
||||
ui.label(egui::RichText::new(tr(title)).font(Tokens::semibold(15.0)).color(t.tab_text_active));
|
||||
ui.add_space(10.0);
|
||||
egui::ScrollArea::both().max_height((available.y - 84.0).max(40.0)).auto_shrink([false, true]).show(ui, body);
|
||||
let title_h = ui.cursor().top() - ui.min_rect().top();
|
||||
body(ui, (size.y - 36.0 - title_h).max(40.0));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -193,6 +210,7 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
Dialog::RenderTemplates => super::rq_templates::show(app, ctx, &t),
|
||||
Dialog::UnsavedChanges => super::unsaved::show(app, ctx, &t),
|
||||
Dialog::DeleteItems => super::delete_items::show(app, ctx, &t),
|
||||
Dialog::GradientEditor => super::gradient_editor::show(app, ctx, &t),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1415,6 +1415,9 @@ pub fn viewer_hook(
|
||||
if !picking && app.ui.viewer.show_layer_controls && matches!(&g.kind, GroupKind::Effect { effect } if effect == super::fx_editors::RESHAPE) {
|
||||
super::fx_editors::reshape_overlay(app, ui, painter, map, ectx, layer, g, &m, &mut actions);
|
||||
}
|
||||
if !picking && app.ui.viewer.show_layer_controls && matches!(&g.kind, GroupKind::Effect { effect } if effect == super::fx_editors::MESH_WARP) {
|
||||
super::fx_editors::mesh_warp_overlay(app, ui, painter, map, ectx, layer, g, &fm, &mut actions);
|
||||
}
|
||||
let scope = FxScope { effect: &g.match_id, root: g, path: String::new() };
|
||||
let mut pts = Vec::new();
|
||||
visible_points(g, &scope, layer, ectx, 0, &mut pts);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Effects & Presets: search (matches highlighted), the contents menu (colour-depth / GPU
|
||||
//! filters, animation presets on/off, categories or alphabetical, refresh), Favorites (star an
|
||||
//! effect), Recently Used, "* Animation Presets" (EffectCraft's own text animation presets and
|
||||
//! the user's `.ecpreset` files) and the effect categories. Double-click applies to the
|
||||
//! effect), Recently Used, "* Animation Presets" (EffectCraft's own text animation and transition
|
||||
//! presets and the user's `.ecpreset` files) and the effect categories. Double-click applies to the
|
||||
//! selected layers; dragging an effect onto a layer (timeline, viewer, Effect Controls) applies
|
||||
//! it there.
|
||||
|
||||
@@ -108,6 +108,8 @@ fn highlighted(p: &egui::Painter, pos: egui::Pos2, name: &str, query: &str, t: &
|
||||
enum Apply {
|
||||
Effect(String),
|
||||
TextPreset(String),
|
||||
/// A built-in animation preset (Transitions…) by id.
|
||||
Builtin(String),
|
||||
PresetFile(String),
|
||||
}
|
||||
|
||||
@@ -340,18 +342,35 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
|
||||
// * Animation Presets: our text presets and the user's .ecpreset files.
|
||||
// * Animation Presets: our own presets (Text, Transitions…) and the user's .ecpreset files.
|
||||
if view.presets {
|
||||
let text: Vec<(String, String)> =
|
||||
effectcraft_engine::text_presets().into_iter().filter(|(_, n)| query.is_empty() || n.to_lowercase().contains(&query)).collect();
|
||||
let builtin: Vec<(String, String, String)> =
|
||||
effectcraft_engine::animation_presets().into_iter().filter(|(_, n, _)| query.is_empty() || n.to_lowercase().contains(&query)).collect();
|
||||
let mut categories: Vec<&str> = Vec::new();
|
||||
for (_, _, c) in &builtin {
|
||||
if !categories.contains(&c.as_str()) {
|
||||
categories.push(c);
|
||||
}
|
||||
}
|
||||
let files: Vec<PresetFile> =
|
||||
user_presets(&ctx, force_scan).into_iter().filter(|f| query.is_empty() || f.name.to_lowercase().contains(&query)).collect();
|
||||
if (!text.is_empty() || !files.is_empty()) && folder_row(app, ui, &lp, list, &mut y, "presets", "* Animation Presets", 0.0, searching, None) {
|
||||
let any = !text.is_empty() || !builtin.is_empty() || !files.is_empty();
|
||||
if any && folder_row(app, ui, &lp, list, &mut y, "presets", "* Animation Presets", 0.0, searching, None) {
|
||||
if !text.is_empty() && folder_row(app, ui, &lp, list, &mut y, "presets/Text", "Text", 14.0, searching, None) {
|
||||
for (id, name) in text {
|
||||
preset_row(app, ui, &lp, list, &mut y, &name, &format!("effects.preset.text.{id}"), &query, Apply::TextPreset(id.clone()), &mut apply);
|
||||
}
|
||||
}
|
||||
for cat in &categories {
|
||||
if !folder_row(app, ui, &lp, list, &mut y, &format!("presets/{cat}"), cat, 14.0, searching, None) {
|
||||
continue;
|
||||
}
|
||||
for (id, name, _) in builtin.iter().filter(|(_, _, c)| c == cat) {
|
||||
preset_row(app, ui, &lp, list, &mut y, name, &format!("effects.preset.builtin.{id}"), &query, Apply::Builtin(id.clone()), &mut apply);
|
||||
}
|
||||
}
|
||||
if !files.is_empty() && folder_row(app, ui, &lp, list, &mut y, "presets/User", "User Presets", 14.0, searching, None) {
|
||||
for f in files {
|
||||
preset_row(
|
||||
@@ -418,6 +437,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let (cmd, params) = match &apply {
|
||||
Apply::Effect(id) => ("effect.apply", json!({"effect": id})),
|
||||
Apply::TextPreset(id) => ("layer.applyTextPreset", json!({"preset": id})),
|
||||
Apply::Builtin(id) => ("anim.applyBuiltinPreset", json!({"preset": id})),
|
||||
Apply::PresetFile(path) => ("anim.applyPreset", json!({"path": path})),
|
||||
};
|
||||
match app.session.execute(cmd, params) {
|
||||
|
||||
@@ -215,16 +215,15 @@ pub fn open_form(app: &mut EffectcraftApp, id: &str, p: &Value) -> bool {
|
||||
let lt = layer.map(|l| l.layer_time(t)).unwrap_or(t);
|
||||
let base = p.clone();
|
||||
let (title, fields): (String, Vec<Field>) = match id {
|
||||
// Photoshop files: Import Kind (Footage / Composition / – Retain Layer Sizes).
|
||||
"file.import" if !has(p, &["importAs"]) && is_layered(p) => (
|
||||
"Import Photoshop File".into(),
|
||||
vec![Field::choice(
|
||||
"importAs",
|
||||
"Import Kind",
|
||||
&[("Footage", json!("footage")), ("Composition", json!("composition")), ("Composition - Retain Layer Sizes", json!("compositionLayerSizes"))],
|
||||
1,
|
||||
)],
|
||||
),
|
||||
// Photoshop files: Import Kind (Footage / Composition / – Retain Layer Sizes). Dropped
|
||||
// files start at Settings ▸ Import ▸ Default Drag Import As.
|
||||
"file.import" if !has(p, &["importAs"]) && is_layered(p) => {
|
||||
let kinds =
|
||||
[("Footage", json!("footage")), ("Composition", json!("composition")), ("Composition - Retain Layer Sizes", json!("compositionLayerSizes"))];
|
||||
let drag = p.get("drag").and_then(Value::as_bool).unwrap_or(false);
|
||||
let sel = if drag { kinds.iter().position(|(_, v)| v.as_str() == Some(s.prefs.drag_import_as())).unwrap_or(0) } else { 1 };
|
||||
("Import Photoshop File".into(), vec![Field::choice("importAs", "Import Kind", &kinds, sel)])
|
||||
}
|
||||
// PDF / Illustrator files: Import Kind and the page.
|
||||
"file.import" if !has(p, &["importAs", "page"]) && is_pdf(p) => (
|
||||
"Import PDF / Illustrator File".into(),
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
//! - Reshape: correspondence point list buttons here, and on the Composition viewer the source
|
||||
//! and destination mask outlines with draggable correspondence handles ([`reshape_overlay`]);
|
||||
//! - EXtractoR: a Layer popup of the footage's OpenEXR layers, and Red / Green / Blue / Alpha
|
||||
//! popups of its channels ([`channel_popup`]).
|
||||
//! popups of its channels ([`channel_popup`]);
|
||||
//! - Mesh Warp: on the Composition viewer, the distortion mesh's grid over the layer with a
|
||||
//! draggable handle on every vertex ([`mesh_warp_overlay`], #303).
|
||||
//!
|
||||
//! Every edit is a `prop.set` engine command (undoable; one drag = one undo step) and every
|
||||
//! handle registers an automation id.
|
||||
@@ -37,6 +39,7 @@ pub const COLORAMA: &str = "ec.color.colorama";
|
||||
pub const GLOW: &str = "ec.stylize.glow";
|
||||
pub const RESHAPE: &str = "ec.distort.reshape";
|
||||
pub const EXTRACTOR: &str = "ec.3d.extractor";
|
||||
pub const MESH_WARP: &str = "ec.distort.meshwarp";
|
||||
|
||||
fn str_value(layer: &Layer, ectx: &EvalCtx, g: &PropGroup, id: &str) -> String {
|
||||
match g.get(id).map(|p| ectx.value(layer, p)) {
|
||||
@@ -1018,10 +1021,109 @@ pub fn reshape_overlay(
|
||||
}
|
||||
}
|
||||
|
||||
/// Mesh Warp's grid: (rows, columns, vertex offsets in layer pixels, row-major). A stored mesh
|
||||
/// that doesn't match the grid (Rows or Columns changed since) reads as undistorted, as it
|
||||
/// renders.
|
||||
fn mesh_grid(layer: &Layer, ectx: &EvalCtx, g: &PropGroup) -> (usize, usize, Vec<(f64, f64)>) {
|
||||
let n = |id: &str| {
|
||||
let v = g.get(id).map(|p| ectx.value(layer, p).as_f64()).unwrap_or(7.0);
|
||||
if v.is_finite() { v.round().clamp(1.0, 31.0) as usize } else { 7 }
|
||||
};
|
||||
let (rows, cols) = (n("rows"), n("columns"));
|
||||
let count = (rows + 1) * (cols + 1);
|
||||
let mut offs = effectcraft_engine::effects::parse_mesh(&str_value(layer, ectx, g, "mesh"));
|
||||
if offs.len() != count {
|
||||
offs = vec![(0.0, 0.0); count];
|
||||
}
|
||||
(rows, cols, offs)
|
||||
}
|
||||
|
||||
/// The `mesh` parameter's text for these offsets (the inverse of `parse_mesh`).
|
||||
fn format_mesh(offs: &[(f64, f64)]) -> String {
|
||||
let r = |v: f64| if v.is_finite() { (v * 1000.0).round() / 1000.0 + 0.0 } else { 0.0 };
|
||||
offs.iter().map(|o| format!("{},{}", r(o.0), r(o.1))).collect::<Vec<_>>().join(" ")
|
||||
}
|
||||
|
||||
/// Mesh Warp on the Composition viewer (#303): the distortion mesh's grid over the layer, with
|
||||
/// a handle on every vertex. Dragging a vertex moves it (its offset in the hidden `mesh`
|
||||
/// parameter; the first drag of an undistorted mesh writes the whole grid). `fm` maps effect
|
||||
/// space to comp.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn mesh_warp_overlay(
|
||||
app: &mut EffectcraftApp,
|
||||
ui: &mut egui::Ui,
|
||||
painter: &egui::Painter,
|
||||
map: &super::viewer::ViewerMap,
|
||||
ectx: &EvalCtx,
|
||||
layer: &Layer,
|
||||
g: &PropGroup,
|
||||
fm: &Mat3,
|
||||
actions: &mut Actions,
|
||||
) {
|
||||
let (rows, cols, offs) = mesh_grid(layer, ectx, g);
|
||||
let [lw, lh] = ectx.effect_bounds(layer).0;
|
||||
let rest = |k: usize| [(k % (cols + 1)) as f64 / cols as f64 * lw, (k / (cols + 1)) as f64 / rows as f64 * lh];
|
||||
let screen: Vec<Pos2> = offs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(k, o)| {
|
||||
let r = rest(k);
|
||||
map.to_screen(fw::layer_to_comp(fm, [r[0] + o.0, r[1] + o.1]))
|
||||
})
|
||||
.collect();
|
||||
let line = Stroke::new(1.0, Color32::from_white_alpha(150));
|
||||
for (k, s) in screen.iter().enumerate() {
|
||||
if k % (cols + 1) < cols
|
||||
&& let Some(e) = screen.get(k + 1)
|
||||
{
|
||||
painter.line_segment([*s, *e], line);
|
||||
}
|
||||
if let Some(e) = screen.get(k + cols + 1) {
|
||||
painter.line_segment([*s, *e], line);
|
||||
}
|
||||
}
|
||||
let ctx = ui.ctx().clone();
|
||||
let accent = app.tokens.accent;
|
||||
for (k, s) in screen.iter().enumerate() {
|
||||
let hr = Rect::from_center_size(*s, vec2(10.0, 10.0));
|
||||
let id = egui::Id::new(("mesh-warp-vertex", g.uid, k));
|
||||
let resp = ui.interact(hr, id, Sense::drag());
|
||||
let hot = resp.hovered() || resp.dragged();
|
||||
let dot = Rect::from_center_size(*s, vec2(5.0, 5.0));
|
||||
painter.rect_filled(dot, 0.0, if hot { accent } else { Color32::WHITE });
|
||||
painter.rect_stroke(dot, 0.0, Stroke::new(1.0, Color32::BLACK), StrokeKind::Outside);
|
||||
let (row, col) = (k / (cols + 1), k % (cols + 1));
|
||||
app.auto.add(&format!("viewer.meshWarp.{}.{row}.{col}", g.uid), hr, &format!("Mesh vertex (row {row}, column {col})"));
|
||||
if hot {
|
||||
ctx.set_cursor_icon(egui::CursorIcon::Move);
|
||||
}
|
||||
if resp.dragged()
|
||||
&& let Some(pos) = resp.interact_pointer_pos()
|
||||
&& let Some(lp) = fw::comp_to_layer(fm, map.to_comp(pos))
|
||||
{
|
||||
let mut v = offs.clone();
|
||||
let r = rest(k);
|
||||
if let Some(o) = v.get_mut(k) {
|
||||
*o = (lp[0] - r[0], lp[1] - r[1]);
|
||||
}
|
||||
let key = gesture_key(ui, id, resp.drag_started());
|
||||
set_str(actions, layer, g, "mesh", format_mesh(&v), Some(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn mesh_text_round_trips() {
|
||||
let offs = vec![(0.0, 0.0), (12.5, -3.25), (1.0 / 3.0, f64::NAN)];
|
||||
let s = format_mesh(&offs);
|
||||
assert_eq!(s, "0,0 12.5,-3.25 0.333,0");
|
||||
assert_eq!(effectcraft_engine::effects::parse_mesh(&s), vec![(0.0, 0.0), (12.5, -3.25), (0.333, 0.0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offset_points_and_palettes_round_trip() {
|
||||
let p = OffsetPoints::parse("0.5,0.75 0.1,0.5");
|
||||
|
||||
@@ -0,0 +1,519 @@
|
||||
//! The Gradient Editor (#612), opened by a gradient property's "Edit Gradient…" in the Timeline
|
||||
//! (Gradient Fill / Gradient Stroke ▸ Colors, Gradient Overlay ▸ Gradient): `prop.editGradient`.
|
||||
//! Opacity stops sit above the preview bar and colour stops below it. Click above or below the
|
||||
//! bar to add a stop (it takes that track's value there), drag a stop to move it, edit the
|
||||
//! selected stop's location, opacity or colour, and Delete removes it (never the last stop of a
|
||||
//! track). The editor works on a draft: OK sets the property once with `prop.set` at the time it
|
||||
//! opened (one undo step, nothing at all when nothing changed); Cancel and Escape leave it as it
|
||||
//! was.
|
||||
//!
|
||||
//! Automation ids: `dialog.gradient.bar`, `dialog.gradient.addOpacity`, `dialog.gradient.addColor`,
|
||||
//! `dialog.gradient.opacityStop.<i>`, `dialog.gradient.colorStop.<i>` (in order along the bar),
|
||||
//! `dialog.gradient.location`, `dialog.gradient.opacity`, `dialog.gradient.color`,
|
||||
//! `dialog.gradient.delete`, `dialog.gradient.ok`, `dialog.gradient.cancel`.
|
||||
|
||||
use effectcraft_engine::keyframe::{Gradient, Value};
|
||||
use effectcraft_engine::project::{ItemId, LayerId};
|
||||
use egui::{Color32, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
|
||||
use serde_json::{Value as Json, json};
|
||||
|
||||
use crate::i18n::tr;
|
||||
use crate::theme::Tokens;
|
||||
use crate::{Dialog, EffectcraftApp};
|
||||
|
||||
/// Which row of stops: opacity (above the bar) or colour (below it).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Track {
|
||||
Opacity,
|
||||
Color,
|
||||
}
|
||||
|
||||
/// A stop in the draft. `id` stays with the stop when it moves past another one (the tracks are
|
||||
/// kept in order along the bar, so its index changes).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Stop<T> {
|
||||
pub id: u64,
|
||||
pub pos: f64,
|
||||
pub value: T,
|
||||
}
|
||||
|
||||
/// The property being edited, as it was when the editor opened.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Target {
|
||||
pub comp: u64,
|
||||
pub layer: u64,
|
||||
pub prop: u64,
|
||||
/// Composition seconds, snapped to the nearest frame: the value is read and set there.
|
||||
pub time: f64,
|
||||
}
|
||||
|
||||
/// The editor's draft gradient and selection.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Draft {
|
||||
pub target: Option<Target>,
|
||||
pub colors: Vec<Stop<[f32; 4]>>,
|
||||
pub opacities: Vec<Stop<f32>>,
|
||||
pub selected: Option<(Track, u64)>,
|
||||
/// The gradient as it opened, stops in order: OK with an equal draft changes nothing.
|
||||
pub baseline: Gradient,
|
||||
/// Stop counts (colour, opacity) of the keyframes just before and after the edit time.
|
||||
pub neighbors: Vec<(usize, usize)>,
|
||||
next_id: u64,
|
||||
}
|
||||
|
||||
fn by_pos<T>(v: &mut [Stop<T>]) {
|
||||
// Stable: stops at the same location keep their order.
|
||||
v.sort_by(|a, b| a.pos.total_cmp(&b.pos));
|
||||
}
|
||||
|
||||
fn clamp_pos(p: f64) -> f64 {
|
||||
if p.is_finite() { p.clamp(0.0, 1.0) } else { 0.0 }
|
||||
}
|
||||
|
||||
impl Draft {
|
||||
/// A draft of `g` (stops put in order, locations clamped to 0..1).
|
||||
pub fn new(g: &Gradient, target: Option<Target>, neighbors: Vec<(usize, usize)>) -> Draft {
|
||||
let mut d = Draft { target, neighbors, ..Default::default() };
|
||||
for &(pos, value) in &g.colors {
|
||||
let id = d.fresh();
|
||||
d.colors.push(Stop { id, pos: clamp_pos(pos), value });
|
||||
}
|
||||
for &(pos, value) in &g.opacities {
|
||||
let id = d.fresh();
|
||||
d.opacities.push(Stop { id, pos: clamp_pos(pos), value });
|
||||
}
|
||||
by_pos(&mut d.colors);
|
||||
by_pos(&mut d.opacities);
|
||||
d.baseline = d.gradient();
|
||||
d
|
||||
}
|
||||
|
||||
fn fresh(&mut self) -> u64 {
|
||||
self.next_id = self.next_id.saturating_add(1);
|
||||
self.next_id
|
||||
}
|
||||
|
||||
/// The draft as a gradient (the tracks are always in order).
|
||||
pub fn gradient(&self) -> Gradient {
|
||||
Gradient { colors: self.colors.iter().map(|s| (s.pos, s.value)).collect(), opacities: self.opacities.iter().map(|s| (s.pos, s.value)).collect() }
|
||||
}
|
||||
|
||||
pub fn len(&self, track: Track) -> usize {
|
||||
match track {
|
||||
Track::Color => self.colors.len(),
|
||||
Track::Opacity => self.opacities.len(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The id of the stop `i`-th along the bar.
|
||||
pub fn id_at(&self, track: Track, i: usize) -> Option<u64> {
|
||||
match track {
|
||||
Track::Color => self.colors.get(i).map(|s| s.id),
|
||||
Track::Opacity => self.opacities.get(i).map(|s| s.id),
|
||||
}
|
||||
}
|
||||
|
||||
/// Where stop `id` is along the bar (its index), if it exists.
|
||||
pub fn index_of(&self, track: Track, id: u64) -> Option<usize> {
|
||||
match track {
|
||||
Track::Color => self.colors.iter().position(|s| s.id == id),
|
||||
Track::Opacity => self.opacities.iter().position(|s| s.id == id),
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a stop at `pos` with that track's current value there, select it, return its id.
|
||||
pub fn add(&mut self, track: Track, pos: f64) -> u64 {
|
||||
let pos = clamp_pos(pos);
|
||||
let g = self.gradient();
|
||||
let id = self.fresh();
|
||||
match track {
|
||||
Track::Color => self.colors.push(Stop { id, pos, value: g.color_at(pos) }),
|
||||
Track::Opacity => self.opacities.push(Stop { id, pos, value: g.opacity_at(pos) }),
|
||||
}
|
||||
self.sort();
|
||||
self.selected = Some((track, id));
|
||||
id
|
||||
}
|
||||
|
||||
/// Move stop `id` to `pos` (clamped) and keep the track in order.
|
||||
pub fn move_to(&mut self, track: Track, id: u64, pos: f64) {
|
||||
let pos = clamp_pos(pos);
|
||||
match track {
|
||||
Track::Color => {
|
||||
if let Some(s) = self.colors.iter_mut().find(|s| s.id == id) {
|
||||
s.pos = pos;
|
||||
}
|
||||
}
|
||||
Track::Opacity => {
|
||||
if let Some(s) = self.opacities.iter_mut().find(|s| s.id == id) {
|
||||
s.pos = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.sort();
|
||||
}
|
||||
|
||||
/// Remove stop `id` unless it is the last of its track. Returns whether it went.
|
||||
pub fn remove(&mut self, track: Track, id: u64) -> bool {
|
||||
if self.len(track) <= 1 {
|
||||
return false;
|
||||
}
|
||||
let before = self.len(track);
|
||||
match track {
|
||||
Track::Color => self.colors.retain(|s| s.id != id),
|
||||
Track::Opacity => self.opacities.retain(|s| s.id != id),
|
||||
}
|
||||
if self.selected == Some((track, id)) {
|
||||
self.selected = None;
|
||||
}
|
||||
self.len(track) < before
|
||||
}
|
||||
|
||||
/// Set colour stop `id`'s RGB, keeping its alpha.
|
||||
pub fn set_rgb(&mut self, id: u64, rgb: [f32; 3]) {
|
||||
if let Some(s) = self.colors.iter_mut().find(|s| s.id == id) {
|
||||
s.value = [rgb[0], rgb[1], rgb[2], s.value[3]];
|
||||
}
|
||||
}
|
||||
|
||||
/// Set opacity stop `id` (0..1).
|
||||
pub fn set_opacity(&mut self, id: u64, a: f32) {
|
||||
if let Some(s) = self.opacities.iter_mut().find(|s| s.id == id) {
|
||||
s.value = if a.is_finite() { a.clamp(0.0, 1.0) } else { s.value };
|
||||
}
|
||||
}
|
||||
|
||||
fn sort(&mut self) {
|
||||
by_pos(&mut self.colors);
|
||||
by_pos(&mut self.opacities);
|
||||
}
|
||||
|
||||
/// The draft's stop counts differ from a neighbouring keyframe's, so the two can't
|
||||
/// interpolate (gradient keyframes blend only with the same number of stops).
|
||||
pub fn mismatched(&self) -> bool {
|
||||
self.neighbors.iter().any(|&(c, o)| c != self.colors.len() || o != self.opacities.len())
|
||||
}
|
||||
}
|
||||
|
||||
/// `prop.editGradient {layer, prop, comp?}`: open the editor on that gradient property at the
|
||||
/// current time (snapped to the nearest frame, as `prop.set` snaps it).
|
||||
pub fn open(app: &mut EffectcraftApp, p: &Json) -> Result<Json, String> {
|
||||
let cid = match p.get("comp").and_then(Json::as_u64) {
|
||||
Some(c) => ItemId(c),
|
||||
None => app.session.active_comp_id().ok_or("no composition is open")?,
|
||||
};
|
||||
let comp = app.session.project.comp(cid).ok_or_else(|| format!("no composition {}", cid.0))?;
|
||||
let lid = p.get("layer").and_then(Json::as_u64).ok_or("missing `layer`")?;
|
||||
let layer = comp.layer(LayerId(lid)).ok_or_else(|| format!("no layer {lid}"))?;
|
||||
let uid = p.get("prop").and_then(Json::as_u64).ok_or("missing `prop`")?;
|
||||
let prop = layer.props.find(uid).ok_or_else(|| format!("no property @{uid}"))?;
|
||||
let ct = comp.frame_rate.snap_nearest(app.session.time_of(cid));
|
||||
let lt = layer.layer_time(ct);
|
||||
let Value::Gradient(g) = prop.value_at(lt) else {
|
||||
return Err(format!("{} is not a gradient", prop.name));
|
||||
};
|
||||
// The keyframes either side of the edit time (one exactly there is the one being edited).
|
||||
let counts = |v: &Value| match v {
|
||||
Value::Gradient(g) => Some((g.colors.len(), g.opacities.len())),
|
||||
_ => None,
|
||||
};
|
||||
let before = prop.keys.iter().rev().find(|k| k.time < lt).and_then(|k| counts(&k.value));
|
||||
let after = prop.keys.iter().find(|k| k.time > lt).and_then(|k| counts(&k.value));
|
||||
let target = Target { comp: cid.0, layer: lid, prop: uid, time: ct.seconds() };
|
||||
app.dialog_state.gradient = Draft::new(&g, Some(target), before.into_iter().chain(after).collect());
|
||||
app.dialog = Some(Dialog::GradientEditor);
|
||||
Ok(json!({"dialog": "gradientEditor"}))
|
||||
}
|
||||
|
||||
/// Set the property to the draft: one `prop.set` at the time the editor opened, in composition
|
||||
/// time, or nothing when the draft is unchanged (so OK adds no keyframe).
|
||||
fn commit(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
app.dialog = None;
|
||||
let d = std::mem::take(&mut app.dialog_state.gradient);
|
||||
let g = d.gradient();
|
||||
let Some(tg) = d.target else { return };
|
||||
if g == d.baseline {
|
||||
return;
|
||||
}
|
||||
let params = json!({"comp": tg.comp, "layer": tg.layer, "prop": tg.prop, "time": tg.time, "timeBase": "comp", "value": Value::Gradient(g).to_json()});
|
||||
if let Err(e) = crate::menus::invoke(app, ctx, "prop.set", params) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
|
||||
fn to_color32(c: [f32; 4]) -> Color32 {
|
||||
let b = |v: f32| (v.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||
Color32::from_rgba_unmultiplied(b(c[0]), b(c[1]), b(c[2]), b(c[3]))
|
||||
}
|
||||
|
||||
pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
if app.dialog_state.gradient.target.is_none() {
|
||||
app.dialog = None;
|
||||
return;
|
||||
}
|
||||
let mut answer: Option<bool> = None;
|
||||
super::dialogs::modal(ctx, tr("Gradient Editor"), vec2(520.0, 270.0), t, |ui| {
|
||||
let w = ui.available_width().max(200.0);
|
||||
let (area, _) = ui.allocate_exact_size(vec2(w, 72.0), Sense::hover());
|
||||
let bar = Rect::from_min_max(pos2(area.min.x + 8.0, area.min.y + 22.0), pos2(area.max.x - 8.0, area.min.y + 48.0));
|
||||
let opacity_row = Rect::from_min_max(pos2(bar.min.x, area.min.y), pos2(bar.max.x, bar.min.y - 2.0));
|
||||
let color_row = Rect::from_min_max(pos2(bar.min.x, bar.max.y + 2.0), pos2(bar.max.x, area.max.y));
|
||||
let pos_of = |x: f32| ((x - bar.min.x) / bar.width().max(1.0)) as f64;
|
||||
let x_of = |p: f64| bar.min.x + bar.width() * p as f32;
|
||||
let painter = ui.painter().clone();
|
||||
|
||||
// The bar: a checkerboard under the gradient, so opacity shows.
|
||||
let cell = 6.0;
|
||||
let mut y = bar.min.y;
|
||||
let mut row = 0;
|
||||
while y < bar.max.y {
|
||||
let mut x = bar.min.x;
|
||||
let mut col = row;
|
||||
while x < bar.max.x {
|
||||
let c = if col % 2 == 0 { Color32::from_gray(200) } else { Color32::from_gray(150) };
|
||||
painter.rect_filled(Rect::from_min_max(pos2(x, y), pos2((x + cell).min(bar.max.x), (y + cell).min(bar.max.y))), 0.0, c);
|
||||
x += cell;
|
||||
col += 1;
|
||||
}
|
||||
y += cell;
|
||||
row += 1;
|
||||
}
|
||||
let g = app.dialog_state.gradient.gradient();
|
||||
let n = 96;
|
||||
for k in 0..n {
|
||||
let x0 = bar.min.x + bar.width() * k as f32 / n as f32;
|
||||
let x1 = bar.min.x + bar.width() * (k + 1) as f32 / n as f32;
|
||||
let c = g.sample((k as f64 + 0.5) / n as f64);
|
||||
painter.rect_filled(Rect::from_min_max(pos2(x0, bar.min.y), pos2(x1, bar.max.y)), 0.0, to_color32(c));
|
||||
}
|
||||
painter.rect_stroke(bar, 0.0, Stroke::new(1.0, t.field_border), StrokeKind::Outside);
|
||||
app.auto.add("dialog.gradient.bar", bar, "Gradient");
|
||||
|
||||
// Clicking a row's empty space adds a stop there.
|
||||
for (track, rowr, id) in [(Track::Opacity, opacity_row, "dialog.gradient.addOpacity"), (Track::Color, color_row, "dialog.gradient.addColor")] {
|
||||
let r = ui.interact(rowr, egui::Id::new(("gradient-add", id)), Sense::click());
|
||||
app.auto.add(id, rowr, id);
|
||||
if r.clicked()
|
||||
&& let Some(p) = r.interact_pointer_pos()
|
||||
{
|
||||
app.dialog_state.gradient.add(track, pos_of(p.x));
|
||||
}
|
||||
}
|
||||
|
||||
// The stops (drawn and hit-tested over the rows, so they take the clicks).
|
||||
for track in [Track::Opacity, Track::Color] {
|
||||
for i in 0..app.dialog_state.gradient.len(track) {
|
||||
let d = &app.dialog_state.gradient;
|
||||
let Some(id) = d.id_at(track, i) else { continue };
|
||||
let (pos, fill) = match track {
|
||||
Track::Color => d.colors.get(i).map(|s| (s.pos, to_color32([s.value[0], s.value[1], s.value[2], 1.0]))),
|
||||
Track::Opacity => d.opacities.get(i).map(|s| (s.pos, Color32::from_gray((s.value.clamp(0.0, 1.0) * 255.0) as u8))),
|
||||
}
|
||||
.unwrap_or((0.0, Color32::WHITE));
|
||||
let selected = d.selected == Some((track, id));
|
||||
let x = x_of(pos);
|
||||
let r = match track {
|
||||
Track::Opacity => Rect::from_min_max(pos2(x - 5.0, opacity_row.max.y - 15.0), pos2(x + 5.0, opacity_row.max.y)),
|
||||
Track::Color => Rect::from_min_max(pos2(x - 5.0, color_row.min.y), pos2(x + 5.0, color_row.min.y + 15.0)),
|
||||
};
|
||||
painter.rect_filled(r, 1.0, fill);
|
||||
painter.rect_stroke(
|
||||
r,
|
||||
1.0,
|
||||
Stroke::new(if selected { 2.0 } else { 1.0 }, if selected { t.accent } else { t.field_border }),
|
||||
StrokeKind::Outside,
|
||||
);
|
||||
let resp = ui.interact(r.expand(2.0), egui::Id::new(("gradient-stop", track == Track::Color, id)), Sense::click_and_drag());
|
||||
let name = match track {
|
||||
Track::Opacity => format!("dialog.gradient.opacityStop.{i}"),
|
||||
Track::Color => format!("dialog.gradient.colorStop.{i}"),
|
||||
};
|
||||
app.auto.add(&name, r, &name);
|
||||
if resp.clicked() || resp.drag_started() {
|
||||
app.dialog_state.gradient.selected = Some((track, id));
|
||||
}
|
||||
if resp.dragged()
|
||||
&& let Some(p) = resp.interact_pointer_pos()
|
||||
{
|
||||
app.dialog_state.gradient.move_to(track, id, pos_of(p.x));
|
||||
}
|
||||
}
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
|
||||
// The selected stop's fields.
|
||||
let selected = app.dialog_state.gradient.selected;
|
||||
let selected = selected.and_then(|(track, id)| app.dialog_state.gradient.index_of(track, id).map(|i| (track, id, i)));
|
||||
ui.horizontal(|ui| {
|
||||
let Some((track, id, i)) = selected else {
|
||||
ui.label(egui::RichText::new(tr("Click above the bar to add an opacity stop, below it to add a color stop.")).color(t.text_dim));
|
||||
return;
|
||||
};
|
||||
ui.label(tr("Location:"));
|
||||
let d = &app.dialog_state.gradient;
|
||||
let pos = match track {
|
||||
Track::Color => d.colors.get(i).map(|s| s.pos),
|
||||
Track::Opacity => d.opacities.get(i).map(|s| s.pos),
|
||||
}
|
||||
.unwrap_or(0.0);
|
||||
let mut pct = pos * 100.0;
|
||||
let r = ui.add(egui::DragValue::new(&mut pct).range(0.0..=100.0).speed(0.5).max_decimals(1).suffix("%"));
|
||||
app.auto.add("dialog.gradient.location", r.rect, "Location");
|
||||
if r.changed() {
|
||||
app.dialog_state.gradient.move_to(track, id, pct / 100.0);
|
||||
}
|
||||
// Moving can reorder the track: find the stop again by its id, so the fields below
|
||||
// show this stop and not the one now at its old index.
|
||||
let Some(i) = app.dialog_state.gradient.index_of(track, id) else { return };
|
||||
match track {
|
||||
Track::Opacity => {
|
||||
ui.label(tr("Opacity:"));
|
||||
let mut a = app.dialog_state.gradient.opacities.get(i).map_or(1.0, |s| s.value) as f64 * 100.0;
|
||||
let r = ui.add(egui::DragValue::new(&mut a).range(0.0..=100.0).speed(0.5).max_decimals(1).suffix("%"));
|
||||
app.auto.add("dialog.gradient.opacity", r.rect, "Opacity");
|
||||
if r.changed() {
|
||||
app.dialog_state.gradient.set_opacity(id, (a / 100.0) as f32);
|
||||
}
|
||||
}
|
||||
Track::Color => {
|
||||
ui.label(tr("Color:"));
|
||||
let c = app.dialog_state.gradient.colors.get(i).map_or([1.0; 4], |s| s.value);
|
||||
// The shared colour picker (sRGB, hex field, OK / Cancel); the stop keeps its alpha.
|
||||
let mut rgb = [c[0], c[1], c[2]];
|
||||
let swatch = crate::widgets::srgb_color_button(ui, &mut rgb);
|
||||
app.auto.add("dialog.gradient.color", swatch.rect, "Color");
|
||||
if swatch.changed() {
|
||||
app.dialog_state.gradient.set_rgb(id, rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
let can_delete = app.dialog_state.gradient.len(track) > 1;
|
||||
let r = ui.add_enabled(can_delete, egui::Button::new(tr("Delete")));
|
||||
app.auto.add("dialog.gradient.delete", r.rect, "Delete");
|
||||
if r.clicked() {
|
||||
app.dialog_state.gradient.remove(track, id);
|
||||
}
|
||||
});
|
||||
if app.dialog_state.gradient.mismatched() {
|
||||
ui.add_space(4.0);
|
||||
ui.label(egui::RichText::new(tr("These adjacent keyframes cannot interpolate because their stop counts differ.")).color(t.danger).size(11.0));
|
||||
}
|
||||
ui.add_space(14.0);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let r = ui.button(tr("Cancel"));
|
||||
app.auto.add("dialog.gradient.cancel", r.rect, "Cancel");
|
||||
if r.clicked() {
|
||||
answer = Some(false);
|
||||
}
|
||||
let r = ui.button(tr("OK"));
|
||||
app.auto.add("dialog.gradient.ok", r.rect, "OK");
|
||||
if r.clicked() {
|
||||
answer = Some(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
// Delete / Backspace remove the selected stop, but not while typing in a field.
|
||||
if answer.is_none()
|
||||
&& !ctx.egui_wants_keyboard_input()
|
||||
&& ctx.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace))
|
||||
&& let Some((track, id)) = app.dialog_state.gradient.selected
|
||||
{
|
||||
app.dialog_state.gradient.remove(track, id);
|
||||
}
|
||||
match answer {
|
||||
Some(true) => commit(app, ctx),
|
||||
Some(false) => {
|
||||
app.dialog = None;
|
||||
app.dialog_state.gradient = Draft::default();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn draft() -> Draft {
|
||||
Draft::new(&Gradient { colors: vec![(0.0, [1.0, 0.0, 0.0, 1.0]), (1.0, [0.0, 0.0, 1.0, 1.0])], opacities: vec![(0.0, 1.0), (1.0, 0.5)] }, None, vec![])
|
||||
}
|
||||
|
||||
/// Dragging the first stop past the second keeps the track in order and the same stop
|
||||
/// selected; a stop added afterwards samples the reordered track.
|
||||
#[test]
|
||||
fn stops_stay_in_order_and_selected_while_moving() {
|
||||
for track in [Track::Color, Track::Opacity] {
|
||||
let g = Gradient { colors: vec![(0.0, [1.0, 0.0, 0.0, 1.0]), (0.6, [0.0, 0.0, 1.0, 1.0])], opacities: vec![(0.0, 1.0), (0.6, 0.5)] };
|
||||
let mut d = Draft::new(&g, None, vec![]);
|
||||
let first = d.id_at(track, 0).unwrap();
|
||||
d.selected = Some((track, first));
|
||||
d.move_to(track, first, 0.3);
|
||||
d.move_to(track, first, 0.8);
|
||||
assert_eq!(d.index_of(track, first), Some(1), "{track:?}: dragged past the stop at 0.6, it is now second");
|
||||
assert_eq!(d.selected, Some((track, first)), "{track:?}: the selection followed it");
|
||||
let g = d.gradient();
|
||||
let positions: Vec<f64> = match track {
|
||||
Track::Color => g.colors.iter().map(|c| c.0).collect(),
|
||||
Track::Opacity => g.opacities.iter().map(|c| c.0).collect(),
|
||||
};
|
||||
assert!(positions.windows(2).all(|w| w[0] <= w[1]), "{track:?}: {positions:?}");
|
||||
let added = d.add(track, 0.5);
|
||||
assert_eq!(d.index_of(track, added), Some(0), "{track:?}: the new stop sorts before the stops at 0.6 and 0.8");
|
||||
assert_eq!(d.selected, Some((track, added)));
|
||||
}
|
||||
// After the swap the colour track runs blue (at 0) to red (at 1): a stop added at 0.5 is
|
||||
// their mix in the swapped order, not the original red-to-blue.
|
||||
let mut d = draft();
|
||||
let red = d.id_at(Track::Color, 0).unwrap();
|
||||
let blue = d.id_at(Track::Color, 1).unwrap();
|
||||
d.move_to(Track::Color, red, 1.0);
|
||||
d.move_to(Track::Color, blue, 0.0);
|
||||
let id = d.add(Track::Color, 0.25);
|
||||
let i = d.index_of(Track::Color, id).unwrap();
|
||||
let c = d.colors[i].value;
|
||||
assert!(c[2] > c[0], "blue dominates near 0 after the swap: {c:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn last_stop_stays_and_new_stops_keep_their_tracks_values() {
|
||||
let mut d = draft();
|
||||
let a = d.id_at(Track::Opacity, 0).unwrap();
|
||||
let b = d.id_at(Track::Opacity, 1).unwrap();
|
||||
assert!(d.remove(Track::Opacity, a));
|
||||
assert!(!d.remove(Track::Opacity, b), "the last opacity stop stays");
|
||||
let mut d = draft();
|
||||
let id = d.add(Track::Opacity, 0.5);
|
||||
let i = d.index_of(Track::Opacity, id).unwrap();
|
||||
assert!((d.opacities[i].value - 0.75).abs() < 1e-6, "the opacity track's own value");
|
||||
let id = d.add(Track::Color, 0.5);
|
||||
let i = d.index_of(Track::Color, id).unwrap();
|
||||
assert!((d.colors[i].value[3] - 1.0).abs() < 1e-6, "colour stops keep their own alpha, not times opacity");
|
||||
d.set_rgb(id, [0.0, 1.0, 0.0]);
|
||||
assert_eq!(d.colors[i].value, [0.0, 1.0, 0.0, 1.0]);
|
||||
d.set_opacity(d.id_at(Track::Opacity, 0).unwrap(), f32::NAN);
|
||||
assert!(d.opacities.iter().all(|s| s.value.is_finite()));
|
||||
d.move_to(Track::Color, id, f64::INFINITY);
|
||||
assert!(d.colors.iter().all(|s| (0.0..=1.0).contains(&s.pos)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unchanged_drafts_equal_their_baseline() {
|
||||
// Out-of-order and out-of-range stops come in sorted and clamped: still "unchanged".
|
||||
let g = Gradient { colors: vec![(1.2, [0.0, 0.0, 1.0, 1.0]), (0.0, [1.0, 0.0, 0.0, 1.0])], opacities: vec![(0.5, 1.0)] };
|
||||
let d = Draft::new(&g, None, vec![]);
|
||||
assert_eq!(d.gradient(), d.baseline);
|
||||
assert_eq!(d.gradient().colors.iter().map(|c| c.0).collect::<Vec<_>>(), vec![0.0, 1.0]);
|
||||
let mut e = d.clone();
|
||||
e.add(Track::Opacity, 0.2);
|
||||
assert_ne!(e.gradient(), e.baseline);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_warning_follows_the_neighbours_stop_counts() {
|
||||
let mut d = Draft::new(&Gradient::default(), None, vec![(2, 2), (2, 2)]);
|
||||
assert!(!d.mismatched(), "same counts as both neighbours");
|
||||
d.add(Track::Color, 0.5);
|
||||
assert!(d.mismatched(), "three colour stops next to keyframes with two");
|
||||
assert!(!Draft::new(&Gradient::default(), None, vec![]).mismatched(), "not animated: no neighbours");
|
||||
}
|
||||
}
|
||||
@@ -419,7 +419,10 @@ pub(crate) fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painte
|
||||
&& let Some((press, grabs)) = ctx.data(|dd| dd.get_temp::<HandleDrag>(handle_drag_id()))
|
||||
{
|
||||
ctx.data_mut(|dd| dd.insert_temp(drag_id, true));
|
||||
let (dt, dv) = (tm.t(pt.x) - tm.t(press.x), vmap(pt.y) - vmap(press.y));
|
||||
// Shift keeps the handle on the time or the value axis, whichever moved more (as for keys).
|
||||
let (time_ok, value_ok) = shift_axes(ui.input(|i| i.modifiers.shift), pt.x - press.x, pt.y - press.y);
|
||||
let dt = if time_ok { tm.t(pt.x) - tm.t(press.x) } else { 0.0 };
|
||||
let dv = if value_ok { vmap(pt.y) - vmap(press.y) } else { 0.0 };
|
||||
let merge = format!("ghandle-{uid}-{}", k.idx);
|
||||
for g in &grabs {
|
||||
actions.push(("keys.setEase".into(), g.ease(g.end.0 + dt, g.end.1 + dv, speed, &merge)));
|
||||
@@ -470,7 +473,7 @@ pub(crate) fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painte
|
||||
{
|
||||
ctx.data_mut(|dd| dd.insert_temp(drag_id, true));
|
||||
let (dx, dy) = (pt.x - g.press.x, pt.y - g.press.y);
|
||||
let (time_ok, value_ok) = if mods.shift { (dx.abs() >= dy.abs(), dy.abs() > dx.abs()) } else { (true, true) };
|
||||
let (time_ok, value_ok) = shift_axes(mods.shift, dx, dy);
|
||||
// Graph Editor ▸ Snap: to the current time and other keys.
|
||||
let others: Vec<f64> = all_key_times.iter().filter(|(u, i, _)| !(*u == uid && *i == k.idx)).map(|x| x.2).collect();
|
||||
let t = if time_ok { super::graph_tools::snap_time(app, tm, (g.t + (tm.t(pt.x) - tm.t(g.press.x))).max(0.0), &others) } else { g.t };
|
||||
@@ -703,3 +706,21 @@ type HandleDrag = (Pos2, Vec<HandleGrab>);
|
||||
fn handle_drag_id() -> egui::Id {
|
||||
egui::Id::new("graph-handle-drag")
|
||||
}
|
||||
|
||||
/// Which axes a drag may move on (time, value): both, or with Shift only the one the pointer moved more along.
|
||||
fn shift_axes(shift: bool, dx: f32, dy: f32) -> (bool, bool) {
|
||||
if shift { (dx.abs() >= dy.abs(), dy.abs() > dx.abs()) } else { (true, true) }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::shift_axes;
|
||||
|
||||
#[test]
|
||||
fn shift_locks_drag_to_dominant_axis() {
|
||||
assert_eq!(shift_axes(false, 10.0, 3.0), (true, true));
|
||||
assert_eq!(shift_axes(true, 10.0, -3.0), (true, false));
|
||||
assert_eq!(shift_axes(true, 2.0, -9.0), (false, true));
|
||||
assert_eq!(shift_axes(true, 5.0, 5.0), (true, false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ pub mod footage_panel;
|
||||
pub mod forms;
|
||||
pub mod fx_editors;
|
||||
pub mod fx_widgets;
|
||||
pub mod gradient_editor;
|
||||
pub mod graph;
|
||||
pub mod graph_tools;
|
||||
pub mod home;
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
//! Media Duration, Frame Rate, File Path, Comment — shown or hidden from the header's context
|
||||
//! menu), folders (drag items into and out of them), renaming (Enter, or double-click the name),
|
||||
//! the label colour picker, and the bottom bar (interpret, new folder, new comp: click, or drop
|
||||
//! items on it for a comp from them, bit depth, delete). Edits are engine commands, so they are
|
||||
//! undoable.
|
||||
//! items on it for a comp from them, bit depth, delete), and the keyboard (the arrow keys select,
|
||||
//! extend the selection and open / close folders; rows and buttons carry AccessKit names and
|
||||
//! states for screen readers). Edits are engine commands, so they are undoable.
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -191,6 +192,130 @@ pub fn begin_rename(app: &EffectcraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a Shift-extended selection starts (the last item clicked or moved to without Shift).
|
||||
fn anchor_id() -> egui::Id {
|
||||
egui::Id::new("project-selection-anchor")
|
||||
}
|
||||
|
||||
/// The item the arrow keys move from: the last item clicked or moved to.
|
||||
fn cursor_id() -> egui::Id {
|
||||
egui::Id::new("project-selection-cursor")
|
||||
}
|
||||
|
||||
/// An item row's widget: its click / drag area, keyboard focus and accessibility node.
|
||||
fn row_id(item: ItemId) -> egui::Id {
|
||||
egui::Id::new(("pitem", item.0))
|
||||
}
|
||||
|
||||
/// The last row drawn with keyboard focus (egui drops the focus of a row scrolled out of view).
|
||||
fn focused_row_id() -> egui::Id {
|
||||
egui::Id::new("project-focused-row")
|
||||
}
|
||||
|
||||
/// The focused widget is one of the panel's rows, or nothing has keyboard focus: the panel's keys
|
||||
/// apply. Any other focused widget (a text field, a button reached with Tab) keeps them.
|
||||
fn keys_reach_rows(app: &EffectcraftApp, ctx: &egui::Context) -> bool {
|
||||
match ctx.memory(|m| m.focused()) {
|
||||
None => app.ui.focused == crate::dock::PanelKind::Project,
|
||||
Some(f) => ctx.data(|d| d.get_temp::<ItemId>(focused_row_id())).is_some_and(|row| row_id(row) == f),
|
||||
}
|
||||
}
|
||||
|
||||
/// The Project panel's arrow keys, as in After Effects: Up / Down Arrow select the previous /
|
||||
/// next item (the first or last when nothing is selected), Shift+Up / Down extend the selection
|
||||
/// from its anchor, Right Arrow opens the selected folder and Left Arrow closes it (on an item
|
||||
/// inside a folder, Left selects the folder). They apply while the panel has focus and nothing
|
||||
/// else takes them: a dialog, an open menu, an inline rename. A row focused with Tab keeps them
|
||||
/// too, and keyboard focus then follows the selection, so a screen reader reads the new item.
|
||||
/// Returns the item the selection moved to.
|
||||
fn keyboard_nav(app: &mut EffectcraftApp, ctx: &egui::Context) -> Option<ItemId> {
|
||||
use egui::Key;
|
||||
let keys: Vec<(Key, egui::Modifiers)> = ctx.input(|i| {
|
||||
i.events
|
||||
.iter()
|
||||
.filter_map(|e| match e {
|
||||
egui::Event::Key { key: k @ (Key::ArrowUp | Key::ArrowDown | Key::ArrowLeft | Key::ArrowRight), pressed: true, modifiers, .. } => {
|
||||
Some((*k, *modifiers))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
if keys.is_empty()
|
||||
|| app.dialog.is_some()
|
||||
|| widgets::any_menu_open(ctx)
|
||||
|| ctx.data(|d| d.get_temp::<Editing>(edit_id())).is_some()
|
||||
|| !keys_reach_rows(app, ctx)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let row_focused = ctx.memory(|m| m.focused()).is_some();
|
||||
let mut moved = None;
|
||||
for (key, m) in keys {
|
||||
let (plain, shift) = (!m.any(), m.shift_only());
|
||||
// Folders opened or closed by an earlier key in this frame change the rows.
|
||||
let rows = visible_rows(app);
|
||||
let pos = |id: ItemId| rows.iter().position(|(r, _)| *r == id);
|
||||
let sel = &app.session.state.project_selection;
|
||||
let cursor = ctx.data(|d| d.get_temp::<ItemId>(cursor_id())).filter(|c| sel.contains(c)).or_else(|| sel.last().copied());
|
||||
let cur = cursor.and_then(pos);
|
||||
let to = match key {
|
||||
Key::ArrowUp | Key::ArrowDown if plain || shift => {
|
||||
let Some(last) = rows.len().checked_sub(1) else { continue };
|
||||
let next = match (cur, key == Key::ArrowDown) {
|
||||
(Some(c), true) => c.saturating_add(1).min(last),
|
||||
(Some(c), false) => c.saturating_sub(1),
|
||||
(None, true) => 0,
|
||||
(None, false) => last,
|
||||
};
|
||||
let Some((to, _)) = rows.get(next).copied() else { continue };
|
||||
if shift {
|
||||
let anchor = ctx.data(|d| d.get_temp::<ItemId>(anchor_id())).and_then(pos).or(cur).unwrap_or(next);
|
||||
app.session.state.project_selection = rows.get(anchor.min(next)..=anchor.max(next)).unwrap_or_default().iter().map(|(i, _)| *i).collect();
|
||||
to
|
||||
} else {
|
||||
app.session.state.project_selection = vec![to];
|
||||
ctx.data_mut(|d| d.insert_temp(anchor_id(), to));
|
||||
to
|
||||
}
|
||||
}
|
||||
Key::ArrowRight | Key::ArrowLeft if plain => {
|
||||
let Some((id, folder, parent)) = cursor.and_then(|c| app.session.project.item(c)).map(|it| (it.id, it.is_folder(), it.parent)) else {
|
||||
continue;
|
||||
};
|
||||
let open = app.ui.project_open_folders.contains(&id.0);
|
||||
if key == Key::ArrowRight {
|
||||
if folder {
|
||||
app.ui.project_open_folders.insert(id.0);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if folder && open {
|
||||
app.ui.project_open_folders.remove(&id.0);
|
||||
continue;
|
||||
}
|
||||
let Some(parent) = parent.filter(|p| pos(*p).is_some()) else { continue };
|
||||
app.session.state.project_selection = vec![parent];
|
||||
ctx.data_mut(|d| d.insert_temp(anchor_id(), parent));
|
||||
parent
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
ctx.data_mut(|d| d.insert_temp(cursor_id(), to));
|
||||
moved = Some(to);
|
||||
}
|
||||
// The arrows are the list's, not egui's spatial focus moves.
|
||||
if row_focused {
|
||||
ctx.memory_mut(|m| {
|
||||
m.move_focus(egui::FocusDirection::None);
|
||||
if let Some(to) = moved {
|
||||
m.request_focus(row_id(to));
|
||||
}
|
||||
});
|
||||
}
|
||||
moved
|
||||
}
|
||||
|
||||
pub(crate) fn visible_rows(app: &EffectcraftApp) -> Vec<(ItemId, usize)> {
|
||||
fn walk(app: &EffectcraftApp, folder: Option<ItemId>, depth: usize, q: &str, out: &mut Vec<(ItemId, usize)>) {
|
||||
let mut kids = app.session.project.children(folder);
|
||||
@@ -307,6 +432,15 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
));
|
||||
}
|
||||
app.auto.add(&format!("project.sort.{key}"), hr, if label.is_empty() { "Label" } else { label });
|
||||
let column = crate::i18n::tr(if label.is_empty() { "Label" } else { label });
|
||||
let order = (app.ui.project_sort == *key).then(|| crate::i18n::tr(if app.ui.project_sort_desc { "descending" } else { "ascending" }));
|
||||
resp.widget_info(|| {
|
||||
let name = match order {
|
||||
Some(o) => crate::i18n::tr_args("Sort by {}, {}", &[&column, &o]),
|
||||
None => crate::i18n::tr_args("Sort by {}", &[&column]),
|
||||
};
|
||||
egui::WidgetInfo::labeled(egui::WidgetType::Button, true, name)
|
||||
});
|
||||
if resp.clicked() {
|
||||
if app.ui.project_sort == *key {
|
||||
app.ui.project_sort_desc = !app.ui.project_sort_desc;
|
||||
@@ -317,7 +451,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
column_menu(app, &resp);
|
||||
}
|
||||
let hresp = ui.interact(Rect::from_min_max(pos2(x, hdr.min.y), hdr.max), egui::Id::new("proj-hdr-rest"), Sense::click());
|
||||
let hresp = ui.interact(Rect::from_min_max(pos2(x, hdr.min.y), hdr.max), egui::Id::new("proj-hdr-rest"), Sense::CLICK);
|
||||
column_menu(app, &hresp);
|
||||
app.auto.add("project.columns", hdr, "Columns (right-click to show or hide)");
|
||||
// Rows.
|
||||
@@ -327,7 +461,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// The list's empty area (under the rows and the scroll bar, which take their own clicks):
|
||||
// a click deselects, a drag draws a selection box, a double-click imports, as in After
|
||||
// Effects (File ▸ Import ▸ File...).
|
||||
let empty = ui.interact(list, egui::Id::new("proj-empty"), Sense::click_and_drag());
|
||||
// Not a Tab stop: the keyboard reaches the rows, and nothing else here takes a key.
|
||||
let empty = ui.interact(list, egui::Id::new("proj-empty"), Sense::CLICK | Sense::DRAG);
|
||||
app.auto.add("project.empty", list, "Double-click to import files; drag to select items; right-click for project actions");
|
||||
if overflow > 0.0 && ui.rect_contains_pointer(list) {
|
||||
let (dx, dy, shift) = ui.input(|i| (i.smooth_scroll_delta.x, i.smooth_scroll_delta.y, i.modifiers.shift));
|
||||
@@ -340,11 +475,12 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
};
|
||||
app.ui.project_hscroll = (app.ui.project_hscroll - d).clamp(0.0, overflow);
|
||||
}
|
||||
let moved = keyboard_nav(app, &ctx);
|
||||
let rows = visible_rows(app);
|
||||
// Enter renames the selected item (Project panel focused, not typing).
|
||||
if app.ui.focused == crate::dock::PanelKind::Project
|
||||
&& app.dialog.is_none()
|
||||
&& !ctx.egui_wants_keyboard_input()
|
||||
&& keys_reach_rows(app, &ctx)
|
||||
&& ctx.data(|d| d.get_temp::<Editing>(edit_id())).is_none()
|
||||
&& ctx.input(|i| i.key_pressed(egui::Key::Enter))
|
||||
{
|
||||
@@ -382,6 +518,12 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The arrow keys' item scrolls into view (Shift+Up extends upward, past the selection's end).
|
||||
if let Some(row) = moved.and_then(|m| rows.iter().position(|(id, _)| *id == m)) {
|
||||
let top = row as f32 * ROW_H;
|
||||
// Not `clamp`: a panel shorter than a row would make its bounds cross. The row's top wins.
|
||||
app.ui.project_scroll = app.ui.project_scroll.max(top + ROW_H - list.height()).min(top);
|
||||
}
|
||||
app.ui.project_scroll = app.ui.project_scroll.clamp(0.0, max_scroll);
|
||||
let scroll = app.ui.project_scroll;
|
||||
let first = ((scroll / ROW_H).floor() as usize).min(rows.len());
|
||||
@@ -406,14 +548,37 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
);
|
||||
// The row's click / drag area goes first, so the twirl, proxy, label and comment widgets
|
||||
// on top of it take their own clicks.
|
||||
let mut resp = ui.interact(r.intersect(list), egui::Id::new(("pitem", id.0)), Sense::click_and_drag());
|
||||
let mut resp = ui.interact(r.intersect(list), row_id(*id), Sense::click_and_drag());
|
||||
app.auto.add(&format!("project.item.{}", id.0), r, &it.name);
|
||||
// For screen readers: a tree item named by the item and its type, with its selection,
|
||||
// depth and (a folder) open state. One Tab stop per row; the panel's keys then apply.
|
||||
let open = it.is_folder().then(|| app.ui.project_open_folders.contains(&id.0) || !app.ui.project_search.is_empty());
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Other, true, format!("{}, {}", it.name, crate::i18n::tr(it.type_name()))));
|
||||
ctx.accesskit_node_builder(resp.id, |n| {
|
||||
n.set_role(egui::accesskit::Role::TreeItem);
|
||||
n.set_selected(selected);
|
||||
n.set_level(depth.saturating_add(1));
|
||||
if let Some(open) = open {
|
||||
n.set_expanded(open);
|
||||
}
|
||||
});
|
||||
if resp.has_focus() {
|
||||
ctx.data_mut(|d| d.insert_temp(focused_row_id(), *id));
|
||||
}
|
||||
if resp.gained_focus() {
|
||||
app.ui.focused = crate::dock::PanelKind::Project;
|
||||
}
|
||||
let _ = i;
|
||||
let x0 = r.min.x + 8.0 + 14.0 * *depth as f32;
|
||||
if it.is_folder() {
|
||||
let open = app.ui.project_open_folders.contains(&id.0);
|
||||
let tw = Rect::from_center_size(pos2(x0 + 4.0, r.center().y), vec2(12.0, 12.0));
|
||||
if widgets::twirl(ui, tw, open, egui::Id::new(("pf", id.0)), &t).clicked() {
|
||||
let tresp = widgets::twirl(ui, tw, open, egui::Id::new(("pf", id.0)), &t);
|
||||
tresp.widget_info(|| {
|
||||
let name = crate::i18n::tr_args(if open { "Close folder {}" } else { "Open folder {}" }, &[&it.name]);
|
||||
egui::WidgetInfo::labeled(egui::WidgetType::Button, true, name)
|
||||
});
|
||||
if tresp.clicked() {
|
||||
if open {
|
||||
app.ui.project_open_folders.remove(&id.0);
|
||||
} else {
|
||||
@@ -437,6 +602,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if px.enabled { "in use" } else { "off" }
|
||||
));
|
||||
app.auto.add(&format!("project.item.{}.proxy", id.0), pr, if px.enabled { "Proxy in use" } else { "Proxy off" });
|
||||
presp.widget_info(|| {
|
||||
let name = crate::i18n::tr_args(if px.enabled { "Proxy of {}: in use" } else { "Proxy of {}: off" }, &[&it.name]);
|
||||
egui::WidgetInfo::labeled(egui::WidgetType::Button, true, name)
|
||||
});
|
||||
if presp.clicked() {
|
||||
actions.push(("file.useProxy".into(), json!({"item": id.0})));
|
||||
}
|
||||
@@ -485,6 +654,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
lp.rect_filled(sw, 2.0, t.label(it.label));
|
||||
let sresp = ui.interact(sw.expand(3.0).intersect(list), egui::Id::new(("plabel", id.0)), Sense::click());
|
||||
app.auto.add(&format!("project.item.{}.label", id.0), sw, it.label.name());
|
||||
sresp.widget_info(|| {
|
||||
let name = crate::i18n::tr_args("Label of {}: {}", &[&it.name, &app.session.prefs.label_name(it.label)]);
|
||||
egui::WidgetInfo::labeled(egui::WidgetType::Button, true, name)
|
||||
});
|
||||
let pop = egui::Id::new(("plabel-pop", id.0));
|
||||
if sresp.clicked() || sresp.secondary_clicked() {
|
||||
widgets::open_popup(ui, pop);
|
||||
@@ -510,8 +683,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if cell_edit(app, ui, &mut actions, "comment", cr) {
|
||||
continue;
|
||||
}
|
||||
let cresp = ui.interact(cell, egui::Id::new(("pcomment", id.0)), Sense::click());
|
||||
let cresp = ui.interact(cell, egui::Id::new(("pcomment", id.0)), Sense::CLICK);
|
||||
app.auto.add(&format!("project.item.{}.comment", id.0), cell, &it.comment);
|
||||
cresp.widget_info(|| {
|
||||
egui::WidgetInfo::labeled(egui::WidgetType::Other, true, crate::i18n::tr_args("Comment of {}: {}", &[&it.name, &it.comment]))
|
||||
});
|
||||
if cresp.double_clicked() {
|
||||
ctx.data_mut(|d| d.insert_temp::<Editing>(edit_id(), (id.0, "comment".into(), it.comment.clone())));
|
||||
} else {
|
||||
@@ -529,12 +705,18 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if dragging.is_some_and(|d| d != id.0) && drop_row == Some(*id) && it.is_folder() {
|
||||
lp.rect_stroke(r.shrink(1.0), 2.0, Stroke::new(1.5, t.accent), egui::StrokeKind::Inside);
|
||||
}
|
||||
let nresp = ui.interact(name_clip, egui::Id::new(("pname", id.0)), Sense::click_and_drag());
|
||||
// The row with keyboard focus (Tab, or the arrow keys after it) shows a focus ring.
|
||||
if ctx.memory(|m| m.has_focus(row_id(*id))) {
|
||||
lp.rect_stroke(r.shrink(0.5), 0.0, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside);
|
||||
}
|
||||
// Part of the row: not a second Tab stop.
|
||||
let nresp = ui.interact(name_clip, egui::Id::new(("pname", id.0)), Sense::CLICK | Sense::DRAG);
|
||||
app.auto.add(&format!("project.item.{}.name", id.0), name_clip, &it.name);
|
||||
let resp = resp.union(nresp);
|
||||
if resp.clicked() {
|
||||
let m = ui.input(|i| i.modifiers);
|
||||
let anchor_key = egui::Id::new("project-selection-anchor");
|
||||
let anchor_key = anchor_id();
|
||||
ctx.data_mut(|d| d.insert_temp(cursor_id(), *id));
|
||||
let anchor = ctx.data(|d| d.get_temp::<ItemId>(anchor_key)).or_else(|| app.session.state.project_selection.first().copied());
|
||||
if m.shift
|
||||
&& let Some(a) = anchor.and_then(|a| rows.iter().position(|(i, _)| *i == a))
|
||||
@@ -692,6 +874,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let r = Rect::from_min_size(pos2(x, foot.min.y + 3.0), vec2(22.0, 22.0));
|
||||
let resp = widgets::icon_button(ui, r, icon, false, &t, egui::Id::new(("pfoot", id))).on_hover_text(tip);
|
||||
app.auto.add(&format!("project.{id}"), r, tip);
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, crate::i18n::tr(tip)));
|
||||
if resp.clicked() {
|
||||
let footage =
|
||||
app.session.state.project_selection.first().and_then(|i| app.session.project.item(*i)).is_some_and(|i| matches!(i.kind, ItemKind::Footage(_)));
|
||||
@@ -724,6 +907,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let dresp = ui.interact(dr, egui::Id::new("bpc"), Sense::click());
|
||||
p.text(dr.center(), Align2::CENTER_CENTER, depth, Tokens::ui(11.5), if dresp.hovered() { t.text } else { t.text_dim });
|
||||
app.auto.add("project.bitDepth", dr, depth);
|
||||
dresp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, crate::i18n::tr_args("Project color depth: {}", &[&depth])));
|
||||
// Click cycles 8/16/32 bpc; Alt-click opens Project Settings (as in After Effects).
|
||||
if dresp.clicked() {
|
||||
if ui.input(|i| i.modifiers.alt) {
|
||||
@@ -734,9 +918,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
dresp.on_hover_text(crate::i18n::tr("Project color depth: click to cycle 8/16/32 bpc, Alt-click for Project Settings"));
|
||||
let tr = Rect::from_min_size(pos2(foot.max.x - 30.0, foot.min.y + 3.0), vec2(22.0, 22.0));
|
||||
if widgets::icon_button(ui, tr, Icon::Trash, false, &t, egui::Id::new("ptrash")).on_hover_text(crate::i18n::tr("Delete selected project items")).clicked()
|
||||
&& !app.session.state.project_selection.is_empty()
|
||||
{
|
||||
let trash = widgets::icon_button(ui, tr, Icon::Trash, false, &t, egui::Id::new("ptrash")).on_hover_text(crate::i18n::tr("Delete selected project items"));
|
||||
trash.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, crate::i18n::tr("Delete selected project items")));
|
||||
if trash.clicked() && !app.session.state.project_selection.is_empty() {
|
||||
actions.push(("project.delete".into(), json!({})));
|
||||
}
|
||||
app.auto.add("project.delete", tr, "Delete");
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
use crate::i18n::{tr, tr_args};
|
||||
use effectcraft_engine::prefs::{APPEARANCE_MODES, DARK_THEMES, Item, Kind, LIGHT_THEMES, Page, pages};
|
||||
use effectcraft_engine::segment::Task;
|
||||
use egui::{Color32, RichText, vec2};
|
||||
use egui::{Color32, Rect, RichText, vec2};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::theme::{ThemeKind, Tokens};
|
||||
@@ -118,7 +118,10 @@ fn page_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, page: &Page, cur: &Value
|
||||
let r = match kind {
|
||||
Kind::Int(lo, hi, unit) => {
|
||||
let mut x = v.as_i64().unwrap_or(0);
|
||||
let r = ui.add(crate::widgets::drag_value(egui::DragValue::new(&mut x).range(lo..=hi).speed(0.25)));
|
||||
// A typed number applies once entered: typing 85 into UI Scale
|
||||
// doesn't resize the interface to 75 % at its first digit.
|
||||
let drag = egui::DragValue::new(&mut x).range(lo..=hi).speed(0.25).update_while_editing(false);
|
||||
let r = ui.add(crate::widgets::drag_value(drag));
|
||||
if !unit.is_empty() {
|
||||
ui.label(RichText::new(unit).color(t.text_dim));
|
||||
}
|
||||
@@ -152,7 +155,6 @@ fn page_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, page: &Page, cur: &Value
|
||||
r
|
||||
}
|
||||
Kind::Choice(opts) => {
|
||||
// (A number with choices, UI Scale, shows as its text.)
|
||||
let curv = v.as_str().map_or_else(|| v.to_string(), str::to_string);
|
||||
let shown = opts.iter().find(|o| o.1 == curv).map(|o| o.0).unwrap_or(curv.as_str()).to_string();
|
||||
egui::ComboBox::from_id_salt(("settings", key))
|
||||
@@ -602,10 +604,40 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
let cur = serde_json::to_value(&app.session.prefs).unwrap_or_default();
|
||||
let mut acts: Vec<Act> = vec![];
|
||||
let (mut ok, mut cancel) = (false, false);
|
||||
super::dialogs::modal(ctx, "Settings", vec2(820.0, 600.0), t, |ui| {
|
||||
let body_h = (ctx.content_rect().height() - 170.0).clamp(120.0, 470.0);
|
||||
ui.allocate_ui_with_layout(vec2(ui.available_width(), body_h), egui::Layout::left_to_right(egui::Align::Min), |ui| {
|
||||
ui.set_height(body_h);
|
||||
super::dialogs::modal_fit(ctx, "Settings", vec2(820.0, 600.0), t, |ui, height| {
|
||||
// The buttons go first, from the bottom up, and the pages get the height they leave: at
|
||||
// a high UI Scale the pages scroll and the buttons stay in view.
|
||||
let area = ui.allocate_space(vec2(ui.available_width(), height)).1;
|
||||
let mut foot = ui.new_child(egui::UiBuilder::new().max_rect(area).layout(egui::Layout::bottom_up(egui::Align::Min)));
|
||||
foot.horizontal(|ui| {
|
||||
let r = ui.add_enabled(idx > 0, egui::Button::new(tr("Previous")));
|
||||
app.auto.add("settings.previous", r.rect, "Previous");
|
||||
if r.clicked() {
|
||||
page = all[idx - 1].id.to_string();
|
||||
}
|
||||
let r = ui.add_enabled(idx + 1 < all.len(), egui::Button::new(tr("Next")));
|
||||
app.auto.add("settings.next", r.rect, "Next");
|
||||
if r.clicked() {
|
||||
page = all[idx + 1].id.to_string();
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let r = ui.add(egui::Button::new(RichText::new(tr(" OK ")).color(Color32::WHITE)).fill(t.accent));
|
||||
app.auto.add("settings.ok", r.rect, "OK");
|
||||
ok |= r.clicked();
|
||||
let r = ui.button(tr("Cancel"));
|
||||
app.auto.add("settings.cancel", r.rect, "Cancel");
|
||||
cancel |= r.clicked();
|
||||
});
|
||||
});
|
||||
foot.separator();
|
||||
foot.add_space(8.0);
|
||||
let body_h = (foot.min_rect().top() - area.top()).max(0.0);
|
||||
// (A child, clipped to its share, so a wide page can't widen the dialog under the buttons.)
|
||||
let pages = Rect::from_min_size(area.min, vec2(area.width(), body_h));
|
||||
let mut body = ui.new_child(egui::UiBuilder::new().max_rect(pages).layout(egui::Layout::left_to_right(egui::Align::Min)));
|
||||
body.set_clip_rect(pages.intersect(body.clip_rect()));
|
||||
{
|
||||
let ui = &mut body;
|
||||
// Page list (left, like After Effects).
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(180.0);
|
||||
@@ -640,33 +672,11 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
let p = &all[idx];
|
||||
ui.label(RichText::new(tr(p.title)).font(Tokens::semibold(14.0)).color(t.tab_text_active));
|
||||
ui.add_space(6.0);
|
||||
egui::ScrollArea::vertical().max_height(body_h - 30.0).auto_shrink([false, false]).show(ui, |ui| {
|
||||
egui::ScrollArea::vertical().max_height((body_h - 30.0).max(0.0)).auto_shrink([false, false]).show(ui, |ui| {
|
||||
page_ui(app, ui, p, &cur, t, &mut acts);
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
let r = ui.add_enabled(idx > 0, egui::Button::new(tr("Previous")));
|
||||
app.auto.add("settings.previous", r.rect, "Previous");
|
||||
if r.clicked() {
|
||||
page = all[idx - 1].id.to_string();
|
||||
}
|
||||
let r = ui.add_enabled(idx + 1 < all.len(), egui::Button::new(tr("Next")));
|
||||
app.auto.add("settings.next", r.rect, "Next");
|
||||
if r.clicked() {
|
||||
page = all[idx + 1].id.to_string();
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let r = ui.add(egui::Button::new(RichText::new(tr(" OK ")).color(Color32::WHITE)).fill(t.accent));
|
||||
app.auto.add("settings.ok", r.rect, "OK");
|
||||
ok |= r.clicked();
|
||||
let r = ui.button(tr("Cancel"));
|
||||
app.auto.add("settings.cancel", r.rect, "Cancel");
|
||||
cancel |= r.clicked();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
app.dialog_state.settings_page = page;
|
||||
for a in acts {
|
||||
|
||||
@@ -579,6 +579,10 @@ pub(super) fn font_picker(app: &mut EffectcraftApp, ui: &mut egui::Ui, id: egui:
|
||||
});
|
||||
let preview = app.session.prefs.type_.font_preview;
|
||||
let t = app.tokens;
|
||||
// The Variable Fonts filter (After Effects 26.3) stays as set while the app runs, like the
|
||||
// menu's other settings; the search query resets on every open.
|
||||
let variable_id = id.with("variable-only");
|
||||
let mut only_variable = ui.data(|d| d.get_temp::<bool>(variable_id)).unwrap_or(false);
|
||||
// The font field itself becomes editable. The popup contains only results.
|
||||
let arrow = Rect::from_min_max(pos2(rect.max.x - 22.0, rect.min.y), rect.max);
|
||||
let edit_rect = Rect::from_min_max(rect.min, pos2(arrow.min.x, rect.max.y));
|
||||
@@ -608,12 +612,28 @@ pub(super) fn font_picker(app: &mut EffectcraftApp, ui: &mut egui::Ui, id: egui:
|
||||
let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).pivot(pivot).fixed_pos(anchor).show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| {
|
||||
ui.set_width(rect.width().max(180.0));
|
||||
// Filter row: a checkbox that keeps only the variable fonts.
|
||||
let filter_h = 22.0;
|
||||
let row = ui.add_sized([ui.available_width(), filter_h], egui::Button::selectable(false, ""));
|
||||
let box_rect = Rect::from_min_size(row.rect.min, vec2(18.0, filter_h));
|
||||
let label_rect = Rect::from_min_max(pos2(box_rect.max.x + 2.0, row.rect.min.y), row.rect.max);
|
||||
let boxed = widgets::checkbox(ui, box_rect, only_variable, &t, id.with("variable-check"));
|
||||
ui.painter().text(label_rect.left_center(), Align2::LEFT_CENTER, tr("Variable fonts only"), Tokens::ui(11.5), t.text);
|
||||
app.auto.add(&format!("{auto}.variable"), row.rect, "Variable fonts only");
|
||||
let toggled = row.clicked() || boxed.clicked();
|
||||
if toggled {
|
||||
only_variable = !only_variable;
|
||||
ui.data_mut(|d| d.insert_temp(variable_id, only_variable));
|
||||
// Typing goes on into the search field.
|
||||
ui.memory_mut(|m| m.request_focus(search_id));
|
||||
}
|
||||
let query = state.query.trim().to_lowercase();
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let filtered: Vec<_> = rows
|
||||
.iter()
|
||||
.filter(|r| {
|
||||
!r.family.is_empty()
|
||||
&& (!only_variable || r.variable)
|
||||
&& (query.is_empty()
|
||||
|| ((r.family.to_lowercase().contains(&query) || r.display.to_lowercase().contains(&query)) && seen.insert(&r.family)))
|
||||
})
|
||||
@@ -621,7 +641,7 @@ pub(super) fn font_picker(app: &mut EffectcraftApp, ui: &mut egui::Ui, id: egui:
|
||||
if fresh {
|
||||
state.selected = filtered.iter().position(|r| r.family == current).unwrap_or(0);
|
||||
}
|
||||
if search.changed() {
|
||||
if search.changed() || toggled {
|
||||
state.selected = 0;
|
||||
}
|
||||
let last = filtered.len().saturating_sub(1);
|
||||
@@ -637,10 +657,12 @@ pub(super) fn font_picker(app: &mut EffectcraftApp, ui: &mut egui::Ui, id: egui:
|
||||
}
|
||||
// Give the result list its actual height even when the previous query had
|
||||
// only one row. A cached tiny Area must not collapse a reopened long list.
|
||||
let height = (filtered.len() as f32 * (24.0 + ui.spacing().item_spacing.y) + 16.0).clamp(28.0, max_height);
|
||||
ui.set_height(height);
|
||||
let filter_room = filter_h + ui.spacing().item_spacing.y;
|
||||
let height = (filtered.len() as f32 * (24.0 + ui.spacing().item_spacing.y) + 16.0).clamp(28.0, (max_height - filter_room).max(28.0));
|
||||
// A minimum, from below the filter row (a maximum would move the cursor back up).
|
||||
ui.set_min_height(height);
|
||||
let mut scroll = egui::ScrollArea::vertical().id_salt(id.with("results")).max_height(height).min_scrolled_height(height);
|
||||
if search.changed() {
|
||||
if search.changed() || toggled {
|
||||
scroll = scroll.vertical_scroll_offset(0.0);
|
||||
}
|
||||
scroll.show(ui, |ui| {
|
||||
|
||||
@@ -488,6 +488,21 @@ impl TMap {
|
||||
}
|
||||
}
|
||||
|
||||
/// A Timeline ruler tick label for comp frame `fno`: seconds:frames (`00:15f`, AE) or, when
|
||||
/// the project's Time Display Style is Frames, the frame number the current-time display shows
|
||||
/// (`00015`, counted from Start Numbering Frames At) (#710).
|
||||
fn ruler_label(fno: i64, fps_i: i64, settings: &effectcraft_engine::project::ProjectSettings) -> String {
|
||||
if settings.time_display == effectcraft_engine::project::TimeDisplayStyle::Frames {
|
||||
return format!("{:05}", fno.saturating_add(settings.frame_start));
|
||||
}
|
||||
let fps_i = fps_i.max(1);
|
||||
if fno >= 60 * fps_i * 60 {
|
||||
format!("{}:{:02}:{:02}f", fno / (fps_i * 60), (fno / fps_i) % 60, fno % fps_i)
|
||||
} else {
|
||||
format!("{:02}:{:02}f", fno / fps_i, fno % fps_i)
|
||||
}
|
||||
}
|
||||
|
||||
fn tl_map_id() -> egui::Id {
|
||||
egui::Id::new("timeline-map")
|
||||
}
|
||||
@@ -1513,11 +1528,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let x = tm.x(s);
|
||||
pr.line_segment([pos2(x, ruler.max.y - 10.0), pos2(x, ruler.max.y)], Stroke::new(1.0, t.tl_ruler_tick));
|
||||
let fno = (s / fd).round() as i64;
|
||||
let label = if fno >= 60 * fps_i * 60 {
|
||||
format!("{}:{:02}:{:02}f", fno / (fps_i * 60), (fno / fps_i) % 60, fno % fps_i)
|
||||
} else {
|
||||
format!("{:02}:{:02}f", fno / fps_i, fno % fps_i)
|
||||
};
|
||||
let label = ruler_label(fno, fps_i, &app.session.project.settings);
|
||||
pr.text(pos2(x + 3.0, ruler.max.y - 16.0), Align2::LEFT_CENTER, label, Tokens::ui(10.0), t.tl_ruler_text);
|
||||
for k in 1..5 {
|
||||
let xx = tm.x(s + secs_per_label * k as f64 / 5.0);
|
||||
@@ -3671,7 +3682,16 @@ fn value_editor(
|
||||
);
|
||||
}
|
||||
Value::Gradient(_) => {
|
||||
p.text(pos2(x, at.y), Align2::LEFT_CENTER, crate::i18n::tr("Edit Gradient…"), Tokens::ui(12.0), t.hot_text);
|
||||
// Opens the Gradient Editor at the current time (#612).
|
||||
let r = p.text(pos2(x, at.y), Align2::LEFT_CENTER, crate::i18n::tr("Edit Gradient…"), Tokens::ui(12.0), t.hot_text);
|
||||
let resp = ui.interact(r.expand(2.0), egui::Id::new(("gradient-edit", uid)), Sense::click());
|
||||
if resp.hovered() {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);
|
||||
}
|
||||
app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);
|
||||
if resp.clicked() {
|
||||
actions.push(("prop.editGradient".into(), json!({"layer": layer.id.0, "prop": uid})));
|
||||
}
|
||||
}
|
||||
Value::Str(s) => {
|
||||
p.text(pos2(x, at.y), Align2::LEFT_CENTER, s.chars().take(30).collect::<String>(), Tokens::ui(12.0), t.text_dim);
|
||||
@@ -3684,6 +3704,23 @@ fn value_editor(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// #710: with Time Display set to Frames the ruler labels are frame numbers (as under the
|
||||
/// CTI, from Start Numbering Frames At); otherwise seconds:frames.
|
||||
#[test]
|
||||
fn ruler_labels_follow_the_time_display_style() {
|
||||
use effectcraft_engine::project::{ProjectSettings, TimeDisplayStyle};
|
||||
let mut st = ProjectSettings { time_display: TimeDisplayStyle::Timecode, frame_start: 0, ..ProjectSettings::default() };
|
||||
assert_eq!(ruler_label(15, 30, &st), "00:15f");
|
||||
assert_eq!(ruler_label(45, 30, &st), "01:15f");
|
||||
assert_eq!(ruler_label(30 * 3600 + 31, 30, &st), "60:01:01f");
|
||||
st.time_display = TimeDisplayStyle::Frames;
|
||||
assert_eq!(ruler_label(0, 30, &st), "00000");
|
||||
assert_eq!(ruler_label(45, 30, &st), "00045");
|
||||
st.frame_start = 1;
|
||||
assert_eq!(ruler_label(45, 30, &st), "00046");
|
||||
assert_eq!(ruler_label(i64::MAX, 30, &st), format!("{:05}", i64::MAX));
|
||||
}
|
||||
|
||||
/// #468: playback pages the view to the CTI; a scrub past either end scrolls that way.
|
||||
#[test]
|
||||
fn the_view_pages_to_the_cti() {
|
||||
|
||||
@@ -1113,6 +1113,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let context_layers: Vec<u64> =
|
||||
app.session.state.selected_layers.iter().filter(|id| comp.layer(**id).is_some_and(|l| !l.switches.locked)).map(|id| id.0).collect();
|
||||
let mut context_actions = Vec::new();
|
||||
let copy_frame = crate::i18n::label(app, "comp.copyFrame", "Copy Frame to Clipboard");
|
||||
resp.context_menu(|ui| {
|
||||
let hits = ui.data(|d| d.get_temp::<Vec<(u64, String)>>(menu_hits_id)).unwrap_or_default();
|
||||
if !hits.is_empty() {
|
||||
@@ -1133,6 +1134,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
} else {
|
||||
super::timeline::layer_menu(ui, &context_layers, &mut context_actions);
|
||||
}
|
||||
ui.separator();
|
||||
if ui.button(copy_frame).clicked() {
|
||||
context_actions.push(("comp.copyFrame".to_owned(), serde_json::json!({"comp": cid.0})));
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
for (id, params) in context_actions {
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
@@ -2282,7 +2288,7 @@ fn create_shape(app: &mut EffectcraftApp, tool: Tool, a: [f64; 2], b: [f64; 2],
|
||||
|
||||
fn empty_state(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let p = ui.painter();
|
||||
let p = ui.painter().clone();
|
||||
p.rect_filled(rect, 0.0, t.pasteboard);
|
||||
let c = rect.center();
|
||||
p.text(c - vec2(0.0, 40.0), Align2::CENTER_CENTER, crate::i18n::tr("Composition"), Tokens::semibold(16.0), t.text);
|
||||
@@ -2296,6 +2302,36 @@ fn empty_state(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let _ = crate::menus::invoke(app, &ui.ctx().clone(), "file.import", json!({}));
|
||||
}
|
||||
app.auto.add("viewer.empty.import", b2, "New Composition From Footage");
|
||||
// A Project item dropped on the empty viewer creates the first composition,
|
||||
// just like dropping it onto an empty Timeline (#684). Multiple selected
|
||||
// items use the existing New Comp from Selection dialog.
|
||||
let ctx = ui.ctx().clone();
|
||||
if let Some(crate::panels::DragPayload::Item(dragged)) = egui::DragAndDrop::payload::<crate::panels::DragPayload>(&ctx).as_deref()
|
||||
&& ui.rect_contains_pointer(rect)
|
||||
{
|
||||
let items: Vec<effectcraft_engine::project::ItemId> = crate::panels::project_drop_items(app, *dragged)
|
||||
.into_iter()
|
||||
.map(effectcraft_engine::project::ItemId)
|
||||
.filter(|id| {
|
||||
app.session.project.item(*id).is_some_and(|item| match &item.kind {
|
||||
effectcraft_engine::project::ItemKind::Footage(f) => f.kind != effectcraft_engine::project::FootageKind::Data,
|
||||
effectcraft_engine::project::ItemKind::Solid(_) | effectcraft_engine::project::ItemKind::Comp(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
if !items.is_empty() {
|
||||
p.rect_stroke(rect.shrink(2.0), 0.0, Stroke::new(2.0, t.accent), StrokeKind::Inside);
|
||||
app.auto.add("viewer.newCompDrop", rect, "Drop footage to create a composition");
|
||||
if ctx.input(|i| i.pointer.any_released()) {
|
||||
app.session.state.project_selection = items;
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, "file.newCompFromSelection", json!({})) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
egui::DragAndDrop::clear_payload(&ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `#rrggbb` → sRGB bytes.
|
||||
|
||||
@@ -91,14 +91,19 @@ pub fn dropped_files(app: &mut EffectcraftApp, ui: &egui::Ui, bounds: Rect) {
|
||||
// Dropped files import as stills and folders' numbered stills as sequences; Alt-drag
|
||||
// imports a folder's files one by one (After Effects).
|
||||
let alt = ctx.input(|i| i.modifiers.alt);
|
||||
// A dropped Photoshop file asks how to import it (the Import Photoshop File dialog, its
|
||||
// Import Kind starting at Default Drag Import As), as File ▸ Import ▸ File… does (#678).
|
||||
let layered = rest.iter().any(|p| p.rsplit('.').next().is_some_and(|e| matches!(e.to_ascii_lowercase().as_str(), "psd" | "psb")));
|
||||
let mut params = json!({
|
||||
"paths": rest,
|
||||
"drag": true,
|
||||
"importAs": app.session.prefs.drag_import_as(),
|
||||
"addToComp": at.is_some(),
|
||||
"position": at,
|
||||
"background": true
|
||||
});
|
||||
if !layered {
|
||||
params["importAs"] = json!(app.session.prefs.drag_import_as());
|
||||
}
|
||||
if alt {
|
||||
params["sequence"] = json!(false);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use effectcraft_ui_egui::dock::PanelKind;
|
||||
use effectcraft_ui_egui::panels::viewer::{comp_to_screen, last_fit};
|
||||
use egui::{Event, Modifiers, Pos2, Rect, pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
|
||||
/// Comp "Main" (4 s at 30 fps, current time 1 s) with solids Top, Middle and Bottom, and comp
|
||||
@@ -252,6 +253,48 @@ fn multiple_selected_footage_dropped_on_empty_timeline_asks_how_to_create_comps(
|
||||
assert!(h.state().session.active_comp().is_none(), "no composition until the user chooses");
|
||||
}
|
||||
|
||||
/// #684: dropping imported footage onto the empty Composition viewer creates
|
||||
/// a composition that matches the source, with that source as its first layer.
|
||||
#[test]
|
||||
fn project_footage_dropped_on_empty_viewer_creates_first_comp() {
|
||||
let mut s = Session::default();
|
||||
let footage =
|
||||
s.execute("file.importPlaceholder", json!({"name": "Landscape.png", "width": 640, "height": 360, "frameRate": 24, "duration": 5})).unwrap()["item"]
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
assert!(h.state().session.active_comp().is_none());
|
||||
let from = rect(&h, &format!("project.item.{footage}.name")).center();
|
||||
let viewer = rect(&h, "panel.Composition");
|
||||
drag(&mut h, from, pos2(viewer.min.x + 40.0, viewer.min.y + 70.0), Modifiers::NONE);
|
||||
let comp = h.state().session.active_comp().expect("created a composition");
|
||||
assert_eq!((comp.width, comp.height), (640, 360));
|
||||
assert_eq!(comp.frame_rate, effectcraft_engine::time::FrameRate::from_f64(24.0));
|
||||
assert_eq!(comp.duration.seconds(), 5.0);
|
||||
assert_eq!(comp.layers.len(), 1);
|
||||
assert_eq!(comp.layers[0].name, "Landscape.png");
|
||||
assert!(h.state().dialog.is_none());
|
||||
}
|
||||
|
||||
/// Several dragged sources must ask whether to create one or multiple comps,
|
||||
/// rather than silently discarding the other selected items.
|
||||
#[test]
|
||||
fn multiple_selected_footage_dropped_on_empty_viewer_asks_how_to_create_comps() {
|
||||
let mut s = Session::default();
|
||||
let first = s.execute("file.importPlaceholder", json!({"name": "First.png", "width": 160, "height": 90})).unwrap()["item"].as_u64().unwrap();
|
||||
let second = s.execute("file.importPlaceholder", json!({"name": "Second.png", "width": 300, "height": 200})).unwrap()["item"].as_u64().unwrap();
|
||||
s.state.project_selection = vec![effectcraft_engine::project::ItemId(first), effectcraft_engine::project::ItemId(second)];
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
let from = rect(&h, &format!("project.item.{first}.name")).center();
|
||||
let viewer = rect(&h, "panel.Composition");
|
||||
drag(&mut h, from, pos2(viewer.min.x + 40.0, viewer.min.y + 70.0), Modifiers::NONE);
|
||||
assert_eq!(h.state().dialog, Some(effectcraft_ui_egui::Dialog::Form));
|
||||
assert!(h.state().auto.find("form.field.single").is_some());
|
||||
assert!(h.state().session.active_comp().is_none(), "no composition until the user chooses");
|
||||
}
|
||||
|
||||
/// A file dropped on the window (egui hands it over as a dropped file).
|
||||
#[derive(Debug)]
|
||||
struct Dropped(std::path::PathBuf);
|
||||
@@ -379,6 +422,35 @@ fn dropped_file_on_viewer_imports_and_adds_layer_at_pointer() {
|
||||
assert!((p[0] - 80.0).abs() <= tol && (p[1] - 45.0).abs() <= tol, "{p:?}");
|
||||
}
|
||||
|
||||
/// #678: a dropped Photoshop file asks how to import it, as File ▸ Import ▸ File… does; the
|
||||
/// Import Kind starts at Settings ▸ Import ▸ Default Drag Import As, and OK imports the drop.
|
||||
#[test]
|
||||
fn dropped_photoshop_file_shows_the_import_photoshop_file_dialog() {
|
||||
let (mut h, _) = harness();
|
||||
h.state_mut().session.importer = Some(Arc::new(Gated { started: AtomicUsize::new(0), allow: Arc::new(AtomicUsize::new(usize::MAX)) }));
|
||||
h.state_mut().session.prefs.import.drag_import_as = "compLayerSizes".into();
|
||||
h.event(Event::PointerMoved(rect(&h, "panel.Project").center()));
|
||||
h.step();
|
||||
h.input_mut().dropped_files.push(Arc::new(Dropped(std::env::temp_dir().join("Layers.PSD"))));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, Some(effectcraft_ui_egui::Dialog::Form), "the drop asks first");
|
||||
h.run_steps(2);
|
||||
assert!(h.query_by_label("Import Photoshop File").is_some());
|
||||
assert!(h.query_by_value("Composition - Retain Layer Sizes").is_some(), "Import Kind starts at Default Drag Import As");
|
||||
assert!(!h.state().session.project.items.values().any(|i| i.name == "Layers.PSD"), "nothing imported before OK");
|
||||
click_id(&mut h, "form.cancel");
|
||||
assert_eq!(h.state().dialog, None);
|
||||
|
||||
// With Default Drag Import As at Footage, OK imports the file as one item.
|
||||
h.state_mut().session.prefs.import.drag_import_as = "footage".into();
|
||||
h.input_mut().dropped_files.push(Arc::new(Dropped(std::env::temp_dir().join("Layers.PSD"))));
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().dialog, Some(effectcraft_ui_egui::Dialog::Form));
|
||||
assert!(h.query_by_value("Footage").is_some());
|
||||
click_id(&mut h, "form.ok");
|
||||
step_until(&mut h, |h| h.state().session.project.items.values().any(|i| i.name == "Layers.PSD"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unsupported_drop_reports_the_error_and_keeps_valid_files() {
|
||||
let (mut h, _) = harness();
|
||||
|
||||
@@ -105,3 +105,74 @@ fn font_search_preserves_edited_text_and_applies_only_to_selected_characters() {
|
||||
assert_eq!(doc.style_at(0).font, "Noto Serif");
|
||||
assert_eq!(doc.style_at(8).font, "Inter");
|
||||
}
|
||||
|
||||
/// A font file of just `name` (the family, Regular) and an `fvar` table with one axis pinned at
|
||||
/// 400: a variable font as far as the font menu's filter is concerned.
|
||||
fn pinned_variable_font(family: &str) -> Vec<u8> {
|
||||
let u16s = |v: &[u16]| -> Vec<u8> { v.iter().flat_map(|x| x.to_be_bytes()).collect() };
|
||||
let strings: Vec<Vec<u8>> = [family, "Regular"].iter().map(|s| s.encode_utf16().flat_map(|u| u.to_be_bytes()).collect()).collect();
|
||||
let mut name = u16s(&[0, 2, 30]);
|
||||
let mut off = 0;
|
||||
for (id, st) in strings.iter().enumerate() {
|
||||
name.extend(u16s(&[3, 1, 0x409, id as u16 + 1, st.len() as u16, off]));
|
||||
off += st.len() as u16;
|
||||
}
|
||||
strings.iter().for_each(|st| name.extend(st));
|
||||
let mut fvar = u16s(&[1, 0, 16, 2, 1, 20, 0, 8]);
|
||||
fvar.extend(b"wght".iter().copied().chain(u16s(&[0x190, 0, 0x190, 0, 0x190, 0, 0, 256])));
|
||||
let mut out = u16s(&[1, 0, 2, 0, 0, 0]);
|
||||
let mut body: Vec<u8> = vec![];
|
||||
for (tag, data) in [(b"fvar", fvar), (b"name", name)] {
|
||||
out.extend(tag);
|
||||
out.extend([0u8; 4]);
|
||||
out.extend(((12 + 32 + body.len()) as u32).to_be_bytes());
|
||||
out.extend((data.len() as u32).to_be_bytes());
|
||||
body.extend(data);
|
||||
}
|
||||
out.extend(body);
|
||||
out
|
||||
}
|
||||
|
||||
/// The font menu's Variable Fonts filter (After Effects 26.3): the checkbox keeps only variable
|
||||
/// families, works with the typed search (which keeps the keyboard), and stays on when the menu
|
||||
/// is reopened until it is turned off.
|
||||
#[test]
|
||||
fn font_menu_filters_variable_fonts() {
|
||||
const FAMILY: &str = "Inter Variable Menu Test";
|
||||
assert_eq!(effectcraft_engine::text::fonts::add_font_data(pinned_variable_font(FAMILY)).len(), 1);
|
||||
let variable = effectcraft_engine::text::fonts::variable_families();
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"width": 320, "height": 180})).unwrap();
|
||||
let lid = s.execute("layer.newText", json!({"text": "Var", "font": "Inter"})).unwrap()["layer"].as_u64().unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(move |_| EffectcraftApp::new(s));
|
||||
h.state_mut().show_panel(PanelKind::Character);
|
||||
h.run_steps(3);
|
||||
let families = |h: &Harness<'_, EffectcraftApp>| -> Vec<String> {
|
||||
h.state().auto.query("character.font.option.").iter().map(|e| e.id.trim_start_matches("character.font.option.").to_string()).collect()
|
||||
};
|
||||
click(&mut h, "character.font");
|
||||
type_text(&mut h, "inter");
|
||||
let shown = families(&h);
|
||||
assert!(shown.iter().any(|f| f == "Inter") && shown.iter().any(|f| f == FAMILY), "unfiltered at first: {shown:?}");
|
||||
click(&mut h, "character.font.variable");
|
||||
let shown = families(&h);
|
||||
assert!(shown.iter().any(|f| f == FAMILY), "{shown:?}");
|
||||
assert!(shown.iter().all(|f| variable.contains(f)), "only variable families: {shown:?}");
|
||||
// The search field keeps the keyboard and narrows the filtered list further.
|
||||
type_text(&mut h, " variable menu");
|
||||
assert_eq!(families(&h), vec![FAMILY.to_string()]);
|
||||
type_text(&mut h, "x");
|
||||
assert!(families(&h).is_empty());
|
||||
assert!(h.state().auto.find("character.font.empty").is_some());
|
||||
key(&mut h, Key::Escape);
|
||||
// Reopened: still filtered; turning it off lists the static families again.
|
||||
click(&mut h, "character.font");
|
||||
h.run_steps(2);
|
||||
let shown = families(&h);
|
||||
assert!(!shown.is_empty() && shown.iter().all(|f| variable.contains(f)), "the filter stays on: {shown:?}");
|
||||
click(&mut h, "character.font.variable");
|
||||
type_text(&mut h, "inter");
|
||||
assert!(families(&h).iter().any(|f| f == "Inter"), "{:?}", families(&h));
|
||||
key(&mut h, Key::Escape);
|
||||
assert_eq!(layer_doc(&h.state().session, LayerId(lid)).unwrap().font, "Inter", "filtering changes nothing");
|
||||
}
|
||||
|
||||
@@ -250,6 +250,36 @@ fn reshape_correspondence_points_on_the_viewer() {
|
||||
assert_eq!(h.state().session.history.undo.len(), undo_len + 1);
|
||||
}
|
||||
|
||||
/// #303: with Mesh Warp selected, the viewer shows its grid; dragging a vertex warps the mesh
|
||||
/// (one undo step), and the other vertices stay put.
|
||||
#[test]
|
||||
fn mesh_warp_vertices_drag_on_the_viewer() {
|
||||
let (mut s0, l, fx) = with_effect("Mesh Warp");
|
||||
let g = s0.active_comp().unwrap().layer(LayerId(l)).unwrap().props.find_group(fx).unwrap().clone();
|
||||
s0.execute("prop.set", json!({"layer": l, "prop": g.get("rows").unwrap().uid, "value": 2})).unwrap();
|
||||
s0.execute("prop.set", json!({"layer": l, "prop": g.get("columns").unwrap().uid, "value": 2})).unwrap();
|
||||
let mut h = harness(s0);
|
||||
h.state_mut().toggle_maximize(PanelKind::EffectControls);
|
||||
h.state_mut().session.state.selected_props = vec![(LayerId(l), fx)];
|
||||
for _ in 0..6 {
|
||||
h.step();
|
||||
}
|
||||
let v = |r: usize, c: usize| format!("viewer.meshWarp.{fx}.{r}.{c}");
|
||||
let (tl, mid, br) = (rect(&h, &v(0, 0)).center(), rect(&h, &v(1, 1)).center(), rect(&h, &v(2, 2)).center());
|
||||
assert!(((tl.x + br.x) / 2.0 - mid.x).abs() < 1.0 && ((tl.y + br.y) / 2.0 - mid.y).abs() < 1.0, "{tl:?} {mid:?} {br:?}");
|
||||
assert!(br.x - tl.x > 100.0, "the grid spans the layer: {tl:?} {br:?}");
|
||||
assert_eq!(s(value(&h, l, fx, "mesh")), "");
|
||||
let undo_len = h.state().session.history.undo.len();
|
||||
drag(&mut h, mid, mid + egui::vec2(40.0, 0.0));
|
||||
let mesh = effectcraft_engine::effects::parse_mesh(&s(value(&h, l, fx, "mesh")));
|
||||
assert_eq!(mesh.len(), 9, "{mesh:?}");
|
||||
assert!(mesh[4].0 > 10.0 && mesh[4].1.abs() < 1.0, "the centre vertex moved right: {mesh:?}");
|
||||
assert!(mesh.iter().enumerate().all(|(i, o)| i == 4 || *o == (0.0, 0.0)), "{mesh:?}");
|
||||
assert_eq!(h.state().session.history.undo.len(), undo_len + 1);
|
||||
let moved = rect(&h, &v(1, 1)).center();
|
||||
assert!((moved.x - mid.x - 40.0).abs() < 2.0, "the handle follows the vertex: {mid:?} → {moved:?}");
|
||||
}
|
||||
|
||||
/// UI fixes of M13.10: the Composition / Timeline tabs' close button, swatch and lock; the
|
||||
/// Preview panel scrolls in the default workspace (where it shows just the transport).
|
||||
#[test]
|
||||
|
||||
@@ -0,0 +1,493 @@
|
||||
//! The Gradient Editor (#612): the Timeline's "Edit Gradient…" opens it on a gradient property
|
||||
//! (here a shape layer's Gradient Fill ▸ Colors). OK sets the edited gradient with one undo step
|
||||
//! at the composition time it opened at (offset and stretched layers too); OK with no change, Cancel
|
||||
//! and Escape change nothing; on an animated gradient only the keyframe at that time changes, with
|
||||
//! a warning when its stop counts no longer match a neighbour's.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::keyframe::{Gradient, Value};
|
||||
use effectcraft_engine::project::{LayerId, PropGroup};
|
||||
use effectcraft_engine::time::Tick;
|
||||
use effectcraft_ui_egui::panels::gradient_editor::Track;
|
||||
use effectcraft_ui_egui::{Dialog, EffectcraftApp};
|
||||
use egui::accesskit::Role;
|
||||
use egui::{Event, Key, Modifiers, PointerButton, Pos2, pos2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
const WARNING: &str = "These adjacent keyframes cannot interpolate because their stop counts differ.";
|
||||
|
||||
/// The uids from the layer's root down to the Gradient Fill group, and its Colors property.
|
||||
fn gradient_fill(g: &PropGroup) -> Option<(Vec<u64>, u64)> {
|
||||
for x in g.groups() {
|
||||
if x.match_id == "gfill" {
|
||||
return Some((vec![x.uid], x.get("colors")?.uid));
|
||||
}
|
||||
if let Some((mut path, colors)) = gradient_fill(x) {
|
||||
path.insert(0, x.uid);
|
||||
return Some((path, colors));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// A 20 s comp with a rectangle shape layer holding a Gradient Fill, its rows open in the
|
||||
/// Timeline. `timing` runs on the layer first (start, stretch). Returns (harness, layer, Colors uid).
|
||||
fn setup(timing: &[(&str, serde_json::Value)]) -> (Harness<'static, EffectcraftApp>, u64, u64) {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "duration": 20})).unwrap();
|
||||
let l = s.execute("layer.newShape", json!({"kind": "rect"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.addShapeItem", json!({"layer": l, "kind": "gfill"})).unwrap();
|
||||
for (cmd, p) in timing {
|
||||
let mut p = p.clone();
|
||||
p["layers"] = json!([l]);
|
||||
s.execute(cmd, p).unwrap();
|
||||
}
|
||||
let (groups, colors) = gradient_fill(&s.active_comp().unwrap().layer(LayerId(l)).unwrap().props).expect("a Gradient Fill");
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.state_mut().ui.timeline.open_layers.insert(l);
|
||||
h.state_mut().ui.timeline.open_groups.extend(groups);
|
||||
h.run_steps(3);
|
||||
(h, l, colors)
|
||||
}
|
||||
|
||||
fn rect(h: &Harness<'_, EffectcraftApp>, id: &str) -> [f32; 4] {
|
||||
h.state().auto.find(id).unwrap_or_else(|| panic!("no automation id {id}")).rect
|
||||
}
|
||||
|
||||
fn center(h: &Harness<'_, EffectcraftApp>, id: &str) -> Pos2 {
|
||||
let r = rect(h, id);
|
||||
pos2(r[0] + r[2] / 2.0, r[1] + r[3] / 2.0)
|
||||
}
|
||||
|
||||
/// The point at `f` (0..1) along the bar, at the height of automation id `row`.
|
||||
fn along(h: &Harness<'_, EffectcraftApp>, row: &str, f: f32) -> Pos2 {
|
||||
let bar = rect(h, "dialog.gradient.bar");
|
||||
pos2(bar[0] + bar[2] * f, center(h, row).y)
|
||||
}
|
||||
|
||||
fn click_at(h: &mut Harness<'_, EffectcraftApp>, p: Pos2) {
|
||||
h.input_mut().events.push(Event::PointerMoved(p));
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn click(h: &mut Harness<'_, EffectcraftApp>, id: &str) {
|
||||
let p = center(h, id);
|
||||
click_at(h, p);
|
||||
}
|
||||
|
||||
fn drag(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) {
|
||||
h.input_mut().events.push(Event::PointerMoved(from));
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
for k in 1..=6 {
|
||||
let f = k as f32 / 6.0;
|
||||
h.input_mut().events.push(Event::PointerMoved(from + (to - from) * f));
|
||||
h.step();
|
||||
}
|
||||
h.input_mut().events.push(Event::PointerButton { pos: to, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn key(h: &mut Harness<'_, EffectcraftApp>, k: Key) {
|
||||
h.input_mut().events.push(Event::Key { key: k, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.input_mut().events.push(Event::Key { key: k, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn colors_prop(h: &Harness<'_, EffectcraftApp>, l: u64, uid: u64) -> effectcraft_engine::project::Property {
|
||||
h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().props.find(uid).unwrap().clone()
|
||||
}
|
||||
|
||||
fn gradient(v: &Value) -> Gradient {
|
||||
match v {
|
||||
Value::Gradient(g) => g.clone(),
|
||||
other => panic!("not a gradient: {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn open_editor(h: &mut Harness<'_, EffectcraftApp>, colors: u64) {
|
||||
let id = format!("timeline.prop.{colors}.value");
|
||||
assert!(h.state().auto.find(&id).is_some(), "no automation id {id}: the Timeline's gradient value isn't clickable");
|
||||
click(h, &id);
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
fn set_time(h: &mut Harness<'_, EffectcraftApp>, t: f64) {
|
||||
h.state_mut().session.execute("time.set", json!({"time": t})).unwrap();
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
fn add_key(h: &mut Harness<'_, EffectcraftApp>, l: u64, colors: u64, comp_t: f64, g: &Gradient) {
|
||||
h.state_mut()
|
||||
.session
|
||||
.execute("prop.addKey", json!({"layer": l, "prop": colors, "time": comp_t, "timeBase": "comp", "value": Value::Gradient(g.clone()).to_json()}))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn near(a: [f32; 4], b: [f32; 4]) -> bool {
|
||||
a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-4)
|
||||
}
|
||||
|
||||
/// The shared colour picker is showing (its colour field is in the accessibility tree).
|
||||
fn picker_open(h: &Harness<'_, EffectcraftApp>) -> bool {
|
||||
h.query_by_label("Color field").is_some()
|
||||
}
|
||||
|
||||
/// Type `hex` into the open picker's Hex field, over the code it shows.
|
||||
fn type_hex(h: &mut Harness<'_, EffectcraftApp>, hex: &str) {
|
||||
let at = h.get_by_role_and_label(Role::TextInput, "#").rect().center();
|
||||
click_at(h, at);
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::Key { key: Key::A, physical_key: None, pressed, repeat: false, modifiers: Modifiers::COMMAND });
|
||||
}
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::Text(hex.into()));
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn stop_color(h: &Harness<'_, EffectcraftApp>, id: u64) -> [f32; 4] {
|
||||
h.state().gradient_draft().colors.iter().find(|s| s.id == id).expect("the stop").value
|
||||
}
|
||||
|
||||
/// The numbers the editor's fields show (their accessibility values).
|
||||
fn shown_numbers(h: &Harness<'_, EffectcraftApp>) -> Vec<f64> {
|
||||
h.query_all_by(|n| n.numeric_value().is_some()).filter_map(|n| n.accesskit_node().numeric_value()).collect()
|
||||
}
|
||||
|
||||
fn undo_len(h: &Harness<'_, EffectcraftApp>) -> usize {
|
||||
h.state().session.history.undo.len()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stop_edits_ok_sets_the_gradient_in_one_undo_step() {
|
||||
let (mut h, l, colors) = setup(&[]);
|
||||
let before = colors_prop(&h, l, colors).value.clone();
|
||||
let undo = undo_len(&h);
|
||||
open_editor(&mut h, colors);
|
||||
assert_eq!(h.state().dialog, Some(Dialog::GradientEditor));
|
||||
// Add a colour stop a quarter along, recolour it, and drag the right opacity stop to the middle.
|
||||
let p = along(&h, "dialog.gradient.addColor", 0.25);
|
||||
click_at(&mut h, p);
|
||||
let (track, id) = h.state().gradient_draft().selected.expect("the new stop is selected");
|
||||
assert_eq!(track, Track::Color);
|
||||
let sampled = stop_color(&h, id);
|
||||
// The swatch opens the shared colour picker over the modal editor. A click in its colour field
|
||||
// reaches it (a modal blocks the layers below it), and so does typing a hex code.
|
||||
click(&mut h, "dialog.gradient.color");
|
||||
assert!(picker_open(&h), "the colour picker opened");
|
||||
let field = h.get_by_label("Color field").rect().center();
|
||||
click_at(&mut h, field + egui::vec2(20.0, -20.0));
|
||||
assert_ne!(stop_color(&h, id), sampled, "a click in the picker's colour field changed the stop");
|
||||
type_hex(&mut h, "336699");
|
||||
let picked = stop_color(&h, id);
|
||||
assert!(near(picked, [0.2, 0.4, 0.6, sampled[3]]), "the hex code's colour, and the stop kept its alpha: {picked:?}");
|
||||
// Clicking outside the picker keeps the colour and closes it; the editor stays.
|
||||
let title = h.get_by_label("Gradient Editor").rect().center();
|
||||
click_at(&mut h, title);
|
||||
assert!(!picker_open(&h), "the picker closed");
|
||||
assert_eq!(h.state().dialog, Some(Dialog::GradientEditor));
|
||||
assert_eq!(stop_color(&h, id), picked);
|
||||
let from = center(&h, "dialog.gradient.opacityStop.1");
|
||||
let to = along(&h, "dialog.gradient.opacityStop.1", 0.5);
|
||||
drag(&mut h, from, to);
|
||||
assert_eq!(undo_len(&h), undo, "nothing is set while editing");
|
||||
click(&mut h, "dialog.gradient.ok");
|
||||
assert_eq!(h.state().dialog, None);
|
||||
let g = gradient(&colors_prop(&h, l, colors).value);
|
||||
assert_eq!(g.colors.len(), 3, "{g:?}");
|
||||
assert!((g.colors[1].0 - 0.25).abs() < 0.02 && g.colors[1].1 == picked, "{g:?}");
|
||||
assert!((g.opacities[1].0 - 0.5).abs() < 0.02, "{g:?}");
|
||||
assert_eq!(undo_len(&h), undo + 1, "one undo step");
|
||||
h.state_mut().session.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(colors_prop(&h, l, colors).value, before, "one undo restores it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_and_escape_change_nothing() {
|
||||
for cancel in ["button", "escape"] {
|
||||
let (mut h, _, colors) = setup(&[]);
|
||||
let project = h.state().session.project.clone();
|
||||
let undo = undo_len(&h);
|
||||
open_editor(&mut h, colors);
|
||||
let p = along(&h, "dialog.gradient.addOpacity", 0.4);
|
||||
click_at(&mut h, p);
|
||||
assert_eq!(h.state().gradient_draft().opacities.len(), 3);
|
||||
if cancel == "button" {
|
||||
click(&mut h, "dialog.gradient.cancel");
|
||||
} else {
|
||||
key(&mut h, Key::Escape);
|
||||
}
|
||||
assert_eq!(h.state().dialog, None, "{cancel}");
|
||||
assert_eq!(h.state().session.project, project, "{cancel} leaves the project as it was");
|
||||
assert_eq!(undo_len(&h), undo);
|
||||
}
|
||||
}
|
||||
|
||||
/// OK without a change adds no keyframe between two (prop.set would add one).
|
||||
#[test]
|
||||
fn ok_without_changes_adds_no_keyframe() {
|
||||
let (mut h, l, colors) = setup(&[]);
|
||||
add_key(&mut h, l, colors, 1.0, &Gradient::default());
|
||||
add_key(&mut h, l, colors, 3.0, &Gradient::default());
|
||||
set_time(&mut h, 2.0);
|
||||
let undo = undo_len(&h);
|
||||
open_editor(&mut h, colors);
|
||||
click(&mut h, "dialog.gradient.ok");
|
||||
assert_eq!(h.state().dialog, None);
|
||||
assert_eq!(colors_prop(&h, l, colors).keys.len(), 2, "still the two keyframes");
|
||||
assert_eq!(undo_len(&h), undo, "no undo step");
|
||||
}
|
||||
|
||||
/// On an animated gradient OK sets the keyframe at the edit time (adding one between keys) and no
|
||||
/// other.
|
||||
#[test]
|
||||
fn animated_edits_change_only_the_keyframe_at_the_edit_time() {
|
||||
let (mut h, l, colors) = setup(&[]);
|
||||
let red = Gradient { colors: vec![(0.0, [1.0, 0.0, 0.0, 1.0]), (1.0, [0.0, 0.0, 0.0, 1.0])], ..Gradient::default() };
|
||||
add_key(&mut h, l, colors, 1.0, &Gradient::default());
|
||||
add_key(&mut h, l, colors, 3.0, &red);
|
||||
let first = colors_prop(&h, l, colors).keys[0].clone();
|
||||
for (t, keys) in [(3.0, 2), (2.0, 3)] {
|
||||
set_time(&mut h, t);
|
||||
open_editor(&mut h, colors);
|
||||
let d = &h.state().gradient_draft();
|
||||
let id = d.id_at(Track::Color, 1).unwrap();
|
||||
h.state_mut().gradient_draft_mut().set_rgb(id, [0.0, 0.0, 1.0]);
|
||||
click(&mut h, "dialog.gradient.ok");
|
||||
let pr = colors_prop(&h, l, colors);
|
||||
assert_eq!(pr.keys.len(), keys, "at {t} s");
|
||||
assert_eq!(pr.keys[0], first, "the keyframe at 1 s is untouched");
|
||||
let layer = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().clone();
|
||||
// The edit time snapped to the nearest frame (29.97 fps), as prop.set snaps it.
|
||||
let at = h.state().session.active_comp().unwrap().frame_rate.snap_nearest(Tick::from_seconds_f64(t)).seconds();
|
||||
let k = pr.keys.iter().find(|k| (layer.comp_time(k.time).seconds() - at).abs() < 1e-6).expect("a keyframe at the edit time");
|
||||
assert_eq!(gradient(&k.value).colors[1].1, [0.0, 0.0, 1.0, 1.0], "at {t} s");
|
||||
}
|
||||
}
|
||||
|
||||
/// The key goes at the composition time the editor opened at, on a layer that starts late or is
|
||||
/// stretched (layer time differs from composition time).
|
||||
#[test]
|
||||
fn offset_and_stretched_layers_get_the_keyframe_at_the_comp_time() {
|
||||
for timing in
|
||||
[vec![("layer.timing", json!({"start": 5.0}))], vec![("layer.timing", json!({"start": 5.0})), ("layer.timeStretch", json!({"percent": 200.0}))]]
|
||||
{
|
||||
let (mut h, l, colors) = setup(&timing);
|
||||
set_time(&mut h, 5.5);
|
||||
h.state_mut().session.execute("prop.toggleAnimation", json!({"layer": l, "prop": colors})).unwrap();
|
||||
set_time(&mut h, 6.0);
|
||||
open_editor(&mut h, colors);
|
||||
let p = along(&h, "dialog.gradient.addColor", 0.5);
|
||||
click_at(&mut h, p);
|
||||
click(&mut h, "dialog.gradient.ok");
|
||||
let layer = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().clone();
|
||||
let pr = layer.props.find(colors).unwrap();
|
||||
let comp_times: Vec<f64> = pr.keys.iter().map(|k| layer.comp_time(k.time).seconds()).collect();
|
||||
assert_eq!(pr.keys.len(), 2, "{timing:?}: {comp_times:?}");
|
||||
// Composition time 6 s snapped to the nearest frame (29.97 fps: 6.006 s), as prop.set snaps
|
||||
// it: the layer's start and stretch don't move it.
|
||||
let at = h.state().session.active_comp().unwrap().frame_rate.snap_nearest(Tick::from_seconds_f64(6.0)).seconds();
|
||||
let k = pr.keys.iter().find(|k| (layer.comp_time(k.time).seconds() - at).abs() < 1e-6);
|
||||
let k = k.unwrap_or_else(|| panic!("{timing:?}: no keyframe at comp time {at} s: {comp_times:?}"));
|
||||
assert_eq!(gradient(&k.value).colors.len(), 3, "{timing:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Adding a stop next to keyframes with fewer stops warns that they can't interpolate; it still
|
||||
/// saves, the neighbour keeps its stops, and the animation holds until the edited keyframe.
|
||||
#[test]
|
||||
fn mismatched_stop_counts_warn_and_neighbours_stay() {
|
||||
let (mut h, l, colors) = setup(&[]);
|
||||
add_key(&mut h, l, colors, 1.0, &Gradient::default());
|
||||
add_key(&mut h, l, colors, 3.0, &Gradient::default());
|
||||
set_time(&mut h, 3.0);
|
||||
open_editor(&mut h, colors);
|
||||
assert!(h.query_by_label(WARNING).is_none(), "same counts: no warning");
|
||||
let p = along(&h, "dialog.gradient.addColor", 0.5);
|
||||
click_at(&mut h, p);
|
||||
assert!(h.query_by_label(WARNING).is_some(), "three colour stops next to a keyframe with two");
|
||||
click(&mut h, "dialog.gradient.ok");
|
||||
let pr = colors_prop(&h, l, colors);
|
||||
assert_eq!(pr.keys.len(), 2);
|
||||
assert_eq!(gradient(&pr.keys[0].value), Gradient::default(), "the neighbour keeps its stops");
|
||||
assert_eq!(gradient(&pr.keys[1].value).colors.len(), 3);
|
||||
let layer = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().clone();
|
||||
let mid = pr.value_at(layer.layer_time(Tick::from_seconds_f64(2.0)));
|
||||
assert_eq!(gradient(&mid), Gradient::default(), "it holds the first keyframe instead of blending");
|
||||
}
|
||||
|
||||
/// Delete removes the selected stop (never a layer, and never the last stop of a track), but not
|
||||
/// while typing in a field.
|
||||
#[test]
|
||||
fn delete_removes_the_selected_stop_but_not_the_last_or_while_typing() {
|
||||
let (mut h, _, colors) = setup(&[]);
|
||||
let layers = h.state().session.active_comp().unwrap().layers.len();
|
||||
open_editor(&mut h, colors);
|
||||
click(&mut h, "dialog.gradient.colorStop.0");
|
||||
key(&mut h, Key::Delete);
|
||||
assert_eq!(h.state().gradient_draft().colors.len(), 1, "Delete removed the selected stop");
|
||||
click(&mut h, "dialog.gradient.colorStop.0");
|
||||
key(&mut h, Key::Delete);
|
||||
click(&mut h, "dialog.gradient.delete");
|
||||
assert_eq!(h.state().gradient_draft().colors.len(), 1, "the last colour stop stays");
|
||||
assert_eq!(h.state().session.active_comp().unwrap().layers.len(), layers, "Delete never reaches the layer");
|
||||
assert_eq!(h.state().dialog, Some(Dialog::GradientEditor));
|
||||
// Typing in Location: Delete edits the text, not the stops.
|
||||
click(&mut h, "dialog.gradient.opacityStop.0");
|
||||
click(&mut h, "dialog.gradient.location");
|
||||
assert!(h.ctx.egui_wants_keyboard_input(), "the Location field takes the keyboard");
|
||||
key(&mut h, Key::Delete);
|
||||
assert_eq!(h.state().gradient_draft().opacities.len(), 2, "typing doesn't delete a stop");
|
||||
}
|
||||
|
||||
/// One colour stop saves (the typed form; plain JSON needs two) and one undo brings both back.
|
||||
#[test]
|
||||
fn a_single_colour_stop_saves_and_undoes() {
|
||||
let (mut h, l, colors) = setup(&[]);
|
||||
let before = colors_prop(&h, l, colors).value.clone();
|
||||
let undo = undo_len(&h);
|
||||
open_editor(&mut h, colors);
|
||||
click(&mut h, "dialog.gradient.colorStop.1");
|
||||
click(&mut h, "dialog.gradient.delete");
|
||||
assert_eq!(h.state().gradient_draft().colors.len(), 1);
|
||||
click(&mut h, "dialog.gradient.ok");
|
||||
let g = gradient(&colors_prop(&h, l, colors).value);
|
||||
assert_eq!(g.colors, gradient(&before).colors[..1].to_vec(), "{g:?}");
|
||||
assert_eq!(g.opacities, gradient(&before).opacities, "opacity stops unchanged");
|
||||
assert_eq!(undo_len(&h), undo + 1);
|
||||
h.state_mut().session.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(colors_prop(&h, l, colors).value, before);
|
||||
}
|
||||
|
||||
/// Typing a Location that moves a stop past its neighbour keeps the selection on that stop, and
|
||||
/// in the same frame the Opacity field shows its value, not the neighbour's (now at its old index).
|
||||
#[test]
|
||||
fn location_moves_past_a_neighbour_and_the_fields_follow_the_stop() {
|
||||
let (mut h, _, colors) = setup(&[]);
|
||||
open_editor(&mut h, colors);
|
||||
// Opacity 100% at 0 and 40% at 1, plus a stop at 0.5 sampled from them: 70%.
|
||||
let right = h.state().gradient_draft().opacities[1].id;
|
||||
h.state_mut().gradient_draft_mut().set_opacity(right, 0.4);
|
||||
let p = along(&h, "dialog.gradient.addOpacity", 0.5);
|
||||
click_at(&mut h, p);
|
||||
let middle = h.state().gradient_draft().selected.expect("the new stop").1;
|
||||
let i = h.state().gradient_draft().index_of(Track::Opacity, middle).unwrap();
|
||||
assert!((h.state().gradient_draft().opacities[i].value - 0.7).abs() < 0.02, "it sampled 70%");
|
||||
// Select the 100% stop at 0 and type 80 into Location: it passes the stop at 0.5.
|
||||
let first = h.state().gradient_draft().opacities[0].id;
|
||||
click(&mut h, "dialog.gradient.opacityStop.0");
|
||||
click(&mut h, "dialog.gradient.location");
|
||||
assert!(h.ctx.egui_wants_keyboard_input(), "the Location field is being typed in");
|
||||
h.input_mut().events.push(Event::Key { key: Key::A, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::COMMAND });
|
||||
h.input_mut().events.push(Event::Text("80".into()));
|
||||
h.input_mut().events.push(Event::Key { key: Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
let d = h.state().gradient_draft();
|
||||
assert_eq!(d.selected, Some((Track::Opacity, first)), "the moved stop stays selected");
|
||||
assert_eq!(d.index_of(Track::Opacity, first), Some(1), "it is now after the stop at 0.5");
|
||||
// The frame that moved it: Opacity already shows this stop's 100%, never the neighbour's 70%
|
||||
// that is now at its old index. (Location itself was drawn before the move: 0 until the next.)
|
||||
let shown = shown_numbers(&h);
|
||||
assert!(shown.contains(&100.0), "this stop's 100%: {shown:?}");
|
||||
assert!(!shown.iter().any(|v| (v - 70.0).abs() < 1.0), "never the neighbour's 70%: {shown:?}");
|
||||
h.run_steps(2);
|
||||
let shown = shown_numbers(&h);
|
||||
assert!(shown.contains(&80.0) && shown.contains(&100.0), "Location 80 and Opacity 100%: {shown:?}");
|
||||
assert!(!shown.iter().any(|v| (v - 70.0).abs() < 1.0), "{shown:?}");
|
||||
}
|
||||
|
||||
/// A layer deleted while the editor is open: OK reports it, without a crash.
|
||||
#[test]
|
||||
fn a_layer_deleted_while_editing_is_reported() {
|
||||
let (mut h, l, colors) = setup(&[]);
|
||||
open_editor(&mut h, colors);
|
||||
let p = along(&h, "dialog.gradient.addColor", 0.5);
|
||||
click_at(&mut h, p);
|
||||
h.state_mut().session.execute("edit.clear", json!({"layers": [l]})).unwrap();
|
||||
h.run_steps(2);
|
||||
click(&mut h, "dialog.gradient.ok");
|
||||
assert_eq!(h.state().dialog, None);
|
||||
assert!(!h.state().ui.status.is_empty(), "the failed set is reported");
|
||||
}
|
||||
|
||||
/// `prop.editGradient` by id (agents, MCP, the control channel) is an error for a target that
|
||||
/// isn't a gradient property, from the engine and through the UI, and opens nothing.
|
||||
#[test]
|
||||
fn edit_gradient_by_id_rejects_bad_targets() {
|
||||
let (mut h, l, colors) = setup(&[]);
|
||||
let ctx = h.ctx.clone();
|
||||
let opacity = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().props.prop("transform/opacity").unwrap().uid;
|
||||
for (p, err) in [(json!({"layer": 9999, "prop": colors}), "no layer"), (json!({"layer": l, "prop": opacity}), "not a gradient")] {
|
||||
let e = h.state_mut().session.execute_checked("prop.editGradient", p.clone()).expect_err("the engine refuses it");
|
||||
assert!(e.to_string().contains(err), "{p}: {e}");
|
||||
let e = effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "prop.editGradient", p.clone()).expect_err("so does the UI");
|
||||
assert!(e.contains(err), "{p}: {e}");
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, None, "{p}");
|
||||
}
|
||||
let r = effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "prop.editGradient", json!({"layer": l, "prop": colors}));
|
||||
assert!(r.is_ok(), "{r:?}");
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, Some(Dialog::GradientEditor));
|
||||
}
|
||||
|
||||
/// In the editor, the colour picker's Escape and Cancel go back to the stop's colour and close only
|
||||
/// the picker: the editor and its other edits stay (dialogs leave Escape to an open picker).
|
||||
#[test]
|
||||
fn picker_escape_and_cancel_restore_the_stop_and_keep_the_editor() {
|
||||
let (mut h, _, colors) = setup(&[]);
|
||||
open_editor(&mut h, colors);
|
||||
let added = along(&h, "dialog.gradient.addOpacity", 0.3);
|
||||
click_at(&mut h, added);
|
||||
click(&mut h, "dialog.gradient.colorStop.0");
|
||||
let id = h.state().gradient_draft().selected.expect("a selected stop").1;
|
||||
let original = stop_color(&h, id);
|
||||
for how in ["escape", "cancel"] {
|
||||
click(&mut h, "dialog.gradient.color");
|
||||
assert!(picker_open(&h), "{how}: the picker opened");
|
||||
type_hex(&mut h, "ff8000");
|
||||
assert!(near(stop_color(&h, id), [1.0, 128.0 / 255.0, 0.0, original[3]]), "{how}: the picker previews as it goes");
|
||||
if how == "escape" {
|
||||
key(&mut h, Key::Escape);
|
||||
} else {
|
||||
// The picker's Cancel, not the editor's.
|
||||
let editor_cancel = rect(&h, "dialog.gradient.cancel");
|
||||
let cancel =
|
||||
h.query_all_by_label("Cancel").map(|n| n.rect()).find(|r| (r.min.x - editor_cancel[0]).abs() > 1.0 || (r.min.y - editor_cancel[1]).abs() > 1.0);
|
||||
click_at(&mut h, cancel.expect("the picker's Cancel").center());
|
||||
}
|
||||
assert!(!picker_open(&h), "{how}: the picker closed");
|
||||
assert_eq!(h.state().dialog, Some(Dialog::GradientEditor), "{how}: the editor stays open");
|
||||
assert_eq!(stop_color(&h, id), original, "{how}: the stop's colour is back");
|
||||
assert_eq!(h.state().gradient_draft().opacities.len(), 3, "{how}: the editor's other edits stay");
|
||||
}
|
||||
}
|
||||
|
||||
/// The Escape that closes the picker is its own: the next Escape, even in the very next pass,
|
||||
/// cancels the editor (a closed picker doesn't keep the dialog from it).
|
||||
#[test]
|
||||
fn the_escape_after_the_picker_closes_cancels_the_editor() {
|
||||
let (mut h, _, colors) = setup(&[]);
|
||||
let project = h.state().session.project.clone();
|
||||
open_editor(&mut h, colors);
|
||||
click(&mut h, "dialog.gradient.colorStop.0");
|
||||
click(&mut h, "dialog.gradient.color");
|
||||
assert!(picker_open(&h), "the picker opened");
|
||||
let escape = |h: &mut Harness<'_, EffectcraftApp>| {
|
||||
h.input_mut().events.push(Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.input_mut().events.push(Event::Key { key: Key::Escape, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
};
|
||||
escape(&mut h);
|
||||
assert_eq!(h.state().dialog, Some(Dialog::GradientEditor), "the first Escape closed only the picker");
|
||||
escape(&mut h);
|
||||
assert_eq!(h.state().dialog, None, "the next pass's Escape cancels the editor");
|
||||
assert_eq!(h.state().session.project, project, "and changes nothing");
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
//! #612: a gradient property's "Edit Gradient…" in the Timeline opens an editor. Before the fix
|
||||
//! the value only painted its label: no automation id, nothing to click. This test uses only APIs
|
||||
//! that existed before the Gradient Editor, so it runs (and fails) on the code without it; the
|
||||
//! editor itself is tested in `ui_gradient_editor`.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::project::{LayerId, PropGroup};
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use egui::{Event, Modifiers, PointerButton, pos2};
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
|
||||
/// The uids from the layer's root down to the Gradient Fill group, and its Colors property.
|
||||
fn gradient_fill(g: &PropGroup) -> Option<(Vec<u64>, u64)> {
|
||||
for x in g.groups() {
|
||||
if x.match_id == "gfill" {
|
||||
return Some((vec![x.uid], x.get("colors")?.uid));
|
||||
}
|
||||
if let Some((mut path, colors)) = gradient_fill(x) {
|
||||
path.insert(0, x.uid);
|
||||
return Some((path, colors));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_timeline_gradient_value_opens_an_editor() {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "duration": 4})).unwrap();
|
||||
let l = s.execute("layer.newShape", json!({"kind": "rect"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.addShapeItem", json!({"layer": l, "kind": "gfill"})).unwrap();
|
||||
let (groups, colors) = gradient_fill(&s.active_comp().unwrap().layer(LayerId(l)).unwrap().props).expect("a Gradient Fill");
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.state_mut().ui.timeline.open_layers.insert(l);
|
||||
h.state_mut().ui.timeline.open_groups.extend(groups);
|
||||
h.run_steps(3);
|
||||
assert!(h.state().dialog.is_none());
|
||||
let id = format!("timeline.prop.{colors}.value");
|
||||
let r = h.state().auto.find(&id).unwrap_or_else(|| panic!("no automation id {id}: the Timeline's Edit Gradient… isn't clickable")).rect;
|
||||
let p = pos2(r[0] + r[2] / 2.0, r[1] + r[3] / 2.0);
|
||||
h.input_mut().events.push(Event::PointerMoved(p));
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(4);
|
||||
assert!(h.state().dialog.is_some(), "clicking Edit Gradient… opens an editor");
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
//! registers its automation ids; the Footage panel's buttons edit into the comp; the Progress
|
||||
//! panel lists and cancels a job; Lumetri Scopes switch scope through their dropdown.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use std::sync::Arc;
|
||||
|
||||
use effectcraft_engine::{Session, config::MemoryConfig};
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use effectcraft_ui_egui::dock::PanelKind;
|
||||
use egui::{Event, Pos2, pos2};
|
||||
@@ -237,46 +239,147 @@ fn leaving_the_learn_workspace_closes_its_tutorials() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #284: Settings ▸ Appearance ▸ UI Scale sizes the whole interface as soon as it is chosen,
|
||||
/// Cancel puts it back, OK keeps it; Ctrl+0 (Window ▸ Project) doesn't reset it.
|
||||
fn open_settings(h: &mut Harness<'_, EffectcraftApp>) {
|
||||
let ctx = h.ctx.clone();
|
||||
effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "app.settings", json!({"page": "appearance"})).unwrap();
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn key(h: &mut Harness<'_, EffectcraftApp>, key: egui::Key, modifiers: egui::Modifiers) {
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::Key { key, physical_key: None, pressed, repeat: false, modifiers });
|
||||
h.step();
|
||||
}
|
||||
}
|
||||
|
||||
/// The UI Scale setting and the zoom it gives.
|
||||
fn scale(h: &Harness<'_, EffectcraftApp>) -> (u32, f32) {
|
||||
(h.state().session.prefs.appearance.ui_scale, h.ctx.zoom_factor())
|
||||
}
|
||||
|
||||
/// Types `text` into Settings' UI Scale a key at a time: nothing applies (and the field keeps
|
||||
/// the keyboard) until Enter.
|
||||
fn type_scale(h: &mut Harness<'_, EffectcraftApp>, text: &str) {
|
||||
let before = scale(h);
|
||||
click(h, "settings.appearance.uiScale");
|
||||
for c in text.chars() {
|
||||
h.input_mut().events.push(Event::Text(c.to_string()));
|
||||
h.run_steps(2);
|
||||
assert_eq!(scale(h), before, "{text}: not while typing");
|
||||
assert!(h.ctx.memory(|m| m.focused().is_some()), "{text}: the field keeps the keyboard");
|
||||
}
|
||||
key(h, egui::Key::Enter, egui::Modifiers::NONE);
|
||||
// (Settings re-centres a frame after the zoom changes.)
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// #284, #682: Settings ▸ Appearance ▸ UI Scale takes any typed percentage from 75 to 200 and
|
||||
/// sizes the whole interface once it is entered, Cancel puts it back, OK keeps it and later
|
||||
/// sessions start with it; Ctrl+0 (Window ▸ Project) doesn't reset it.
|
||||
#[test]
|
||||
fn ui_scale_setting_sizes_the_interface() {
|
||||
let mut h = harness();
|
||||
let ctx = h.ctx.clone();
|
||||
let choose = |h: &mut Harness<'_, EffectcraftApp>, label: &str| {
|
||||
let ctx = h.ctx.clone();
|
||||
effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "app.settings", json!({"page": "appearance"})).unwrap();
|
||||
h.run_steps(3);
|
||||
click(h, "settings.appearance.uiScale");
|
||||
let option = h.query_by_label(label).unwrap_or_else(|| panic!("the {label} choice")).rect().center();
|
||||
click_at(h, option);
|
||||
h.run_steps(2);
|
||||
};
|
||||
assert_eq!(ctx.zoom_factor(), 1.0);
|
||||
choose(&mut h, "150%");
|
||||
assert_eq!(h.state().session.prefs.appearance.ui_scale, 150);
|
||||
assert_eq!(ctx.zoom_factor(), 1.5, "live");
|
||||
open_settings(&mut h);
|
||||
type_scale(&mut h, "85");
|
||||
assert_eq!(scale(&h), (85, 0.85), "live");
|
||||
click(&mut h, "settings.cancel");
|
||||
h.run_steps(2);
|
||||
assert_eq!((h.state().session.prefs.appearance.ui_scale, ctx.zoom_factor()), (100, 1.0), "Cancel put it back");
|
||||
choose(&mut h, "125%");
|
||||
assert_eq!(scale(&h), (100, 1.0), "Cancel put it back");
|
||||
open_settings(&mut h);
|
||||
type_scale(&mut h, "300");
|
||||
assert_eq!(scale(&h), (200, 2.0), "at most 200");
|
||||
click(&mut h, "settings.cancel");
|
||||
h.run_steps(2);
|
||||
assert_eq!(scale(&h), (100, 1.0), "Cancel put it back from 200 %");
|
||||
open_settings(&mut h);
|
||||
type_scale(&mut h, "50");
|
||||
assert_eq!(scale(&h), (75, 0.75), "at least 75");
|
||||
type_scale(&mut h, "90");
|
||||
click(&mut h, "settings.ok");
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, None);
|
||||
assert_eq!((h.state().session.prefs.appearance.ui_scale, ctx.zoom_factor()), (125, 1.25), "OK kept it");
|
||||
assert_eq!(scale(&h), (90, 0.9), "OK kept it");
|
||||
// Ctrl+0 opens the Project panel; egui's own Ctrl+0 zoom reset stays out of it.
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::Key { key: egui::Key::Num0, physical_key: None, pressed, repeat: false, modifiers: egui::Modifiers::COMMAND });
|
||||
h.step();
|
||||
}
|
||||
key(&mut h, egui::Key::Num0, egui::Modifiers::COMMAND);
|
||||
h.run_steps(2);
|
||||
assert_eq!(ctx.zoom_factor(), 1.25);
|
||||
assert_eq!(ctx.zoom_factor(), 0.9);
|
||||
// A saved scale applies from the first frame.
|
||||
let mut s = Session::default();
|
||||
s.prefs.set("appearance.uiScale", json!(175)).unwrap();
|
||||
let s = Session { prefs: effectcraft_engine::prefs::Prefs::from_json(&h.state().session.prefs.to_json()), ..Default::default() };
|
||||
let mut h2 = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h2.run_steps(3);
|
||||
assert_eq!(h2.ctx.zoom_factor(), 1.75);
|
||||
assert_eq!(h2.ctx.zoom_factor(), 0.9);
|
||||
}
|
||||
|
||||
/// Settings' Previous / Next / Cancel / OK stay whole and in view at 200 % in a 1600×1000
|
||||
/// window (they scrolled out of the dialog with its pages): the page scrolls under them, Cancel
|
||||
/// restores the settings and OK saves them.
|
||||
#[test]
|
||||
fn settings_buttons_stay_in_view_at_200_percent() {
|
||||
let store = Arc::new(MemoryConfig::default());
|
||||
let saved = || {
|
||||
let mut s = Session { config: Some(store.clone()), ..Default::default() };
|
||||
s.prefs.disk.disk_cache_enabled = false;
|
||||
s.load_settings();
|
||||
s.prefs.appearance.ui_scale
|
||||
};
|
||||
let mut s = Session { config: Some(store.clone()), ..Default::default() };
|
||||
s.prefs.disk.disk_cache_enabled = false;
|
||||
s.prefs.set("appearance.uiScale", json!(200)).unwrap();
|
||||
s.save_prefs();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
assert_eq!(scale(&h), (200, 2.0));
|
||||
let rect = |h: &Harness<'_, EffectcraftApp>, id: &str| {
|
||||
let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}"));
|
||||
egui::Rect::from_min_size(pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3]))
|
||||
};
|
||||
// Whole: inside the window, and painted with none of them clipped away.
|
||||
let buttons = |h: &Harness<'_, EffectcraftApp>| {
|
||||
["previous", "next", "cancel", "ok"].map(|b| {
|
||||
let r = rect(h, &format!("settings.{b}"));
|
||||
let clip = h
|
||||
.output()
|
||||
.shapes
|
||||
.iter()
|
||||
.find(|c| matches!(&c.shape, egui::Shape::Rect(s) if (s.rect.center() - r.center()).length() < 0.5))
|
||||
.map(|c| c.clip_rect);
|
||||
assert!(h.ctx.content_rect().contains_rect(r) && clip.is_some_and(|c| c.contains_rect(r)), "{b} is cut off: {r:?} in {clip:?}");
|
||||
r
|
||||
})
|
||||
};
|
||||
let scroll_page = |h: &mut Harness<'_, EffectcraftApp>| {
|
||||
let at = rect(h, "settings.appearance.appearanceMode").center();
|
||||
h.input_mut().events.push(Event::PointerMoved(at));
|
||||
h.input_mut().events.push(Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(0.0, -1000.0),
|
||||
modifiers: Default::default(),
|
||||
phase: egui::TouchPhase::Move,
|
||||
});
|
||||
h.run_steps(5);
|
||||
};
|
||||
open_settings(&mut h);
|
||||
let footer = buttons(&h);
|
||||
let field = rect(&h, "settings.appearance.uiScale");
|
||||
scroll_page(&mut h);
|
||||
assert_eq!(buttons(&h), footer, "the buttons don't scroll with the page");
|
||||
let scrolled = rect(&h, "settings.appearance.uiScale");
|
||||
assert!(scrolled.top() < field.top() && scrolled.bottom() < footer[2].top(), "the page scrolled to UI Scale: {field:?} -> {scrolled:?}");
|
||||
for (button, kept) in [("settings.cancel", 200), ("settings.ok", 150)] {
|
||||
if h.state().dialog.is_none() {
|
||||
open_settings(&mut h);
|
||||
scroll_page(&mut h);
|
||||
}
|
||||
type_scale(&mut h, "150");
|
||||
assert_eq!(scale(&h), (150, 1.5));
|
||||
buttons(&h);
|
||||
click(&mut h, button);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, None, "{button} closed Settings");
|
||||
assert_eq!((scale(&h), saved()), ((kept, kept as f32 / 100.0), kept), "{button}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Headless look at the panels (wgpu offscreen; needs a GPU adapter). Run with
|
||||
@@ -362,3 +465,31 @@ fn essential_graphics_scale_keeps_constrain_proportions() {
|
||||
let unlinked = scale(&h);
|
||||
assert!(unlinked[0] > linked[0] && unlinked[1] == linked[1], "unlinked, X moves alone: {unlinked:?}");
|
||||
}
|
||||
|
||||
/// #757: Effects & Presets lists the built-in Transitions presets under * Animation Presets;
|
||||
/// double-clicking one applies it to the selected layer (effect plus keyframes).
|
||||
#[test]
|
||||
fn transition_presets_apply_from_effects_and_presets() {
|
||||
let mut h = harness();
|
||||
let layer = h.state().session.active_comp().unwrap().layers[0].id.0;
|
||||
h.state_mut().session.execute("layer.select", json!({"layers": [layer]})).unwrap();
|
||||
open(&mut h, "effectsPresets");
|
||||
h.state_mut().ui.effects_search = "clock reveal".into();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().auto.find("effects.category.presets/Transitions").is_some(), "the Transitions folder is listed");
|
||||
let e = h.state().auto.find("effects.preset.builtin.clockReveal").expect("Clock Reveal is listed").clone();
|
||||
let p: Pos2 = pos2(e.rect[0] + e.rect[2] / 2.0, e.rect[1] + e.rect[3] / 2.0);
|
||||
h.input_mut().events.push(Event::PointerMoved(p));
|
||||
h.step();
|
||||
// Both clicks in one frame: the harness' frame time is longer than a double-click's.
|
||||
for _ in 0..2 {
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() });
|
||||
}
|
||||
}
|
||||
h.run_steps(3);
|
||||
let comp = h.state().session.active_comp().unwrap();
|
||||
let fx = comp.layers[0].effects().unwrap().groups().next().expect("an effect was added").clone();
|
||||
assert_eq!(fx.name, "Radial Wipe");
|
||||
assert_eq!(fx.prop("completion").unwrap().keys.len(), 2);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
//! Project panel keyboard navigation and accessibility (#776): the arrow keys move and extend the
|
||||
//! selection and open / close folders, as in After Effects; the rows, sort headers and row buttons
|
||||
//! reach screen readers with names, roles and states; a row focused with Tab keeps the arrows, and
|
||||
//! keyboard focus follows the selection.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::project::{ItemId, ItemKind};
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use effectcraft_ui_egui::dock::PanelKind;
|
||||
use egui::accesskit::Role;
|
||||
use egui::{Event, Key, Modifiers, Pos2, pos2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
/// A closed folder holding a comp, and a solid at the project root: (harness, folder, comp, solid).
|
||||
fn harness() -> (Harness<'static, EffectcraftApp>, ItemId, ItemId, ItemId) {
|
||||
let mut s = Session::default();
|
||||
let comp = ItemId(s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "duration": 4})).unwrap()["comp"].as_u64().unwrap());
|
||||
s.execute("layer.newSolid", json!({"name": "Solid", "color": "#406080"})).unwrap();
|
||||
let solid = s.project.items.values().find(|i| matches!(i.kind, ItemKind::Solid(_))).unwrap().id;
|
||||
let folder = ItemId(s.execute("project.newFolder", json!({"name": "Folder"})).unwrap()["item"].as_u64().unwrap());
|
||||
s.execute("project.move", json!({"items": [comp.0], "folder": folder.0})).unwrap();
|
||||
s.execute("project.move", json!({"items": [solid.0], "folder": null})).unwrap();
|
||||
s.execute("project.select", json!({"items": []})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
(h, folder, comp, solid)
|
||||
}
|
||||
|
||||
fn center(h: &Harness<'_, EffectcraftApp>, id: &str) -> Pos2 {
|
||||
let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}")).clone();
|
||||
pos2(e.rect[0] + e.rect[2] / 2.0, e.rect[1] + e.rect[3] / 2.0)
|
||||
}
|
||||
|
||||
fn click(h: &mut Harness<'_, EffectcraftApp>, id: &str) {
|
||||
let p = center(h, id);
|
||||
h.input_mut().events.push(Event::PointerMoved(p));
|
||||
h.step();
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// Press and release `key` with `modifiers` (one frame each), then let the UI settle.
|
||||
fn key(h: &mut Harness<'_, EffectcraftApp>, key: Key, modifiers: Modifiers) {
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::Key { key, physical_key: None, pressed, repeat: false, modifiers });
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
/// The item rows on screen, top to bottom.
|
||||
fn rows(h: &Harness<'_, EffectcraftApp>) -> Vec<ItemId> {
|
||||
let mut rows: Vec<(f32, ItemId)> = h
|
||||
.state()
|
||||
.auto
|
||||
.query("project.item.")
|
||||
.into_iter()
|
||||
.filter_map(|e| e.id.strip_prefix("project.item.").and_then(|n| n.parse().ok()).map(|n| (e.rect[1], ItemId(n))))
|
||||
.collect();
|
||||
rows.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
rows.into_iter().map(|(_, id)| id).collect()
|
||||
}
|
||||
|
||||
fn selection(h: &Harness<'_, EffectcraftApp>) -> Vec<ItemId> {
|
||||
h.state().session.state.project_selection.clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrow_keys_move_and_extend_the_project_selection() {
|
||||
let (mut h, _, _, _) = harness();
|
||||
let rows = rows(&h);
|
||||
assert!(rows.len() >= 2, "rows: {rows:?}");
|
||||
let (first, second) = (rows[0], rows[1]);
|
||||
click(&mut h, &format!("project.item.{}.name", first.0));
|
||||
assert_eq!(h.state().ui.focused, PanelKind::Project);
|
||||
assert_eq!(selection(&h), vec![first]);
|
||||
key(&mut h, Key::ArrowDown, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![second], "Down Arrow selects the next item");
|
||||
key(&mut h, Key::ArrowUp, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![first], "Up Arrow selects the previous item");
|
||||
key(&mut h, Key::ArrowUp, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![first], "the first item stays selected at the top");
|
||||
for _ in 0..rows.len() + 1 {
|
||||
key(&mut h, Key::ArrowDown, Modifiers::SHIFT);
|
||||
}
|
||||
assert_eq!(selection(&h), rows, "Shift+Down Arrow extends the selection to the last item");
|
||||
key(&mut h, Key::ArrowUp, Modifiers::SHIFT);
|
||||
assert_eq!(selection(&h), rows[..rows.len() - 1], "Shift+Up Arrow shrinks it back toward the anchor");
|
||||
key(&mut h, Key::ArrowDown, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![rows[rows.len() - 1]], "a plain arrow selects one item again");
|
||||
// With nothing selected, Down selects the first item and Up the last.
|
||||
h.state_mut().session.state.project_selection.clear();
|
||||
key(&mut h, Key::ArrowDown, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![first]);
|
||||
h.state_mut().session.state.project_selection.clear();
|
||||
key(&mut h, Key::ArrowUp, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![rows[rows.len() - 1]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_and_left_arrows_open_and_close_the_selected_folder() {
|
||||
let (mut h, folder, comp, _) = harness();
|
||||
click(&mut h, &format!("project.item.{}.name", folder.0));
|
||||
assert!(!rows(&h).contains(&comp), "the folder starts closed");
|
||||
key(&mut h, Key::ArrowRight, Modifiers::NONE);
|
||||
assert!(h.state().ui.project_open_folders.contains(&folder.0), "Right Arrow opens the selected folder");
|
||||
assert!(rows(&h).contains(&comp));
|
||||
key(&mut h, Key::ArrowDown, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![comp], "Down Arrow walks into the open folder");
|
||||
key(&mut h, Key::ArrowLeft, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![folder], "Left Arrow on an item in a folder selects the folder");
|
||||
key(&mut h, Key::ArrowLeft, Modifiers::NONE);
|
||||
assert!(!h.state().ui.project_open_folders.contains(&folder.0), "Left Arrow closes the selected folder");
|
||||
assert_eq!(selection(&h), vec![folder]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrows_leave_the_project_selection_alone_when_another_panel_has_focus() {
|
||||
let (mut h, folder, _, _) = harness();
|
||||
click(&mut h, &format!("project.item.{}.name", folder.0));
|
||||
h.state_mut().ui.focused = PanelKind::Timeline;
|
||||
key(&mut h, Key::ArrowDown, Modifiers::NONE);
|
||||
key(&mut h, Key::ArrowRight, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![folder]);
|
||||
assert!(!h.state().ui.project_open_folders.contains(&folder.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_and_headers_have_accessible_names_roles_and_states() {
|
||||
let (mut h, folder, _, _) = harness();
|
||||
click(&mut h, &format!("project.item.{}.name", folder.0));
|
||||
let row = h.get_by_label("Folder, Folder");
|
||||
let node = row.accesskit_node();
|
||||
assert_eq!(node.role(), Role::TreeItem);
|
||||
assert_eq!(node.is_selected(), Some(true), "the selected row says so");
|
||||
assert_eq!(node.data().is_expanded(), Some(false), "a closed folder says so");
|
||||
assert_eq!(node.data().level(), Some(1));
|
||||
let solid = h.get_by_label("Solid, Solid");
|
||||
assert_eq!(solid.accesskit_node().is_selected(), Some(false));
|
||||
assert_eq!(solid.accesskit_node().data().is_expanded(), None, "only folders open");
|
||||
assert_eq!(h.get_by_label("Sort by Name, ascending").accesskit_node().role(), Role::Button);
|
||||
assert_eq!(h.get_by_label("Open folder Folder").accesskit_node().role(), Role::Button);
|
||||
assert_eq!(h.get_by_label("Delete selected project items").accesskit_node().role(), Role::Button);
|
||||
assert!(h.query_by_label_contains("Label of Folder: ").is_some(), "the label swatch is named");
|
||||
assert!(h.query_by_label("Create a new Folder").is_some());
|
||||
key(&mut h, Key::ArrowRight, Modifiers::NONE);
|
||||
assert_eq!(h.get_by_label("Folder, Folder").accesskit_node().data().is_expanded(), Some(true));
|
||||
assert_eq!(h.get_by_label("Main, Composition").accesskit_node().data().level(), Some(2), "the comp sits one level down");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_focused_row_keeps_the_arrows_and_focus_follows_the_selection() {
|
||||
let (mut h, _, _, _) = harness();
|
||||
let rows = rows(&h);
|
||||
let names: Vec<String> = rows
|
||||
.iter()
|
||||
.map(|id| {
|
||||
let it = h.state().session.project.item(*id).unwrap();
|
||||
format!("{}, {}", it.name, it.type_name())
|
||||
})
|
||||
.collect();
|
||||
// Focus the first row the way a screen reader (or Tab) does, without a click: the panel
|
||||
// takes focus with it.
|
||||
h.state_mut().ui.focused = PanelKind::Timeline;
|
||||
h.get_by_label(&names[0]).focus();
|
||||
h.run_steps(3);
|
||||
assert!(h.get_by_label(&names[0]).is_focused());
|
||||
assert_eq!(h.state().ui.focused, PanelKind::Project, "keyboard focus on a row focuses the panel");
|
||||
// A plain arrow moved egui's focus to the widget below; here it moves the selection and the
|
||||
// focus with it.
|
||||
key(&mut h, Key::ArrowDown, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![rows[0]], "nothing was selected: Down selects the first item");
|
||||
key(&mut h, Key::ArrowDown, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![rows[1]]);
|
||||
assert!(h.get_by_label(&names[1]).is_focused(), "keyboard focus follows the selection");
|
||||
key(&mut h, Key::ArrowUp, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![rows[0]]);
|
||||
assert!(h.get_by_label(&names[0]).is_focused());
|
||||
}
|
||||
|
||||
/// A mouse click on a row gives no keyboard focus to the row, so the app's shortcuts run as
|
||||
/// before the arrow keys came: Delete / Backspace delete, Cmd+D duplicates, Enter renames, also
|
||||
/// after an arrow key moved the selection.
|
||||
#[test]
|
||||
fn shortcuts_still_run_after_a_mouse_click_and_the_arrows() {
|
||||
let focus = |h: &Harness<'_, EffectcraftApp>| h.ctx.memory(|m| m.focused());
|
||||
for delete_key in [Key::Delete, Key::Backspace] {
|
||||
let (mut h, folder, _, _) = harness();
|
||||
let empty = ItemId(h.state_mut().session.execute("project.newFolder", json!({"name": "Empty"})).unwrap()["item"].as_u64().unwrap());
|
||||
h.run_steps(2);
|
||||
click(&mut h, &format!("project.item.{}.name", empty.0));
|
||||
assert_eq!(selection(&h), vec![empty]);
|
||||
assert_eq!(focus(&h), None, "a click gives the row no keyboard focus");
|
||||
key(&mut h, delete_key, Modifiers::NONE);
|
||||
assert!(h.state().session.project.item(empty).is_none(), "{delete_key:?} deletes the clicked item");
|
||||
// Click, an arrow, then the shortcut.
|
||||
let empty2 = ItemId(h.state_mut().session.execute("project.newFolder", json!({"name": "Empty 2"})).unwrap()["item"].as_u64().unwrap());
|
||||
h.run_steps(2);
|
||||
let rows = rows(&h);
|
||||
let at = rows.iter().position(|r| *r == empty2).unwrap();
|
||||
let from = if at > 0 { rows[at - 1] } else { rows[at + 1] };
|
||||
click(&mut h, &format!("project.item.{}.name", from.0));
|
||||
key(&mut h, if at > 0 { Key::ArrowDown } else { Key::ArrowUp }, Modifiers::NONE);
|
||||
assert_eq!(selection(&h), vec![empty2]);
|
||||
assert_eq!(focus(&h), None, "the arrows don't take keyboard focus after a click");
|
||||
key(&mut h, delete_key, Modifiers::NONE);
|
||||
assert!(h.state().session.project.item(empty2).is_none(), "{delete_key:?} deletes the item the arrow moved to");
|
||||
assert!(h.state().session.project.item(folder).is_some());
|
||||
}
|
||||
let (mut h, folder, _, solid) = harness();
|
||||
// Folders can't be duplicated (engine rule): duplicate the solid.
|
||||
click(&mut h, &format!("project.item.{}.name", solid.0));
|
||||
let n = h.state().session.project.items.len();
|
||||
key(&mut h, Key::D, Modifiers::COMMAND);
|
||||
assert_eq!(h.state().session.project.items.len(), n + 1, "Cmd+D duplicates the clicked item");
|
||||
click(&mut h, &format!("project.item.{}.name", folder.0));
|
||||
key(&mut h, Key::Enter, Modifiers::NONE);
|
||||
assert!(h.state().auto.find(&format!("project.item.{}.nameEdit", folder.0)).is_some(), "Enter renames the clicked item");
|
||||
}
|
||||
@@ -127,16 +127,21 @@ fn footage_context_menu_interprets_the_footage() {
|
||||
}
|
||||
h.run_steps(2);
|
||||
};
|
||||
// The menu's Interpret Footage entry, not the panel's footer button of the same name.
|
||||
let menu_entry = |h: &Harness<'_, EffectcraftApp>| {
|
||||
let footer = center(h, "project.interpret");
|
||||
h.query_all_by_label_contains("Interpret Footage").find(|n| !n.rect().contains(footer)).map(|n| n.rect())
|
||||
};
|
||||
let at = center(&h, &format!("project.item.{}.name", solid.0));
|
||||
right_click(&mut h, at);
|
||||
assert_eq!(h.state().session.state.project_selection, vec![solid]);
|
||||
assert!(h.query_by_label_contains("Interpret Footage").is_none(), "a solid isn't footage");
|
||||
assert!(menu_entry(&h).is_none(), "a solid isn't footage");
|
||||
h.input_mut().events.push(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
let at = center(&h, &format!("project.item.{}.name", clip.0));
|
||||
right_click(&mut h, at);
|
||||
assert_eq!(h.state().session.state.project_selection, vec![clip], "right-click selects the item");
|
||||
let sub = h.query_by_label_contains("Interpret Footage").expect("Interpret Footage in the menu").rect();
|
||||
let sub = menu_entry(&h).expect("Interpret Footage in the menu");
|
||||
h.input_mut().events.push(Event::PointerMoved(sub.center()));
|
||||
h.run_steps(3);
|
||||
let main = h.query_by_label_contains("Main...").expect("Interpret Footage ▸ Main...").rect();
|
||||
|
||||
@@ -47,11 +47,15 @@ fn check_info_transaction(via_escape: bool) {
|
||||
let edited_brightness = h.state().session.prefs.appearance.brightness;
|
||||
assert!((edited_brightness - original_brightness).abs() > 0.01, "real brightness slider changed");
|
||||
assert_eq!(saved(&store).prefs.appearance.brightness, original_brightness, "unconfirmed edit is not saved");
|
||||
// Use the upstream percent-valued Scale choice; keyboard zoom is deliberately disabled.
|
||||
// Type a UI Scale; keyboard zoom is deliberately disabled.
|
||||
let at = rect(&h, "settings.appearance.uiScale").center();
|
||||
click(&mut h, at);
|
||||
let at = h.get_by_label("125%").rect().center();
|
||||
click(&mut h, at);
|
||||
h.event(Event::Text("125".into()));
|
||||
for pressed in [true, false] {
|
||||
h.event(Event::Key { key: Key::Enter, physical_key: Some(Key::Enter), pressed, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().session.prefs.appearance.ui_scale, 125);
|
||||
assert_eq!(saved(&store).prefs.appearance.ui_scale, 100, "unconfirmed scale edit is not saved");
|
||||
// Let UI Scale settle the centered dialog before reading its next hit target.
|
||||
@@ -111,3 +115,22 @@ fn gpu_information_ok_returns_to_settings_and_cancel_restores_preferences() {
|
||||
fn gpu_information_escape_returns_to_settings_and_ok_saves_preferences() {
|
||||
check_info_transaction(true);
|
||||
}
|
||||
|
||||
/// GPU Information names the adapter the window got and says why the compositor is off, so a
|
||||
/// card that the compositor could not use does not look undetected (#596).
|
||||
#[test]
|
||||
fn gpu_information_names_the_adapter_and_why_the_gpu_is_off() {
|
||||
let session = Session {
|
||||
accel_note: Some("GPU compositor unavailable: no compute shaders".into()),
|
||||
window_adapter: Some("NVIDIA GeForce RTX 4070 (Dx12, DiscreteGpu)".into()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session));
|
||||
h.run_steps(4);
|
||||
let ctx = h.ctx.clone();
|
||||
menus::invoke(h.state_mut(), &ctx, "app.gpuInfo", json!({})).unwrap();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().dialog, Some(Dialog::Info));
|
||||
assert!(h.query_by_label_contains("Window graphics: NVIDIA GeForce RTX 4070").is_some(), "the window's adapter is shown");
|
||||
assert!(h.query_by_label_contains("GPU compositing is off: GPU compositor unavailable").is_some(), "the reason is shown");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Timeline rows for shape layers, masks and keyframing: the Contents "Add:" menu and the Classic
|
||||
//! 3D "Change Renderer…" row (#206), Alt+Shift+P revealing the key it adds and clicks below the
|
||||
//! layers deselecting them (#205), Mask Feather's linked values (#203), and copying shape items
|
||||
//! between shape layers (#227).
|
||||
//! between shape layers (#227), and Ctrl+V of SVG markup making a shape layer (#738).
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::project::LayerId;
|
||||
@@ -243,3 +243,31 @@ fn timeline_colour_eyedropper_samples_the_comp() {
|
||||
assert!((c[k] - want[k]).abs() < 0.02, "{c:?} vs {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Ctrl+V with SVG markup on the system clipboard pastes it as a shape layer (After Effects
|
||||
/// 26.3), even with layers on the app's clipboard: copying in the app replaces the system
|
||||
/// clipboard, so the SVG was copied later (#738).
|
||||
#[test]
|
||||
fn ctrl_v_pastes_svg_markup_as_a_shape_layer() {
|
||||
let (mut h, a, b, _) = two_shape_layers();
|
||||
click(&mut h, &format!("timeline.layer.{b}.row"));
|
||||
h.input_mut().events.push(Event::Copy);
|
||||
h.step();
|
||||
assert_eq!(h.state().session.state.clipboard.len(), 1, "a layer on the app's clipboard");
|
||||
let svg = r##"<svg xmlns="http://www.w3.org/2000/svg" width="40" height="20"><circle cx="10" cy="10" r="8" fill="#00ff00"/><rect x="20" width="20" height="20"/></svg>"##;
|
||||
h.input_mut().events.push(Event::Paste(svg.into()));
|
||||
h.run_steps(3);
|
||||
let c = h.state().session.active_comp().unwrap().clone();
|
||||
assert_eq!(c.layers.len(), 3, "{:?}", h.state().ui.status);
|
||||
let top = &c.layers[0];
|
||||
assert!(top.id != LayerId(a) && top.id != LayerId(b));
|
||||
assert_eq!(top.name, "Shape Layer 3");
|
||||
assert_eq!(top.props.sub("contents").unwrap().groups().count(), 2);
|
||||
assert_eq!(h.state().session.state.selected_layers, vec![top.id]);
|
||||
// The app's own clipboard note pastes the copied layer as before.
|
||||
h.input_mut().events.push(Event::Paste("EffectCraft: 1 layer".into()));
|
||||
h.run_steps(3);
|
||||
let c = h.state().session.active_comp().unwrap();
|
||||
assert_eq!(c.layers.len(), 4);
|
||||
assert_eq!(c.layers[0].name, "Oval 2");
|
||||
}
|
||||
|
||||
@@ -601,6 +601,32 @@ fn fill_options_paint_the_next_shape() {
|
||||
assert_eq!(gfill.get("opacity").unwrap().value.as_f64(), 40.0);
|
||||
}
|
||||
|
||||
/// With a shape layer selected, Fill Options' None switches its fill off and Solid Color turns
|
||||
/// it back on, and the Fill swatch shows the layer's kind (#732).
|
||||
#[test]
|
||||
fn fill_options_change_the_selected_shape_layer() {
|
||||
let mut h = harness();
|
||||
let l = h.state_mut().session.execute("layer.newShape", json!({"kind": "rect", "size": [100, 100], "position": [320, 180]})).unwrap()["layer"]
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
h.run_steps(2);
|
||||
let fill_on = |h: &Harness<'_, EffectcraftApp>| {
|
||||
let layer = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().clone();
|
||||
layer.props.group("contents/group/contents/fill").unwrap().enabled
|
||||
};
|
||||
assert!(fill_on(&h));
|
||||
for (kind, on) in [("none", false), ("solid", true)] {
|
||||
let at = rect(&h, "header.fillOptions").center();
|
||||
click(&mut h, at);
|
||||
let at = rect(&h, &format!("header.fillOptions.{kind}")).center();
|
||||
click(&mut h, at);
|
||||
h.input_mut().events.push(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() });
|
||||
h.run_steps(3);
|
||||
assert_eq!(fill_on(&h), on, "{kind}");
|
||||
assert_eq!(h.state().session.state.shape_tool.fill.kind.id(), kind);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_pen_draws_a_closed_shape_layer() {
|
||||
let mut h = harness();
|
||||
|
||||
Reference in New Issue
Block a user