Merge branch 'worktree-agent-af1868dabbf03697e'
# Conflicts: # docs/parity.md
This commit is contained in:
@@ -0,0 +1,460 @@
|
||||
//! The Flowchart panel (Composition ▸ Composition Flowchart): a node graph of a composition and
|
||||
//! everything it uses — nested comps, footage, solids — optionally with its layers and their
|
||||
//! effects. Left to right or top to bottom; double-click a comp to open it; Cmd/Ctrl-click a
|
||||
//! node to reveal it in the Project panel (layers: select the layer); drag to pan.
|
||||
//!
|
||||
//! [`build`] is pure and cycle-safe (a comp nested in itself is drawn once, with an edge back),
|
||||
//! so agents get the same graph through `flowchart.graph`.
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use effectcraft_engine::project::{ItemId, ItemKind, LayerSource, Project};
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::theme::Tokens;
|
||||
use crate::{EffectcraftApp, widgets};
|
||||
|
||||
/// Flowchart panel options (the panel's switches).
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct FlowOptions {
|
||||
/// Show layers between a comp and its sources.
|
||||
pub layers: bool,
|
||||
/// Show each layer's effects (with layers shown).
|
||||
pub effects: bool,
|
||||
/// Show solids.
|
||||
pub solids: bool,
|
||||
/// Top to bottom instead of left to right.
|
||||
pub vertical: bool,
|
||||
/// The comp the chart starts from (None = the active comp).
|
||||
pub root: Option<u64>,
|
||||
#[serde(skip)]
|
||||
pub pan: [f32; 2],
|
||||
/// Selected node id.
|
||||
#[serde(skip)]
|
||||
pub selected: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for FlowOptions {
|
||||
fn default() -> Self {
|
||||
FlowOptions { layers: false, effects: false, solids: true, vertical: false, root: None, pan: [0.0, 0.0], selected: None }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
pub struct FlowNode {
|
||||
/// `item:<id>`, `layer:<comp>:<layer>` or `fx:<comp>:<layer>:<uid>`.
|
||||
pub id: String,
|
||||
/// `comp`, `footage`, `solid`, `layer` or `effect`.
|
||||
pub kind: &'static str,
|
||||
pub label: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub item: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub comp: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub layer: Option<u64>,
|
||||
/// Distance from the root (column, or row when vertical).
|
||||
pub depth: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
pub struct FlowGraph {
|
||||
pub nodes: Vec<FlowNode>,
|
||||
/// (from, to) node ids: from a comp to what it uses.
|
||||
pub edges: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
/// Build the flowchart of `root` (a comp). Shared items appear once; cycles stop at the comp
|
||||
/// already on the path.
|
||||
pub fn build(project: &Project, root: ItemId, opts: &FlowOptions) -> FlowGraph {
|
||||
struct B<'a> {
|
||||
p: &'a Project,
|
||||
o: &'a FlowOptions,
|
||||
nodes: Vec<FlowNode>,
|
||||
index: BTreeMap<String, usize>,
|
||||
edges: Vec<(String, String)>,
|
||||
stack: BTreeSet<u64>,
|
||||
}
|
||||
impl B<'_> {
|
||||
fn node(&mut self, n: FlowNode) -> String {
|
||||
let id = n.id.clone();
|
||||
match self.index.get(&id) {
|
||||
Some(&i) => self.nodes[i].depth = self.nodes[i].depth.min(n.depth),
|
||||
None => {
|
||||
self.index.insert(id.clone(), self.nodes.len());
|
||||
self.nodes.push(n);
|
||||
}
|
||||
}
|
||||
id
|
||||
}
|
||||
fn edge(&mut self, a: &str, b: &str) {
|
||||
let e = (a.to_string(), b.to_string());
|
||||
if !self.edges.contains(&e) {
|
||||
self.edges.push(e);
|
||||
}
|
||||
}
|
||||
fn item(&mut self, id: ItemId, depth: usize) -> Option<String> {
|
||||
let it = self.p.item(id)?;
|
||||
let kind = match &it.kind {
|
||||
ItemKind::Comp(_) => "comp",
|
||||
ItemKind::Footage(_) => "footage",
|
||||
ItemKind::Solid(_) => "solid",
|
||||
ItemKind::Folder => return None,
|
||||
};
|
||||
if kind == "solid" && !self.o.solids {
|
||||
return None;
|
||||
}
|
||||
let seen = self.index.contains_key(&format!("item:{}", id.0));
|
||||
let nid = self.node(FlowNode { id: format!("item:{}", id.0), kind, label: it.name.clone(), item: Some(id.0), comp: None, layer: None, depth });
|
||||
if kind == "comp" && !seen && !self.stack.contains(&id.0) {
|
||||
self.comp(id, depth);
|
||||
}
|
||||
Some(nid)
|
||||
}
|
||||
fn comp(&mut self, cid: ItemId, depth: usize) {
|
||||
let Some(c) = self.p.comp(cid) else { return };
|
||||
self.stack.insert(cid.0);
|
||||
let from = format!("item:{}", cid.0);
|
||||
for l in &c.layers {
|
||||
let src_depth = if self.o.layers { depth + 2 } else { depth + 1 };
|
||||
let mut parent = from.clone();
|
||||
if self.o.layers {
|
||||
let lid = self.node(FlowNode {
|
||||
id: format!("layer:{}:{}", cid.0, l.id.0),
|
||||
kind: "layer",
|
||||
label: l.name.clone(),
|
||||
item: None,
|
||||
comp: Some(cid.0),
|
||||
layer: Some(l.id.0),
|
||||
depth: depth + 1,
|
||||
});
|
||||
self.edge(&from, &lid);
|
||||
if self.o.effects
|
||||
&& let Some(fx) = l.effects()
|
||||
{
|
||||
for g in fx.groups() {
|
||||
let fid = self.node(FlowNode {
|
||||
id: format!("fx:{}:{}:{}", cid.0, l.id.0, g.uid),
|
||||
kind: "effect",
|
||||
label: g.name.clone(),
|
||||
item: None,
|
||||
comp: Some(cid.0),
|
||||
layer: Some(l.id.0),
|
||||
depth: depth + 2,
|
||||
});
|
||||
self.edge(&lid, &fid);
|
||||
}
|
||||
}
|
||||
parent = lid;
|
||||
}
|
||||
let src = match l.source {
|
||||
LayerSource::Footage { item } | LayerSource::Comp { item } | LayerSource::Solid { item } | LayerSource::Model { item } => Some(item),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(item) = src {
|
||||
// A comp already on the path: link back to it, don't descend (cycle).
|
||||
if self.stack.contains(&item.0) {
|
||||
self.edge(&parent, &format!("item:{}", item.0));
|
||||
} else if let Some(sid) = self.item(item, src_depth) {
|
||||
self.edge(&parent, &sid);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.stack.remove(&cid.0);
|
||||
}
|
||||
}
|
||||
let mut b = B { p: project, o: opts, nodes: vec![], index: BTreeMap::new(), edges: vec![], stack: BTreeSet::new() };
|
||||
b.item(root, 0);
|
||||
FlowGraph { nodes: b.nodes, edges: b.edges }
|
||||
}
|
||||
|
||||
const NODE_W: f32 = 168.0;
|
||||
const NODE_H: f32 = 34.0;
|
||||
|
||||
/// Node positions (top-left, before panning): one column (or row) per depth, in discovery order.
|
||||
pub fn layout(g: &FlowGraph, vertical: bool) -> Vec<[f32; 2]> {
|
||||
let mut slot: BTreeMap<usize, usize> = BTreeMap::new();
|
||||
g.nodes
|
||||
.iter()
|
||||
.map(|n| {
|
||||
let k = slot.entry(n.depth).or_insert(0);
|
||||
let i = *k as f32;
|
||||
*k += 1;
|
||||
let d = n.depth as f32;
|
||||
if vertical { [i * (NODE_W + 24.0), d * (NODE_H + 46.0)] } else { [d * (NODE_W + 60.0), i * (NODE_H + 14.0)] }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The comp the panel charts.
|
||||
pub fn root(app: &EffectcraftApp) -> Option<ItemId> {
|
||||
app.ui.flowchart.root.map(ItemId).filter(|r| app.session.project.comp(*r).is_some()).or_else(|| app.session.active_comp_id())
|
||||
}
|
||||
|
||||
/// `flowchart.options` / `flowchart.graph` (UI commands).
|
||||
pub fn command(app: &mut EffectcraftApp, id: &str, p: &Value) -> Result<Value, String> {
|
||||
let o = &mut app.ui.flowchart;
|
||||
let b = |k: &str| p.get(k).and_then(Value::as_bool);
|
||||
if let Some(v) = b("layers") {
|
||||
o.layers = v;
|
||||
}
|
||||
if let Some(v) = b("effects") {
|
||||
o.effects = v;
|
||||
}
|
||||
if let Some(v) = b("solids") {
|
||||
o.solids = v;
|
||||
}
|
||||
if let Some(d) = p.get("direction").and_then(Value::as_str) {
|
||||
o.vertical = match d {
|
||||
"lr" | "leftToRight" => false,
|
||||
"tb" | "topToBottom" => true,
|
||||
_ => return Err(format!("direction: lr|tb, not `{d}`")),
|
||||
};
|
||||
}
|
||||
if let Some(c) = p.get("comp") {
|
||||
let cid = match c {
|
||||
Value::Number(n) => n.as_u64().map(ItemId),
|
||||
Value::String(s) => app.session.project.find_by_name(s).map(|i| i.id),
|
||||
_ => None,
|
||||
};
|
||||
let cid = cid.filter(|c| app.session.project.comp(*c).is_some()).ok_or("comp: a composition id or name")?;
|
||||
app.ui.flowchart.root = Some(cid.0);
|
||||
}
|
||||
let o = app.ui.flowchart.clone();
|
||||
if id == "flowchart.graph" {
|
||||
let r = root(app).ok_or("no composition")?;
|
||||
return Ok(serde_json::to_value(build(&app.session.project, r, &o)).unwrap_or_default());
|
||||
}
|
||||
Ok(json!({"layers": o.layers, "effects": o.effects, "solids": o.solids, "direction": if o.vertical { "tb" } else { "lr" }, "root": o.root}))
|
||||
}
|
||||
|
||||
fn kind_style(kind: &str) -> (Icon, Color32) {
|
||||
match kind {
|
||||
"comp" => (Icon::Comp, Color32::from_rgb(0x3d, 0x5a, 0x8c)),
|
||||
"footage" => (Icon::Footage, Color32::from_rgb(0x3c, 0x6e, 0x58)),
|
||||
"solid" => (Icon::Solid, Color32::from_rgb(0x6a, 0x58, 0x3a)),
|
||||
"effect" => (Icon::Fx, Color32::from_rgb(0x6c, 0x44, 0x6e)),
|
||||
_ => (Icon::Null, Color32::from_rgb(0x44, 0x48, 0x52)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the Flowchart panel.
|
||||
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let ctx = ui.ctx().clone();
|
||||
let p = ui.painter().with_clip_rect(rect);
|
||||
p.rect_filled(rect, 0.0, t.tl_bg);
|
||||
let Some(rid) = root(app) else {
|
||||
p.text(rect.center(), Align2::CENTER_CENTER, "(no composition)", Tokens::ui(12.0), t.text_faint);
|
||||
return;
|
||||
};
|
||||
// ---- toolbar: switches and direction.
|
||||
let bar = Rect::from_min_size(rect.min, vec2(rect.width(), 30.0));
|
||||
p.rect_filled(bar, 0.0, t.panel_bg);
|
||||
let root_name = app.session.project.item(rid).map(|i| i.name.clone()).unwrap_or_default();
|
||||
p.text(pos2(bar.min.x + 10.0, bar.center().y), Align2::LEFT_CENTER, format!("Flowchart: {root_name}"), Tokens::medium(12.0), t.text);
|
||||
let mut x = bar.max.x - 8.0;
|
||||
let mut cmds: Vec<(String, Value)> = vec![];
|
||||
let o = app.ui.flowchart.clone();
|
||||
for (key, label, on) in [
|
||||
("direction", if o.vertical { "Top to Bottom" } else { "Left to Right" }, false),
|
||||
("effects", "Effects", o.effects),
|
||||
("layers", "Layers", o.layers),
|
||||
("solids", "Solids", o.solids),
|
||||
] {
|
||||
let w = 18.0 + label.len() as f32 * 6.6;
|
||||
let r = Rect::from_min_size(pos2(x - w, bar.min.y + 5.0), vec2(w, 20.0));
|
||||
x -= w + 6.0;
|
||||
if widgets::text_button(ui, r, label, on, &t, egui::Id::new(("flow-opt", key))).clicked() {
|
||||
let v = if key == "direction" { json!({"direction": if o.vertical { "lr" } else { "tb" }}) } else { json!({key: !on}) };
|
||||
cmds.push(("flowchart.options".into(), v));
|
||||
}
|
||||
app.auto.add(&format!("flowchart.option.{key}"), r, label);
|
||||
}
|
||||
|
||||
// ---- graph.
|
||||
let body = Rect::from_min_max(pos2(rect.min.x, bar.max.y), rect.max);
|
||||
let g = build(&app.session.project, rid, &o);
|
||||
let pos = layout(&g, o.vertical);
|
||||
let origin = body.min + vec2(24.0 + o.pan[0], 24.0 + o.pan[1]);
|
||||
let bg = ui.interact(body, egui::Id::new("flow-bg"), Sense::click_and_drag());
|
||||
if bg.dragged() {
|
||||
let d = bg.drag_delta();
|
||||
app.ui.flowchart.pan[0] += d.x;
|
||||
app.ui.flowchart.pan[1] += d.y;
|
||||
}
|
||||
if ui.rect_contains_pointer(body) {
|
||||
let s = ui.input(|i| i.smooth_scroll_delta);
|
||||
if s != egui::Vec2::ZERO {
|
||||
app.ui.flowchart.pan[0] += s.x;
|
||||
app.ui.flowchart.pan[1] += s.y;
|
||||
}
|
||||
}
|
||||
if bg.clicked() {
|
||||
app.ui.flowchart.selected = None;
|
||||
}
|
||||
let gp = p.with_clip_rect(body);
|
||||
let rect_of = |i: usize| Rect::from_min_size(origin + vec2(pos[i][0], pos[i][1]), vec2(NODE_W, NODE_H));
|
||||
let idx: BTreeMap<&str, usize> = g.nodes.iter().enumerate().map(|(i, n)| (n.id.as_str(), i)).collect();
|
||||
// Edges first (curves with an arrowhead at the target).
|
||||
for (a, b) in &g.edges {
|
||||
let (Some(&ia), Some(&ib)) = (idx.get(a.as_str()), idx.get(b.as_str())) else { continue };
|
||||
let (ra, rb) = (rect_of(ia), rect_of(ib));
|
||||
let back = g.nodes[ib].depth <= g.nodes[ia].depth;
|
||||
let (s, e, n) = if o.vertical { (ra.center_bottom(), rb.center_top(), vec2(0.0, 1.0)) } else { (ra.right_center(), rb.left_center(), vec2(1.0, 0.0)) };
|
||||
let k = if o.vertical { (e.y - s.y).abs() * 0.5 } else { (e.x - s.x).abs() * 0.5 }.max(30.0);
|
||||
let col = if back { Color32::from_rgb(0xd0, 0x80, 0x40) } else { t.text_faint };
|
||||
let curve = egui::epaint::CubicBezierShape::from_points_stroke([s, s + n * k, e - n * k, e], false, Color32::TRANSPARENT, Stroke::new(1.2, col));
|
||||
gp.add(curve);
|
||||
let (l, r) = if o.vertical { (vec2(-4.0, -7.0), vec2(4.0, -7.0)) } else { (vec2(-7.0, -4.0), vec2(-7.0, 4.0)) };
|
||||
gp.add(egui::Shape::convex_polygon(vec![e, e + l, e + r], col, Stroke::NONE));
|
||||
}
|
||||
let cmd_down = ui.input(|i| i.modifiers.command || i.modifiers.ctrl);
|
||||
for (i, n) in g.nodes.iter().enumerate() {
|
||||
let r = rect_of(i);
|
||||
if !r.intersects(body) {
|
||||
continue;
|
||||
}
|
||||
let (icon, fill) = kind_style(n.kind);
|
||||
let selected = o.selected.as_deref() == Some(n.id.as_str());
|
||||
let resp = ui.interact(r.intersect(body), egui::Id::new(("flow-node", &n.id)), Sense::click());
|
||||
let fill = if resp.hovered() { fill.gamma_multiply(1.25) } else { fill };
|
||||
gp.rect_filled(r, 5.0, fill);
|
||||
gp.rect_stroke(
|
||||
r,
|
||||
5.0,
|
||||
Stroke::new(if selected { 2.0 } else { 1.0 }, if selected { t.accent } else { Color32::from_black_alpha(120) }),
|
||||
StrokeKind::Inside,
|
||||
);
|
||||
icons::paint(&gp, Rect::from_center_size(pos2(r.min.x + 16.0, r.center().y), vec2(14.0, 14.0)), icon, Color32::WHITE);
|
||||
gp.with_clip_rect(r.shrink(2.0).intersect(body)).text(
|
||||
pos2(r.min.x + 30.0, r.center().y),
|
||||
Align2::LEFT_CENTER,
|
||||
&n.label,
|
||||
Tokens::ui(12.0),
|
||||
Color32::WHITE,
|
||||
);
|
||||
app.auto.add(&format!("flowchart.node.{}", n.id), r, &n.label);
|
||||
if resp.clicked() {
|
||||
app.ui.flowchart.selected = Some(n.id.clone());
|
||||
if cmd_down {
|
||||
// Reveal: items in the Project panel, layers selected in their comp.
|
||||
match (n.item, n.comp, n.layer) {
|
||||
(Some(item), ..) => {
|
||||
cmds.push(("project.select".into(), json!({"items": [item]})));
|
||||
cmds.push(("window.panel".into(), json!({"panel": "project"})));
|
||||
}
|
||||
(None, Some(c), Some(l)) => {
|
||||
cmds.push(("comp.open".into(), json!({"comp": c})));
|
||||
cmds.push(("layer.select".into(), json!({"layers": [l]})));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
if resp.double_clicked() {
|
||||
match (n.kind, n.item, n.comp) {
|
||||
("comp", Some(c), _) => cmds.push(("comp.open".into(), json!({"comp": c}))),
|
||||
(_, _, Some(c)) => cmds.push(("comp.open".into(), json!({"comp": c}))),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
resp.on_hover_text(format!("{} — double-click to open, {}-click to reveal", n.label, if cfg!(target_os = "macos") { "Cmd" } else { "Ctrl" }));
|
||||
}
|
||||
for (id, params) in cmds {
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use effectcraft_engine::Session;
|
||||
|
||||
/// Main ⊃ Mid ⊃ Inner (with a solid), Main also uses Inner directly.
|
||||
fn session() -> (Session, ItemId, ItemId, ItemId) {
|
||||
let mut s = Session::default();
|
||||
let id = |v: Value| ItemId(v["id"].as_u64().or_else(|| v["comp"].as_u64()).or_else(|| v["item"].as_u64()).unwrap());
|
||||
let inner = id(s.execute("comp.new", json!({"name": "Inner", "width": 100, "height": 100, "duration": 2})).unwrap());
|
||||
s.execute("layer.newSolid", json!({"name": "Red", "color": "#ff0000", "width": 100, "height": 100})).unwrap();
|
||||
s.execute("layer.select", json!({"layers": []})).unwrap();
|
||||
let mid = id(s.execute("comp.new", json!({"name": "Mid", "width": 100, "height": 100, "duration": 2})).unwrap());
|
||||
s.execute("layer.addItem", json!({"item": inner.0})).unwrap();
|
||||
let main = id(s.execute("comp.new", json!({"name": "Main", "width": 100, "height": 100, "duration": 2})).unwrap());
|
||||
s.execute("layer.addItem", json!({"item": mid.0})).unwrap();
|
||||
s.execute("layer.addItem", json!({"item": inner.0})).unwrap();
|
||||
s.execute("layer.newText", json!({"text": "Title"})).unwrap();
|
||||
(s, main, mid, inner)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_comps_make_a_graph() {
|
||||
let (s, main, mid, inner) = session();
|
||||
let g = build(&s.project, main, &FlowOptions::default());
|
||||
let label = |id: &str| g.nodes.iter().find(|n| n.id == id).map(|n| (n.label.clone(), n.depth));
|
||||
assert_eq!(label(&format!("item:{}", main.0)), Some(("Main".into(), 0)));
|
||||
assert_eq!(label(&format!("item:{}", mid.0)), Some(("Mid".into(), 1)));
|
||||
// Inner is reached at depth 1 (directly) and 2 (through Mid): drawn once, at depth 1.
|
||||
assert_eq!(label(&format!("item:{}", inner.0)), Some(("Inner".into(), 1)));
|
||||
assert_eq!(g.nodes.iter().filter(|n| n.label == "Inner").count(), 1);
|
||||
let has = |a: ItemId, b: ItemId| g.edges.contains(&(format!("item:{}", a.0), format!("item:{}", b.0)));
|
||||
assert!(has(main, mid) && has(mid, inner) && has(main, inner));
|
||||
// The solid is shown (Solids on) and hidden with Solids off; text layers have no source.
|
||||
assert!(g.nodes.iter().any(|n| n.kind == "solid"));
|
||||
let g2 = build(&s.project, main, &FlowOptions { solids: false, ..Default::default() });
|
||||
assert!(!g2.nodes.iter().any(|n| n.kind == "solid"));
|
||||
// Layers between comps and sources; effects under layers.
|
||||
let g3 = build(&s.project, main, &FlowOptions { layers: true, ..Default::default() });
|
||||
assert!(g3.nodes.iter().any(|n| n.kind == "layer" && n.label == "Title"));
|
||||
let mid_layer = g3.nodes.iter().find(|n| n.kind == "layer" && n.comp == Some(main.0) && n.label == "Mid").unwrap();
|
||||
assert!(g3.edges.contains(&(mid_layer.id.clone(), format!("item:{}", mid.0))));
|
||||
// Layout: one column per depth, no overlaps.
|
||||
let pos = layout(&g3, false);
|
||||
for i in 0..pos.len() {
|
||||
for j in i + 1..pos.len() {
|
||||
assert!(pos[i] != pos[j], "{} and {} overlap", g3.nodes[i].label, g3.nodes[j].label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cycles_are_safe() {
|
||||
let (mut s, main, mid, _) = session();
|
||||
// Make Mid contain Main: Main → Mid → Main.
|
||||
s.execute("comp.open", json!({"comp": mid.0})).unwrap();
|
||||
// Adding a cyclic layer may be refused by the engine; build a cycle in the model directly.
|
||||
let mut p = (*s.project).clone();
|
||||
let mut c = (*p.comp(mid).unwrap()).clone();
|
||||
let mut l = c.layers[0].clone();
|
||||
l.id = effectcraft_engine::project::LayerId(9999);
|
||||
l.source = LayerSource::Comp { item: main };
|
||||
c.layers.push(l);
|
||||
if let Some(ItemKind::Comp(arc)) = p.items.get_mut(&mid).map(|i| &mut i.kind) {
|
||||
*arc = std::sync::Arc::new(c);
|
||||
}
|
||||
let g = build(&p, main, &FlowOptions { layers: true, effects: true, ..Default::default() });
|
||||
assert_eq!(g.nodes.iter().filter(|n| n.kind == "comp" && n.label == "Main").count(), 1);
|
||||
// The back edge points at the root.
|
||||
assert!(g.edges.iter().any(|(_, b)| *b == format!("item:{}", main.0)));
|
||||
assert!(g.nodes.len() < 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn options_command() {
|
||||
let (s, main, ..) = session();
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
let r = command(&mut app, "flowchart.options", &json!({"layers": true, "direction": "tb"})).unwrap();
|
||||
assert_eq!(r["direction"], "tb");
|
||||
assert!(app.ui.flowchart.layers && app.ui.flowchart.vertical);
|
||||
assert!(command(&mut app, "flowchart.options", &json!({"direction": "diagonal"})).is_err());
|
||||
let g = command(&mut app, "flowchart.graph", &json!({"comp": "Main"})).unwrap();
|
||||
assert_eq!(g["nodes"][0]["id"], format!("item:{}", main.0));
|
||||
assert!(g["edges"].as_array().is_some_and(|e| !e.is_empty()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
//! The Home screen (shown in the Composition panel at launch, from the header's Home button, and
|
||||
//! by the Learn workspace): New Project / Open Project / New Composition / Open Demo, the recent
|
||||
//! projects (File ▸ Open Recent, from Settings) with thumbnails, folders and dates, and where
|
||||
//! After Effects has its Learn / What's New area, the ArtCraft community links.
|
||||
//!
|
||||
//! Thumbnails: when a project is opened or saved and the viewer has its frame, a 96×54 RGB
|
||||
//! thumbnail is stored in the config store (`thumb-<hash>.txt`, hex) and shown here.
|
||||
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::theme::Tokens;
|
||||
use crate::{EffectcraftApp, widgets};
|
||||
|
||||
pub const THUMB_W: usize = 96;
|
||||
pub const THUMB_H: usize = 54;
|
||||
|
||||
/// One row of the recent projects list.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
pub struct RecentEntry {
|
||||
pub index: usize,
|
||||
pub path: String,
|
||||
pub name: String,
|
||||
pub folder: String,
|
||||
/// Last modified (`2026-10-02 14:05`, UTC), when the file is readable.
|
||||
pub modified: Option<String>,
|
||||
pub exists: bool,
|
||||
}
|
||||
|
||||
/// The recent projects, most recent first (Settings ▸ General ▸ recent items).
|
||||
pub fn recent_entries(prefs: &effectcraft_engine::prefs::Prefs) -> Vec<RecentEntry> {
|
||||
prefs
|
||||
.recent_projects
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, p)| {
|
||||
let path = std::path::Path::new(p);
|
||||
let meta = std::fs::metadata(path).ok();
|
||||
let modified = meta
|
||||
.as_ref()
|
||||
.and_then(|m| m.modified().ok())
|
||||
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
|
||||
.map(|d| format_utc(d.as_secs() as i64));
|
||||
RecentEntry {
|
||||
index,
|
||||
path: p.clone(),
|
||||
name: path.file_stem().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| p.clone()),
|
||||
folder: path.parent().map(|d| d.to_string_lossy().to_string()).unwrap_or_default(),
|
||||
modified,
|
||||
exists: meta.is_some(),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// `YYYY-MM-DD HH:MM` (UTC) from Unix seconds.
|
||||
pub fn format_utc(secs: i64) -> String {
|
||||
let days = secs.div_euclid(86_400);
|
||||
let rem = secs.rem_euclid(86_400);
|
||||
// Civil date from days since 1970-01-01 (Howard Hinnant's algorithm).
|
||||
let z = days + 719_468;
|
||||
let era = z.div_euclid(146_097);
|
||||
let doe = z - era * 146_097;
|
||||
let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365;
|
||||
let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
|
||||
let mp = (5 * doy + 2) / 153;
|
||||
let d = doy - (153 * mp + 2) / 5 + 1;
|
||||
let m = if mp < 10 { mp + 3 } else { mp - 9 };
|
||||
let y = yoe + era * 400 + i64::from(m <= 2);
|
||||
format!("{y:04}-{m:02}-{d:02} {:02}:{:02}", rem / 3600, (rem % 3600) / 60)
|
||||
}
|
||||
|
||||
/// The config-store name of a project's thumbnail.
|
||||
pub fn thumb_name(path: &str) -> String {
|
||||
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||
path.hash(&mut h);
|
||||
format!("thumb-{:016x}.txt", h.finish())
|
||||
}
|
||||
|
||||
/// Downscale an image to a letterboxed THUMB_W×THUMB_H RGB thumbnail (hex text).
|
||||
pub fn encode_thumb(img: &egui::ColorImage) -> String {
|
||||
let [w, h] = img.size;
|
||||
let mut out = String::with_capacity(THUMB_W * THUMB_H * 6);
|
||||
let k = (THUMB_W as f32 / w.max(1) as f32).min(THUMB_H as f32 / h.max(1) as f32);
|
||||
let (dw, dh) = (w as f32 * k, h as f32 * k);
|
||||
let (ox, oy) = ((THUMB_W as f32 - dw) / 2.0, (THUMB_H as f32 - dh) / 2.0);
|
||||
for y in 0..THUMB_H {
|
||||
for x in 0..THUMB_W {
|
||||
let (fx, fy) = ((x as f32 + 0.5 - ox) / k, (y as f32 + 0.5 - oy) / k);
|
||||
let c = if fx >= 0.0 && fy >= 0.0 && (fx as usize) < w && (fy as usize) < h {
|
||||
let p = img.pixels[fy as usize * w + fx as usize];
|
||||
[p.r(), p.g(), p.b()]
|
||||
} else {
|
||||
[0x16, 0x17, 0x1c]
|
||||
};
|
||||
for v in c {
|
||||
out.push_str(&format!("{v:02x}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn decode_thumb(text: &str) -> Option<egui::ColorImage> {
|
||||
let t = text.trim();
|
||||
if t.len() != THUMB_W * THUMB_H * 6 {
|
||||
return None;
|
||||
}
|
||||
let b: Vec<u8> = (0..t.len()).step_by(2).map(|i| u8::from_str_radix(&t[i..i + 2], 16)).collect::<Result<_, _>>().ok()?;
|
||||
let px = b.chunks_exact(3).map(|c| Color32::from_rgb(c[0], c[1], c[2])).collect();
|
||||
Some(egui::ColorImage::new([THUMB_W, THUMB_H], px))
|
||||
}
|
||||
|
||||
/// Store the viewer's frame as the open project's thumbnail after it is opened or saved (once per
|
||||
/// saved revision, when the viewer shows that revision).
|
||||
pub fn capture_thumbnail(app: &mut EffectcraftApp) {
|
||||
let s = &app.session;
|
||||
let (Some(path), Some(_)) = (s.path.clone(), s.config.as_ref()) else { return };
|
||||
if s.is_dirty() {
|
||||
return;
|
||||
}
|
||||
let key = (path.clone(), s.saved_revision);
|
||||
if app.home_thumb_saved.as_ref() == Some(&key) {
|
||||
return;
|
||||
}
|
||||
if app.viewer_shown.as_ref().map(|(_, k)| k.revision) != Some(s.revision) {
|
||||
return;
|
||||
}
|
||||
let Some(img) = app.viewer_pixels() else { return };
|
||||
let text = encode_thumb(&img);
|
||||
if let Some(c) = &app.session.config
|
||||
&& let Err(e) = c.write(&thumb_name(&path), &text)
|
||||
{
|
||||
log::warn!("project thumbnail: {e}");
|
||||
}
|
||||
app.home_thumbs.remove(&path);
|
||||
app.home_thumb_saved = Some(key);
|
||||
}
|
||||
|
||||
fn thumb_texture(app: &mut EffectcraftApp, ctx: &egui::Context, path: &str) -> Option<egui::TextureHandle> {
|
||||
if let Some(t) = app.home_thumbs.get(path) {
|
||||
return t.clone();
|
||||
}
|
||||
let tex = app
|
||||
.session
|
||||
.config
|
||||
.as_ref()
|
||||
.and_then(|c| c.read(&thumb_name(path)))
|
||||
.and_then(|t| decode_thumb(&t))
|
||||
.map(|img| ctx.load_texture(format!("home-thumb-{path}"), img, egui::TextureOptions::LINEAR));
|
||||
app.home_thumbs.insert(path.to_string(), tex.clone());
|
||||
tex
|
||||
}
|
||||
|
||||
/// Draw the Home screen.
|
||||
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let ctx = ui.ctx().clone();
|
||||
let p = ui.painter().with_clip_rect(rect);
|
||||
p.rect_filled(rect, 0.0, Color32::from_rgb(0x1b, 0x1d, 0x24));
|
||||
let wide = rect.width() >= 820.0;
|
||||
let pad = 32.0;
|
||||
let left_w = if wide { 250.0 } else { rect.width() - pad * 2.0 };
|
||||
let mut actions: Vec<(&str, serde_json::Value)> = vec![];
|
||||
|
||||
// ---- left: brand + start actions.
|
||||
let x0 = rect.min.x + pad;
|
||||
let mut y = rect.min.y + pad;
|
||||
crate::header::paint_logo(&p, Rect::from_min_size(pos2(x0, y), vec2(40.0, 40.0)));
|
||||
p.text(pos2(x0 + 52.0, y + 12.0), Align2::LEFT_CENTER, "EffectCraft", Tokens::semibold(22.0), Color32::WHITE);
|
||||
p.text(pos2(x0 + 52.0, y + 32.0), Align2::LEFT_CENTER, format!("Version {}", env!("CARGO_PKG_VERSION")), Tokens::ui(11.0), t.text_faint);
|
||||
y += 64.0;
|
||||
for (label, id, primary) in [
|
||||
("New Project", "file.newProject", true),
|
||||
("Open Project…", "file.open", false),
|
||||
("New Composition", "app.newComp", false),
|
||||
("Open Demo Project", "file.openDemoProject", false),
|
||||
("Import Footage…", "file.import", false),
|
||||
] {
|
||||
let r = Rect::from_min_size(pos2(x0, y), vec2(left_w.min(250.0), 32.0));
|
||||
if widgets::text_button(ui, r, label, primary, &t, egui::Id::new(("home", id))).clicked() {
|
||||
actions.push((id, json!({})));
|
||||
}
|
||||
app.auto.add(&format!("home.{id}"), r, label);
|
||||
y += 40.0;
|
||||
}
|
||||
|
||||
// ---- community (After Effects' Learn / What's New area).
|
||||
let (cx, mut cy, cw) = if wide { (x0, y + 18.0, left_w) } else { (x0, y + 10.0, left_w) };
|
||||
p.text(pos2(cx, cy), Align2::LEFT_CENTER, "Community", Tokens::semibold(13.0), t.text);
|
||||
cy += 16.0;
|
||||
p.text(pos2(cx, cy), Align2::LEFT_CENTER, "Tutorials, help and what's new", Tokens::ui(11.0), t.text_faint);
|
||||
cy += 16.0;
|
||||
let links = [
|
||||
(Icon::Chat, "Join the ArtCraft Discord", "help.discord"),
|
||||
(Icon::Globe, "getartcraft.com", "help.website"),
|
||||
(Icon::Globe, "EffectCraft home page", "help.appPage"),
|
||||
(Icon::Code, "EffectCraft on GitHub", "help.github"),
|
||||
];
|
||||
for (icon, label, cmd) in links {
|
||||
let r = Rect::from_min_size(pos2(cx, cy), vec2(cw.min(250.0), 30.0));
|
||||
let resp = ui.interact(r, egui::Id::new(("home-link", cmd)), Sense::click());
|
||||
let discord = cmd == "help.discord";
|
||||
let bg = if discord {
|
||||
Color32::from_rgb(0x58, 0x65, 0xf2)
|
||||
} else if resp.hovered() {
|
||||
t.hover
|
||||
} else {
|
||||
Color32::from_rgb(0x2a, 0x2c, 0x34)
|
||||
};
|
||||
p.rect_filled(r, 15.0, bg);
|
||||
icons::paint(&p, Rect::from_center_size(pos2(r.min.x + 20.0, r.center().y), vec2(14.0, 14.0)), icon, Color32::WHITE);
|
||||
p.text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::medium(12.0), Color32::WHITE);
|
||||
app.auto.add(&format!("home.{cmd}"), r, label);
|
||||
if resp.clicked() {
|
||||
let _ = app.session.execute(cmd, json!({}));
|
||||
}
|
||||
cy += 36.0;
|
||||
}
|
||||
cy += 8.0;
|
||||
p.text(pos2(cx, cy), Align2::LEFT_CENTER, "More ArtCraft apps", Tokens::ui(11.0), t.text_faint);
|
||||
cy += 12.0;
|
||||
let sib = effectcraft_engine::links::SIBLINGS;
|
||||
let per_row = 2usize;
|
||||
let sw = (cw.min(250.0) - 6.0) / per_row as f32;
|
||||
for (i, (name, slug)) in sib.iter().enumerate() {
|
||||
let r = Rect::from_min_size(pos2(cx + (i % per_row) as f32 * (sw + 6.0), cy + (i / per_row) as f32 * 28.0), vec2(sw, 24.0));
|
||||
let resp = ui.interact(r, egui::Id::new(("sib", *slug)), Sense::click());
|
||||
p.rect_filled(r, 12.0, if resp.hovered() { t.hover } else { Color32::from_rgb(0x24, 0x26, 0x2e) });
|
||||
p.text(r.center(), Align2::CENTER_CENTER, *name, Tokens::ui(11.5), t.text);
|
||||
app.auto.add(&format!("home.sibling.{slug}"), r, name);
|
||||
if resp.clicked() {
|
||||
let _ = app.session.execute("help.sibling", json!({"app": slug}));
|
||||
}
|
||||
}
|
||||
let community_bottom = cy + sib.len().div_ceil(per_row) as f32 * 28.0;
|
||||
|
||||
// ---- recent projects.
|
||||
let (rx, mut ry, rw) = if wide {
|
||||
let rx = x0 + left_w + 40.0;
|
||||
(rx, rect.min.y + pad + 6.0, rect.max.x - pad - rx)
|
||||
} else {
|
||||
(x0, community_bottom + 24.0, left_w)
|
||||
};
|
||||
p.text(pos2(rx, ry + 6.0), Align2::LEFT_CENTER, "Recent", Tokens::semibold(16.0), Color32::WHITE);
|
||||
let entries = recent_entries(&app.session.prefs);
|
||||
if !entries.is_empty() {
|
||||
let cr = Rect::from_min_size(pos2(rx + rw - 100.0, ry - 4.0), vec2(100.0, 20.0));
|
||||
let resp = ui.interact(cr, egui::Id::new("home-clear-recent"), Sense::click());
|
||||
p.text(cr.right_center(), Align2::RIGHT_CENTER, "Clear list", Tokens::ui(11.0), if resp.hovered() { t.text } else { t.text_faint });
|
||||
app.auto.add("home.clearRecent", cr, "Clear Recent Projects");
|
||||
if resp.clicked() {
|
||||
actions.push(("file.clearRecent", json!({})));
|
||||
}
|
||||
}
|
||||
ry += 26.0;
|
||||
// Column headings.
|
||||
let date_w = 130.0;
|
||||
p.text(pos2(rx + 112.0, ry), Align2::LEFT_CENTER, "Name", Tokens::ui(11.0), t.text_faint);
|
||||
p.text(pos2(rx + rw - date_w, ry), Align2::LEFT_CENTER, "Modified", Tokens::ui(11.0), t.text_faint);
|
||||
ry += 10.0;
|
||||
p.line_segment([pos2(rx, ry), pos2(rx + rw, ry)], Stroke::new(1.0, t.separator));
|
||||
ry += 6.0;
|
||||
if entries.is_empty() {
|
||||
p.text(pos2(rx, ry + 20.0), Align2::LEFT_CENTER, "No recent projects. Projects you open or save appear here.", Tokens::ui(12.0), t.text_faint);
|
||||
}
|
||||
let row_h = 66.0;
|
||||
for e in &entries {
|
||||
let r = Rect::from_min_size(pos2(rx, ry), vec2(rw, row_h - 4.0));
|
||||
if r.min.y > rect.max.y {
|
||||
break;
|
||||
}
|
||||
let resp = ui.interact(r, egui::Id::new(("home-recent", e.index)), Sense::click()).on_hover_text(&e.path);
|
||||
if resp.hovered() {
|
||||
p.rect_filled(r, 6.0, t.hover);
|
||||
}
|
||||
let tr = Rect::from_min_size(pos2(r.min.x + 6.0, r.min.y + 4.0), vec2(THUMB_W as f32, THUMB_H as f32));
|
||||
match thumb_texture(app, &ctx, &e.path) {
|
||||
Some(tex) => {
|
||||
p.image(tex.id(), tr, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
|
||||
}
|
||||
None => {
|
||||
p.rect_filled(tr, 3.0, Color32::from_rgb(0x24, 0x26, 0x2e));
|
||||
icons::paint(&p, Rect::from_center_size(tr.center(), vec2(20.0, 20.0)), Icon::Comp, t.text_faint);
|
||||
}
|
||||
}
|
||||
p.rect_stroke(tr, 3.0, Stroke::new(1.0, t.separator), StrokeKind::Inside);
|
||||
let tx = tr.max.x + 12.0;
|
||||
let text_clip = p.with_clip_rect(Rect::from_min_max(pos2(tx, r.min.y), pos2(r.max.x - date_w - 8.0, r.max.y)));
|
||||
text_clip.text(pos2(tx, r.min.y + 20.0), Align2::LEFT_CENTER, &e.name, Tokens::semibold(13.0), if e.exists { Color32::WHITE } else { t.text_dim });
|
||||
let sub = if e.exists { e.folder.clone() } else { format!("{} (missing)", e.folder) };
|
||||
text_clip.text(pos2(tx, r.min.y + 40.0), Align2::LEFT_CENTER, sub, Tokens::ui(11.0), t.text_faint);
|
||||
if let Some(d) = &e.modified {
|
||||
p.text(pos2(r.max.x - date_w, r.min.y + 20.0), Align2::LEFT_CENTER, d, Tokens::ui(11.0), t.text_dim);
|
||||
}
|
||||
app.auto.add(&format!("home.recent.{}", e.index), r, &e.path);
|
||||
if resp.clicked() {
|
||||
actions.push(("file.openRecent", json!({"index": e.index})));
|
||||
}
|
||||
ry += row_h;
|
||||
}
|
||||
|
||||
for (id, params) in actions {
|
||||
let before = (app.session.path.clone(), app.session.revision);
|
||||
match crate::menus::invoke(app, &ctx, id, params) {
|
||||
Err(e) => app.ui.status = e,
|
||||
// Leave Home unless only the list changed or a file dialog was cancelled.
|
||||
Ok(_) => {
|
||||
let cancelled = matches!(id, "file.open" | "file.import") && (app.session.path.clone(), app.session.revision) == before;
|
||||
if id != "file.clearRecent" && !cancelled {
|
||||
app.ui.start_screen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn recent_list_comes_from_settings() {
|
||||
let mut prefs = effectcraft_engine::prefs::Prefs::default();
|
||||
prefs.push_recent("/projects/a/Alpha.ecproj");
|
||||
prefs.push_recent("/projects/b/Beta.ecproj");
|
||||
let e = recent_entries(&prefs);
|
||||
assert_eq!(e.len(), 2);
|
||||
assert_eq!((e[0].name.as_str(), e[0].folder.as_str(), e[0].index), ("Beta", "/projects/b", 0));
|
||||
assert_eq!(e[1].name, "Alpha");
|
||||
assert!(!e[0].exists && e[0].modified.is_none());
|
||||
// A real file has a date.
|
||||
let dir = std::env::temp_dir().join(format!("ec-home-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let f = dir.join("Real.ecproj");
|
||||
std::fs::write(&f, "{}").unwrap();
|
||||
prefs.push_recent(&f.to_string_lossy());
|
||||
let e = recent_entries(&prefs);
|
||||
assert!(e[0].exists && e[0].modified.as_ref().is_some_and(|d| d.len() == 16), "{:?}", e[0]);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dates_and_thumbnails() {
|
||||
assert_eq!(format_utc(0), "1970-01-01 00:00");
|
||||
assert_eq!(format_utc(1_790_000_000), "2026-09-21 14:13");
|
||||
assert_eq!(format_utc(951_782_400), "2000-02-29 00:00");
|
||||
let img = egui::ColorImage::new([200, 100], vec![Color32::from_rgb(10, 200, 30); 200 * 100]);
|
||||
let text = encode_thumb(&img);
|
||||
let back = decode_thumb(&text).unwrap();
|
||||
assert_eq!(back.size, [THUMB_W, THUMB_H]);
|
||||
// Letterboxed: the middle is the image, the top row is the background (2:1 into 16:9).
|
||||
assert_eq!(back.pixels[THUMB_H / 2 * THUMB_W + THUMB_W / 2], Color32::from_rgb(10, 200, 30));
|
||||
assert_ne!(back.pixels[THUMB_W / 2], Color32::from_rgb(10, 200, 30));
|
||||
assert!(decode_thumb("abc").is_none());
|
||||
assert_ne!(thumb_name("/a.ecproj"), thumb_name("/b.ecproj"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn home_screen_registers_its_controls() {
|
||||
let mut s = effectcraft_engine::Session::default();
|
||||
s.prefs.push_recent("/projects/Alpha.ecproj");
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install(&ctx, &app.tokens);
|
||||
ctx.run_ui(Default::default(), |_| {}).textures_delta.clear();
|
||||
ctx.run_ui(Default::default(), |ui| {
|
||||
app.auto.begin_frame();
|
||||
show(&mut app, ui, Rect::from_min_size(pos2(0.0, 0.0), vec2(1200.0, 800.0)));
|
||||
})
|
||||
.textures_delta
|
||||
.clear();
|
||||
for id in [
|
||||
"home.file.newProject",
|
||||
"home.file.open",
|
||||
"home.app.newComp",
|
||||
"home.file.openDemoProject",
|
||||
"home.help.discord",
|
||||
"home.help.github",
|
||||
"home.recent.0",
|
||||
] {
|
||||
assert!(app.auto.find(id).is_some(), "{id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
//! Smaller panels: Preview, Audio, History, Markers, the Home screen and placeholders.
|
||||
//! Smaller panels: Preview, Audio, History, Markers and placeholders.
|
||||
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::dock::PanelKind;
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::icons::Icon;
|
||||
use crate::theme::Tokens;
|
||||
use crate::{EffectcraftApp, widgets};
|
||||
|
||||
@@ -223,73 +223,3 @@ pub fn markers(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Home screen: new/open, recent, and community links.
|
||||
pub fn start_screen(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let ctx = ui.ctx().clone();
|
||||
let p = ui.painter().with_clip_rect(rect);
|
||||
p.rect_filled(rect, 0.0, Color32::from_rgb(0x1b, 0x1d, 0x24));
|
||||
let c = rect.center();
|
||||
let logo = Rect::from_center_size(c + vec2(0.0, -150.0), vec2(64.0, 64.0));
|
||||
crate::header::paint_logo(&p, logo);
|
||||
p.text(c + vec2(0.0, -96.0), Align2::CENTER_CENTER, "EffectCraft", Tokens::semibold(28.0), Color32::WHITE);
|
||||
p.text(c + vec2(0.0, -66.0), Align2::CENTER_CENTER, "Motion graphics and visual effects, in pure Rust.", Tokens::ui(13.0), t.text_dim);
|
||||
let mut y = c.y - 30.0;
|
||||
for (label, id, primary) in [
|
||||
("New Composition", "app.newComp", true),
|
||||
("Open Demo Project", "file.openDemoProject", false),
|
||||
("Open Project…", "file.open", false),
|
||||
("Import Footage…", "file.import", false),
|
||||
] {
|
||||
let r = Rect::from_center_size(pos2(c.x, y + 16.0), vec2(240.0, 32.0));
|
||||
if widgets::text_button(ui, r, label, primary, &t, egui::Id::new(("home", id))).clicked() {
|
||||
let _ = crate::menus::invoke(app, &ctx, id, json!({}));
|
||||
app.ui.start_screen = false;
|
||||
}
|
||||
app.auto.add(&format!("home.{id}"), r, label);
|
||||
y += 40.0;
|
||||
}
|
||||
// Community.
|
||||
y += 14.0;
|
||||
let links = [(Icon::Chat, "Join the Discord", "help.discord"), (Icon::Globe, "getartcraft.com", "help.website"), (Icon::Code, "GitHub", "help.github")];
|
||||
let w = 170.0;
|
||||
let mut x = c.x - w * 1.5 - 8.0;
|
||||
for (icon, label, cmd) in links {
|
||||
let r = Rect::from_min_size(pos2(x, y), vec2(w, 30.0));
|
||||
let resp = ui.interact(r, egui::Id::new(("home-link", cmd)), Sense::click());
|
||||
let discord = cmd == "help.discord";
|
||||
let bg = if discord {
|
||||
Color32::from_rgb(0x58, 0x65, 0xf2)
|
||||
} else if resp.hovered() {
|
||||
t.hover
|
||||
} else {
|
||||
Color32::from_rgb(0x2a, 0x2c, 0x34)
|
||||
};
|
||||
p.rect_filled(r, 15.0, bg);
|
||||
icons::paint(&p, Rect::from_center_size(pos2(r.min.x + 20.0, r.center().y), vec2(14.0, 14.0)), icon, Color32::WHITE);
|
||||
p.text(pos2(r.min.x + 34.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::medium(12.0), Color32::WHITE);
|
||||
app.auto.add(&format!("home.{cmd}"), r, label);
|
||||
if resp.clicked() {
|
||||
let _ = app.session.execute(cmd, json!({}));
|
||||
}
|
||||
x += w + 8.0;
|
||||
}
|
||||
// Siblings.
|
||||
y += 52.0;
|
||||
p.text(pos2(c.x, y), Align2::CENTER_CENTER, "More ArtCraft apps", Tokens::ui(11.5), t.text_faint);
|
||||
y += 18.0;
|
||||
let sib = effectcraft_engine::links::SIBLINGS;
|
||||
let sw = 104.0;
|
||||
let mut x = c.x - sw * sib.len() as f32 / 2.0;
|
||||
for (name, slug) in sib {
|
||||
let r = Rect::from_min_size(pos2(x + 2.0, y), vec2(sw - 4.0, 24.0));
|
||||
let resp = ui.interact(r, egui::Id::new(("sib", *slug)), Sense::click());
|
||||
p.rect_filled(r, 12.0, if resp.hovered() { t.hover } else { Color32::from_rgb(0x24, 0x26, 0x2e) });
|
||||
p.text(r.center(), Align2::CENTER_CENTER, *name, Tokens::ui(11.5), t.text);
|
||||
if resp.clicked() {
|
||||
let _ = app.session.execute("help.sibling", json!({"app": slug}));
|
||||
}
|
||||
x += sw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ pub mod dialogs;
|
||||
pub mod dialogs_3d;
|
||||
pub mod effect_controls;
|
||||
pub mod effects_presets;
|
||||
pub mod flowchart;
|
||||
pub mod forms;
|
||||
pub mod fx_widgets;
|
||||
pub mod graph;
|
||||
pub mod graph_tools;
|
||||
pub mod home;
|
||||
pub mod info;
|
||||
pub mod key_dialogs;
|
||||
pub mod layer_panel;
|
||||
@@ -65,7 +67,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: PanelKind, rect: Rec
|
||||
match p {
|
||||
PanelKind::Composition => {
|
||||
if app.ui.start_screen {
|
||||
misc::start_screen(app, ui, rect);
|
||||
home::show(app, ui, rect);
|
||||
} else {
|
||||
viewer::show(app, ui, rect)
|
||||
}
|
||||
@@ -93,7 +95,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: PanelKind, rect: Rec
|
||||
PanelKind::Layer => layer_panel::show(app, ui, rect),
|
||||
PanelKind::Paint => paint_panels::paint(app, ui, rect),
|
||||
PanelKind::Brushes => paint_panels::brushes(app, ui, rect),
|
||||
other => misc::placeholder(app, ui, rect, other),
|
||||
PanelKind::Flowchart => flowchart::show(app, ui, rect),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user