G2: improve editing reliability and Windows rendering fidelity
This commit is contained in:
@@ -329,6 +329,7 @@ pub fn viewer_hook(
|
||||
}
|
||||
});
|
||||
if resp.hovered()
|
||||
&& app.dialog.is_none()
|
||||
&& !selected.is_empty()
|
||||
&& ui.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace))
|
||||
&& !ctx.egui_wants_keyboard_input()
|
||||
|
||||
@@ -147,18 +147,18 @@ pub fn route_layer_settings(app: &mut EffectcraftApp, id: &str, params: &Value)
|
||||
}
|
||||
|
||||
pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
|
||||
// Dim the app.
|
||||
let screen = ctx.content_rect();
|
||||
ctx.layer_painter(egui::LayerId::new(egui::Order::Middle, egui::Id::new("modal-dim"))).rect_filled(screen, 0.0, Color32::from_black_alpha(120));
|
||||
egui::Area::new(egui::Id::new(("modal", title))).order(egui::Order::Foreground).fixed_pos(screen.center() - size / 2.0).show(ctx, |ui| {
|
||||
egui::Frame::window(ui.style()).fill(t.panel_bg).inner_margin(egui::Margin::same(18)).show(ui, |ui| {
|
||||
let available = (ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0));
|
||||
let size = size.min(available);
|
||||
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)))
|
||||
.show(ctx, |ui| {
|
||||
ui.set_width(size.x - 36.0);
|
||||
ui.set_min_height(size.y - 36.0);
|
||||
ui.label(egui::RichText::new(title).font(Tokens::semibold(15.0)).color(t.tab_text_active));
|
||||
ui.add_space(10.0);
|
||||
body(ui);
|
||||
egui::ScrollArea::both().max_height((available.y - 84.0).max(40.0)).auto_shrink([false, true]).show(ui, body);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
@@ -228,11 +228,12 @@ fn about(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
} else if resp.hovered() {
|
||||
t.hover
|
||||
} else {
|
||||
Color32::from_rgb(0x2b, 0x2b, 0x2b)
|
||||
t.field_bg
|
||||
},
|
||||
);
|
||||
icons::paint(p, Rect::from_center_size(pos2(r.min.x + 18.0, r.center().y), vec2(15.0, 15.0)), icon, Color32::WHITE);
|
||||
p.text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::medium(12.5), Color32::WHITE);
|
||||
let foreground = if discord { Color32::WHITE } else { t.text };
|
||||
icons::paint(p, Rect::from_center_size(pos2(r.min.x + 18.0, r.center().y), vec2(15.0, 15.0)), icon, foreground);
|
||||
p.text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::medium(12.5), foreground);
|
||||
p.text(
|
||||
pos2(r.max.x - 12.0, r.center().y),
|
||||
Align2::RIGHT_CENTER,
|
||||
|
||||
@@ -1064,6 +1064,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
egui::DragAndDrop::clear_payload(&ctx);
|
||||
}
|
||||
}
|
||||
if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") {
|
||||
app.ui.viewer.property_interacting = true;
|
||||
ctx.request_repaint();
|
||||
}
|
||||
for (id, params) in actions {
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
app.ui.status = e;
|
||||
|
||||
@@ -320,8 +320,8 @@ fn name_label(app: &mut EffectcraftApp, ui: &mut egui::Ui, cid: ItemId, c: &EgCo
|
||||
fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Option<ControlType>, p: &Property, v: &KV) -> Option<Value> {
|
||||
let ty = ty?;
|
||||
let mut out = None;
|
||||
let rect;
|
||||
match ty {
|
||||
|
||||
let rect = match ty {
|
||||
ControlType::Text => {
|
||||
let cur = match v {
|
||||
KV::Text(d) => d.text.clone(),
|
||||
@@ -339,7 +339,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
}
|
||||
ui.ctx().data_mut(|d| d.remove::<String>(id));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Color => {
|
||||
let c = v.as_color();
|
||||
@@ -349,7 +349,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
let u = rgba.to_rgba_unmultiplied();
|
||||
out = Some(json!([u[0], u[1], u[2], u[3]]));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Checkbox => {
|
||||
let mut on = v.as_bool();
|
||||
@@ -357,7 +357,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r.changed() {
|
||||
out = Some(json!(on));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Dropdown => {
|
||||
let opts = match &p.ui {
|
||||
@@ -372,7 +372,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
}
|
||||
}
|
||||
});
|
||||
rect = r.response.rect;
|
||||
r.response.rect
|
||||
}
|
||||
ControlType::Point => {
|
||||
let mut a = v.as_vec2();
|
||||
@@ -381,7 +381,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r1.changed() || r2.changed() {
|
||||
out = Some(json!(a));
|
||||
}
|
||||
rect = r1.rect.union(r2.rect);
|
||||
r1.rect.union(r2.rect)
|
||||
}
|
||||
ControlType::Angle => {
|
||||
let mut a = v.as_f64();
|
||||
@@ -389,7 +389,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r.changed() {
|
||||
out = Some(json!(a));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Font => {
|
||||
// Family (from the installed fonts), style and size; the text stays as it is.
|
||||
@@ -421,7 +421,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if changed || r3.changed() {
|
||||
out = serde_json::to_value(&d).ok();
|
||||
}
|
||||
rect = r1.response.rect.union(r3.rect);
|
||||
r1.response.rect.union(r3.rect)
|
||||
}
|
||||
ControlType::Scale => {
|
||||
// One percentage for every axis.
|
||||
@@ -431,7 +431,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r.changed() {
|
||||
out = Some(json!(vec![x; comps.len().max(1)]));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Slider | ControlType::Media => {
|
||||
let mut x = v.as_f64();
|
||||
@@ -442,9 +442,9 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r.changed() {
|
||||
out = Some(json!(x));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
}
|
||||
};
|
||||
app.auto.add(auto, rect, &p.name);
|
||||
out
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ pub fn decode_thumb(text: &str) -> Option<egui::ColorImage> {
|
||||
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();
|
||||
let px = b.as_chunks::<3>().0.iter().map(|c| Color32::from_rgb(c[0], c[1], c[2])).collect();
|
||||
Some(egui::ColorImage::new([THUMB_W, THUMB_H], px))
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,24 @@ pub struct LayerStyleState {
|
||||
pub layer: u64,
|
||||
pub selected: String,
|
||||
pub undo_mark: usize,
|
||||
checkpoint: Option<Checkpoint>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Checkpoint {
|
||||
project: std::sync::Arc<effectcraft_engine::project::Project>,
|
||||
history: effectcraft_engine::history::History,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Checkpoint {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Checkpoint").field("undo_steps", &self.history.undo.len()).finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
fn checkpoint(app: &mut EffectcraftApp) -> Checkpoint {
|
||||
app.session.history.merge_key = None;
|
||||
Checkpoint { project: app.session.project.clone(), history: app.session.history.clone() }
|
||||
}
|
||||
|
||||
/// Open the dialog on the first selected (or given) layer, showing `style` (a style id;
|
||||
@@ -35,7 +53,8 @@ pub fn open(app: &mut EffectcraftApp, params: &Value) -> Result<(), String> {
|
||||
if style != BLENDING && !STYLES.iter().any(|s| s.0 == style) {
|
||||
return Err(format!("unknown layer style `{style}`"));
|
||||
}
|
||||
app.dialog_state.layer_style = LayerStyleState { layer, selected: style, undo_mark: app.session.history.undo.len() };
|
||||
let checkpoint = checkpoint(app);
|
||||
app.dialog_state.layer_style = LayerStyleState { layer, selected: style, undo_mark: app.session.history.undo.len(), checkpoint: Some(checkpoint) };
|
||||
app.dialog = Some(Dialog::LayerStyles);
|
||||
Ok(())
|
||||
}
|
||||
@@ -48,10 +67,12 @@ pub fn route(app: &mut EffectcraftApp, id: &str, params: &Value) -> Result<bool,
|
||||
return Ok(false);
|
||||
}
|
||||
let mark = app.session.history.undo.len();
|
||||
let checkpoint = checkpoint(app);
|
||||
app.session.execute(id, json!({})).map_err(|e| e.to_string())?;
|
||||
open(app, &json!({"style": style}))?;
|
||||
// Cancel also removes the style just added.
|
||||
app.dialog_state.layer_style.undo_mark = mark;
|
||||
app.dialog_state.layer_style.checkpoint = Some(checkpoint);
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@@ -214,13 +235,17 @@ pub fn select(app: &mut EffectcraftApp, style: &str) {
|
||||
|
||||
/// Close the dialog: OK keeps the edits, Cancel undoes everything done since it opened.
|
||||
pub fn finish(app: &mut EffectcraftApp, ok: bool) {
|
||||
if !ok {
|
||||
let mark = app.dialog_state.layer_style.undo_mark;
|
||||
while app.session.history.undo.len() > mark {
|
||||
if !app.session.undo() {
|
||||
break;
|
||||
}
|
||||
if let Some(checkpoint) = app.dialog_state.layer_style.checkpoint.take()
|
||||
&& !ok
|
||||
{
|
||||
let changed = !std::sync::Arc::ptr_eq(&app.session.project, &checkpoint.project);
|
||||
app.session.project = checkpoint.project;
|
||||
app.session.history = checkpoint.history;
|
||||
app.session.sanitize_state();
|
||||
if changed {
|
||||
app.session.bump();
|
||||
}
|
||||
}
|
||||
app.session.history.merge_key = None;
|
||||
app.dialog = None;
|
||||
}
|
||||
|
||||
@@ -189,6 +189,25 @@ pub fn begin_rename(app: &EffectcraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
sort_items(&mut kids, &app.ui.project_sort, app.ui.project_sort_desc);
|
||||
for it in kids {
|
||||
if !q.is_empty() && !it.is_folder() && !it.name.to_lowercase().contains(q) {
|
||||
continue;
|
||||
}
|
||||
out.push((it.id, depth));
|
||||
if it.is_folder() && (app.ui.project_open_folders.contains(&it.id.0) || !q.is_empty()) {
|
||||
walk(app, Some(it.id), depth + 1, q, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut rows = vec![];
|
||||
walk(app, None, 0, &app.ui.project_search.to_lowercase(), &mut rows);
|
||||
rows
|
||||
}
|
||||
|
||||
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let p = ui.painter().clone();
|
||||
@@ -330,22 +349,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.ui.project_hscroll = (hscroll + sresp.drag_delta().x * overflow / (track.width() - tw).max(1.0)).clamp(0.0, overflow);
|
||||
}
|
||||
}
|
||||
let query = app.ui.project_search.to_lowercase();
|
||||
let mut rows: Vec<(ItemId, usize)> = vec![];
|
||||
fn walk(app: &EffectcraftApp, folder: Option<ItemId>, depth: usize, q: &str, out: &mut Vec<(ItemId, usize)>) {
|
||||
let mut kids = app.session.project.children(folder);
|
||||
sort_items(&mut kids, &app.ui.project_sort, app.ui.project_sort_desc);
|
||||
for it in kids {
|
||||
if !q.is_empty() && !it.is_folder() && !it.name.to_lowercase().contains(q) {
|
||||
continue;
|
||||
}
|
||||
out.push((it.id, depth));
|
||||
if it.is_folder() && (app.ui.project_open_folders.contains(&it.id.0) || !q.is_empty()) {
|
||||
walk(app, Some(it.id), depth + 1, q, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(app, None, 0, &query, &mut rows);
|
||||
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()
|
||||
@@ -547,13 +551,24 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.auto.add(&format!("project.item.{}.name", id.0), name_clip, &it.name);
|
||||
let resp = resp.union(nresp);
|
||||
if resp.clicked() {
|
||||
let add = ui.input(|i| i.modifiers.command || i.modifiers.shift);
|
||||
if add {
|
||||
if !app.session.state.project_selection.contains(id) {
|
||||
let m = ui.input(|i| i.modifiers);
|
||||
let anchor_key = egui::Id::new("project-selection-anchor");
|
||||
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))
|
||||
{
|
||||
let b = rows.iter().position(|(i, _)| i == id).unwrap_or(a);
|
||||
app.session.state.project_selection = rows.get(a.min(b)..=a.max(b)).unwrap_or_default().iter().map(|(i, _)| *i).collect();
|
||||
} else if m.command {
|
||||
if app.session.state.project_selection.contains(id) {
|
||||
app.session.state.project_selection.retain(|i| i != id);
|
||||
} else {
|
||||
app.session.state.project_selection.push(*id);
|
||||
}
|
||||
ctx.data_mut(|d| d.insert_temp(anchor_key, *id));
|
||||
} else {
|
||||
app.session.state.project_selection = vec![*id];
|
||||
ctx.data_mut(|d| d.insert_temp(anchor_key, *id));
|
||||
}
|
||||
}
|
||||
// Double-click opens the item, as in After Effects (a comp gets its own Timeline tab and
|
||||
@@ -576,6 +591,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
egui::DragAndDrop::set_payload(&ctx, DragPayload::Item(id.0));
|
||||
}
|
||||
resp.context_menu(|ui| {
|
||||
if ui.button("Delete").clicked() {
|
||||
let items: Vec<u64> = if selected { app.session.state.project_selection.iter().map(|i| i.0).collect() } else { vec![id.0] };
|
||||
actions.push(("project.delete".into(), json!({"items": items})));
|
||||
ui.close();
|
||||
}
|
||||
if matches!(it.kind, ItemKind::Comp(_)) && ui.button("Open Composition").clicked() {
|
||||
actions.push(("comp.open".into(), json!({"comp": id.0})));
|
||||
ui.close();
|
||||
|
||||
@@ -406,6 +406,26 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let rendering = app.session.is_rendering();
|
||||
let available = app.session.exporter.as_ref().map(|e| e.formats()).unwrap_or_default();
|
||||
let mut actions: Vec<(&'static str, Value)> = Vec::new();
|
||||
app.auto.add("renderQueue.drop", rect, "Drop compositions to queue");
|
||||
if !rendering
|
||||
&& let Some(crate::panels::DragPayload::Item(id)) = egui::DragAndDrop::payload::<crate::panels::DragPayload>(ui.ctx()).as_deref()
|
||||
&& app.session.project.comp(effectcraft_engine::project::ItemId(*id)).is_some()
|
||||
&& ui.input(|i| i.pointer.hover_pos()).is_some_and(|pos| rect.contains(pos))
|
||||
{
|
||||
let ids: Vec<u64> = if app.session.state.project_selection.contains(&effectcraft_engine::project::ItemId(*id)) {
|
||||
app.session.state.project_selection.iter().filter(|i| app.session.project.comp(**i).is_some()).map(|i| i.0).collect()
|
||||
} else {
|
||||
vec![*id]
|
||||
};
|
||||
if ui.input(|i| i.pointer.any_released()) {
|
||||
for comp in ids {
|
||||
actions.push(("renderQueue.add", json!({"comp": comp})));
|
||||
}
|
||||
egui::DragAndDrop::clear_payload(ui.ctx());
|
||||
} else {
|
||||
p.rect_stroke(rect.shrink(2.0), 0.0, Stroke::new(2.0, t.accent), StrokeKind::Inside);
|
||||
}
|
||||
}
|
||||
let mut forms: Vec<(RenderQueueItem, String)> = Vec::new();
|
||||
let state_id = egui::Id::new("rq-ui");
|
||||
let (mut open, mut selected): (Vec<u64>, Option<u64>) = ui.data(|d| d.get_temp(state_id).unwrap_or_default());
|
||||
@@ -723,6 +743,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
&& editing.is_none()
|
||||
&& !rendering
|
||||
&& let Some(id) = selected
|
||||
&& app.dialog.is_none()
|
||||
&& ui.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace))
|
||||
&& !ui.ctx().egui_wants_keyboard_input()
|
||||
{
|
||||
|
||||
@@ -428,32 +428,34 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
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 = 470.0;
|
||||
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);
|
||||
// Page list (left, like After Effects).
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(180.0);
|
||||
for p in &all {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(176.0, 24.0), egui::Sense::click());
|
||||
let sel = page == p.id;
|
||||
if sel {
|
||||
ui.painter().rect_filled(r, 3.0, t.accent);
|
||||
} else if resp.hovered() {
|
||||
ui.painter().rect_filled(r, 3.0, t.hover);
|
||||
egui::ScrollArea::vertical().id_salt("settings-pages").max_height(body_h).auto_shrink([false, false]).show(ui, |ui| {
|
||||
for p in &all {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(176.0, 24.0), egui::Sense::click());
|
||||
let sel = page == p.id;
|
||||
if sel {
|
||||
ui.painter().rect_filled(r, 3.0, t.accent);
|
||||
} else if resp.hovered() {
|
||||
ui.painter().rect_filled(r, 3.0, t.hover);
|
||||
}
|
||||
ui.painter().text(
|
||||
r.left_center() + vec2(10.0, 0.0),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
p.title,
|
||||
Tokens::ui(12.5),
|
||||
if sel { Color32::WHITE } else { t.text },
|
||||
);
|
||||
app.auto.add(&format!("settings.page.{}", p.id), r, p.title);
|
||||
if resp.clicked() {
|
||||
page = p.id.to_string();
|
||||
}
|
||||
}
|
||||
ui.painter().text(
|
||||
r.left_center() + vec2(10.0, 0.0),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
p.title,
|
||||
Tokens::ui(12.5),
|
||||
if sel { Color32::WHITE } else { t.text },
|
||||
);
|
||||
app.auto.add(&format!("settings.page.{}", p.id), r, p.title);
|
||||
if resp.clicked() {
|
||||
page = p.id.to_string();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
ui.vertical(|ui| {
|
||||
|
||||
@@ -37,7 +37,7 @@ fn thumb(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, budget: &mut b
|
||||
}
|
||||
*budget = false;
|
||||
let tex = templates::thumbnail(&app.session, id).ok().and_then(|t| templates::decode_thumb(&t)).map(|rgb| {
|
||||
let px = rgb.chunks_exact(3).map(|c| Color32::from_rgb(c[0], c[1], c[2])).collect();
|
||||
let px = rgb.as_chunks::<3>().0.iter().map(|c| Color32::from_rgb(c[0], c[1], c[2])).collect();
|
||||
ctx.load_texture(format!("template-thumb-{id}"), egui::ColorImage::new([THUMB_W, THUMB_H], px), egui::TextureOptions::LINEAR)
|
||||
});
|
||||
app.template_thumbs.insert(id.to_string(), tex.clone());
|
||||
|
||||
@@ -1205,6 +1205,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// Registered before the rows so keys, bars and editors on top of it get the pointer first.
|
||||
let empty_rect = if graph_on { Rect::NOTHING } else { Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max) };
|
||||
let empty = ui.interact(empty_rect, egui::Id::new("tl-graph-bg"), Sense::click_and_drag());
|
||||
let outline_rect = Rect::from_min_max(rows_rect.min, pos2(graph_x0 - 1.0, rows_rect.max.y));
|
||||
let outline_empty = ui.interact(outline_rect, egui::Id::new("tl-layer-bg"), Sense::click_and_drag());
|
||||
app.auto.add("timeline.layerMarquee", outline_rect, "Drag empty outline to select layers");
|
||||
let mut hit_rows: Vec<(Rect, Row)> = vec![];
|
||||
for (ri, row) in rows.iter().enumerate() {
|
||||
// Outline widgets never spill into the time graph (narrow timelines).
|
||||
@@ -1336,7 +1339,28 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.auto.add(&format!("timeline.layer.{}.row", layer.id.0), left, &layer.name);
|
||||
if row_resp.clicked() && !locked {
|
||||
let m = ui.input(|i| i.modifiers);
|
||||
actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "toggle": m.command, "add": m.shift})));
|
||||
let anchor_key = egui::Id::new(("timeline-selection-anchor", cid.0));
|
||||
let anchor = ctx.data(|d| d.get_temp::<LayerId>(anchor_key)).or_else(|| selected.first().copied());
|
||||
let range = if m.shift {
|
||||
anchor.and_then(|a| comp.layers.iter().position(|l| l.id == a)).map(|a| {
|
||||
let b = comp.layers.iter().position(|l| l.id == layer.id).unwrap_or(a);
|
||||
comp.layers
|
||||
.get(a.min(b)..=a.max(b))
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.filter(|l| !l.switches.locked && rows.iter().any(|r| r.layer == l.id))
|
||||
.map(|l| l.id.0)
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(layers) = range {
|
||||
actions.push(("layer.select".into(), json!({"layers": layers})));
|
||||
} else {
|
||||
actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "toggle": m.command})));
|
||||
ctx.data_mut(|d| d.insert_temp(anchor_key, layer.id));
|
||||
}
|
||||
}
|
||||
if row_resp.double_clicked() {
|
||||
match &layer.source {
|
||||
@@ -2015,6 +2039,29 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
ui.set_clip_rect(full_clip);
|
||||
if outline_empty.clicked() && !ui.input(|i| i.modifiers.shift || i.modifiers.command) {
|
||||
actions.push(("layer.select".into(), json!({"layers": []})));
|
||||
}
|
||||
if let (Some(start), Some(end)) = (ctx.input(|i| i.pointer.press_origin()), outline_empty.interact_pointer_pos())
|
||||
&& outline_empty.dragged()
|
||||
{
|
||||
let box_rect = Rect::from_two_pos(start, end).intersect(outline_rect);
|
||||
lp.rect_filled(box_rect, 0.0, t.accent.gamma_multiply(0.12));
|
||||
lp.rect_stroke(box_rect, 0.0, Stroke::new(1.0, t.accent), StrokeKind::Inside);
|
||||
ctx.data_mut(|d| d.insert_temp(egui::Id::new("tl-layer-box"), box_rect));
|
||||
}
|
||||
if outline_empty.drag_stopped()
|
||||
&& let Some(box_rect) = ctx.data(|d| d.get_temp::<Rect>(egui::Id::new("tl-layer-box")))
|
||||
{
|
||||
ctx.data_mut(|d| d.remove::<Rect>(egui::Id::new("tl-layer-box")));
|
||||
let layers: Vec<u64> = hit_rows
|
||||
.iter()
|
||||
.filter(|(r, row)| matches!(row.kind, RowKind::Layer) && r.intersects(box_rect))
|
||||
.filter(|(_, row)| comp.layer(row.layer).is_some_and(|l| !l.switches.locked))
|
||||
.map(|(_, row)| row.layer.0)
|
||||
.collect();
|
||||
actions.push(("layer.select".into(), json!({"layers": layers, "add": ui.input(|i| i.modifiers.shift || i.modifiers.command)})));
|
||||
}
|
||||
// Pick whips: a line follows the pointer; releasing over a row links to it.
|
||||
if let Some((kind, src_layer, src_prop, start)) = ctx.data(|d| d.get_temp::<PickWhip>(pick_whip_id())) {
|
||||
let ptr = ctx.input(|i| i.pointer.latest_pos()).unwrap_or(start);
|
||||
@@ -2287,6 +2334,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
UiAct::EndMerge => app.session.history.merge_key = None,
|
||||
}
|
||||
}
|
||||
if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") {
|
||||
app.ui.viewer.property_interacting = true;
|
||||
ctx.request_repaint();
|
||||
}
|
||||
for (id, params) in actions {
|
||||
if id == "__endMerge" {
|
||||
app.session.history.merge_key = None;
|
||||
@@ -2540,63 +2591,66 @@ fn zoom_at(app: &mut EffectcraftApp, comp: &Comp, tm: TMap, k: f64, at_x: f32) {
|
||||
}
|
||||
|
||||
fn layer_context_menu(resp: &egui::Response, layer: &Layer, actions: &mut Vec<(String, serde_json::Value)>) {
|
||||
resp.context_menu(|ui| {
|
||||
let id = layer.id.0;
|
||||
let mut item = |ui: &mut egui::Ui, label: &str, cmd: &str, params: serde_json::Value| {
|
||||
if ui.button(label).clicked() {
|
||||
actions.push(("layer.select".into(), json!({"layers": [id]})));
|
||||
actions.push((cmd.into(), params));
|
||||
ui.close();
|
||||
}
|
||||
};
|
||||
ui.menu_button("New", |ui| {
|
||||
item(ui, "Text", "layer.newText", json!({"text": "Text"}));
|
||||
item(ui, "Solid…", "app.solidSettings", json!({}));
|
||||
item(ui, "Light…", "layer.newLight", json!({}));
|
||||
item(ui, "Camera…", "layer.newCamera", json!({}));
|
||||
item(ui, "Null Object", "layer.newNull", json!({}));
|
||||
item(ui, "Shape Layer", "layer.newShape", json!({"kind": "none"}));
|
||||
item(ui, "Adjustment Layer", "layer.newAdjustment", json!({}));
|
||||
});
|
||||
item(ui, "Layer Settings…", "layer.settings", json!({}));
|
||||
ui.separator();
|
||||
ui.menu_button("Masks", |ui| {
|
||||
item(ui, "New Mask", "layer.addMask", json!({"layer": id}));
|
||||
});
|
||||
ui.menu_button("Transform", |ui| {
|
||||
item(ui, "Reset", "layer.transform", json!({"layers": [id], "op": "reset"}));
|
||||
item(ui, "Center In View", "layer.transform", json!({"layers": [id], "op": "center"}));
|
||||
item(ui, "Fit to Comp", "layer.transform", json!({"layers": [id], "op": "fit"}));
|
||||
item(ui, "Flip Horizontal", "layer.transform", json!({"layers": [id], "op": "flipH"}));
|
||||
item(ui, "Flip Vertical", "layer.transform", json!({"layers": [id], "op": "flipV"}));
|
||||
});
|
||||
ui.menu_button("Time", |ui| {
|
||||
item(ui, "Enable Time Remapping", "layer.enableTimeRemap", json!({"layers": [id]}));
|
||||
item(ui, "Time-Reverse Layer", "layer.timeReverse", json!({"layers": [id]}));
|
||||
item(ui, "Time Stretch…", "layer.timeStretch", json!({}));
|
||||
item(ui, "Freeze Frame", "layer.freezeFrame", json!({"layers": [id]}));
|
||||
item(ui, "Freeze on Last Frame", "layer.freezeOnLastFrame", json!({"layers": [id]}));
|
||||
});
|
||||
ui.menu_button("Blending Mode", |ui| {
|
||||
for m in BlendMode::ALL {
|
||||
item(ui, m.label(), "layer.setBlendMode", json!({"layers": [id], "mode": m.label()}));
|
||||
if m.ends_group() {
|
||||
ui.separator();
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.menu_button("Arrange", |ui| {
|
||||
item(ui, "Bring Layer to Front", "layer.arrange", json!({"layers": [id], "to": "front"}));
|
||||
item(ui, "Bring Layer Forward", "layer.arrange", json!({"layers": [id], "to": "forward"}));
|
||||
item(ui, "Send Layer Backward", "layer.arrange", json!({"layers": [id], "to": "backward"}));
|
||||
item(ui, "Send Layer to Back", "layer.arrange", json!({"layers": [id], "to": "back"}));
|
||||
});
|
||||
ui.separator();
|
||||
item(ui, "Pre-compose…", "layer.precompose", json!({"layers": [id]}));
|
||||
item(ui, "Duplicate", "edit.duplicate", json!({"layers": [id]}));
|
||||
item(ui, "Split Layer", "edit.splitLayer", json!({"layers": [id]}));
|
||||
item(ui, "Delete", "edit.clear", json!({"layers": [id]}));
|
||||
resp.context_menu(|ui| layer_menu(ui, &[layer.id.0], actions));
|
||||
}
|
||||
|
||||
/// Shared layer actions for Timeline rows and Composition context menus.
|
||||
pub(crate) fn layer_menu(ui: &mut egui::Ui, layers: &[u64], actions: &mut Vec<(String, serde_json::Value)>) {
|
||||
let Some(&id) = layers.first() else { return };
|
||||
let mut item = |ui: &mut egui::Ui, label: &str, cmd: &str, params: serde_json::Value| {
|
||||
if ui.button(label).clicked() {
|
||||
actions.push(("layer.select".into(), json!({"layers": layers})));
|
||||
actions.push((cmd.into(), params));
|
||||
ui.close();
|
||||
}
|
||||
};
|
||||
ui.menu_button("New", |ui| {
|
||||
item(ui, "Text", "layer.newText", json!({"text": "Text"}));
|
||||
item(ui, "Solid…", "app.solidSettings", json!({}));
|
||||
item(ui, "Light…", "layer.newLight", json!({}));
|
||||
item(ui, "Camera…", "layer.newCamera", json!({}));
|
||||
item(ui, "Null Object", "layer.newNull", json!({}));
|
||||
item(ui, "Shape Layer", "layer.newShape", json!({"kind": "none"}));
|
||||
item(ui, "Adjustment Layer", "layer.newAdjustment", json!({}));
|
||||
});
|
||||
item(ui, "Layer Settings…", "layer.settings", json!({}));
|
||||
ui.separator();
|
||||
ui.menu_button("Masks", |ui| {
|
||||
item(ui, "New Mask", "layer.addMask", json!({"layer": id}));
|
||||
});
|
||||
ui.menu_button("Transform", |ui| {
|
||||
item(ui, "Reset", "layer.transform", json!({"layers": layers, "op": "reset"}));
|
||||
item(ui, "Center In View", "layer.transform", json!({"layers": layers, "op": "center"}));
|
||||
item(ui, "Fit to Comp", "layer.transform", json!({"layers": layers, "op": "fit"}));
|
||||
item(ui, "Flip Horizontal", "layer.transform", json!({"layers": layers, "op": "flipH"}));
|
||||
item(ui, "Flip Vertical", "layer.transform", json!({"layers": layers, "op": "flipV"}));
|
||||
});
|
||||
ui.menu_button("Time", |ui| {
|
||||
item(ui, "Enable Time Remapping", "layer.enableTimeRemap", json!({"layers": layers}));
|
||||
item(ui, "Time-Reverse Layer", "layer.timeReverse", json!({"layers": layers}));
|
||||
item(ui, "Time Stretch…", "layer.timeStretch", json!({}));
|
||||
item(ui, "Freeze Frame", "layer.freezeFrame", json!({"layers": layers}));
|
||||
item(ui, "Freeze on Last Frame", "layer.freezeOnLastFrame", json!({"layers": layers}));
|
||||
});
|
||||
ui.menu_button("Blending Mode", |ui| {
|
||||
for m in BlendMode::ALL {
|
||||
item(ui, m.label(), "layer.setBlendMode", json!({"layers": layers, "mode": m.label()}));
|
||||
if m.ends_group() {
|
||||
ui.separator();
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.menu_button("Arrange", |ui| {
|
||||
item(ui, "Bring Layer to Front", "layer.arrange", json!({"layers": layers, "to": "front"}));
|
||||
item(ui, "Bring Layer Forward", "layer.arrange", json!({"layers": layers, "to": "forward"}));
|
||||
item(ui, "Send Layer Backward", "layer.arrange", json!({"layers": layers, "to": "backward"}));
|
||||
item(ui, "Send Layer to Back", "layer.arrange", json!({"layers": layers, "to": "back"}));
|
||||
});
|
||||
ui.separator();
|
||||
item(ui, "Pre-compose…", "layer.precompose", json!({"layers": layers}));
|
||||
item(ui, "Duplicate", "edit.duplicate", json!({"layers": layers}));
|
||||
item(ui, "Split Layer", "edit.splitLayer", json!({"layers": layers}));
|
||||
item(ui, "Delete", "edit.clear", json!({"layers": layers}));
|
||||
}
|
||||
|
||||
fn fmt_num(v: f64, d: usize) -> String {
|
||||
|
||||
@@ -292,6 +292,29 @@ fn point_in_quad(p: [f64; 2], q: &[[f64; 2]; 4]) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Separating-axis test: a marquee may cross a layer without containing any corner.
|
||||
fn quad_intersects_box(q: &[[f64; 2]; 4], a: [f64; 2], b: [f64; 2]) -> bool {
|
||||
if q.iter().flatten().chain(a.iter()).chain(b.iter()).any(|v| !v.is_finite()) {
|
||||
return false;
|
||||
}
|
||||
let lo = [a[0].min(b[0]), a[1].min(b[1])];
|
||||
let hi = [a[0].max(b[0]), a[1].max(b[1])];
|
||||
let rect = [lo, [hi[0], lo[1]], hi, [lo[0], hi[1]]];
|
||||
let axes = [[1.0, 0.0], [0.0, 1.0]].into_iter().chain((0..4).map(|i| {
|
||||
let j = (i + 1) % 4;
|
||||
[q[j][1] - q[i][1], q[i][0] - q[j][0]]
|
||||
}));
|
||||
for axis in axes {
|
||||
let project = |p: &[f64; 2]| p[0] * axis[0] + p[1] * axis[1];
|
||||
let (qmin, qmax) = q.iter().map(project).fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), v| (lo.min(v), hi.max(v)));
|
||||
let (rmin, rmax) = rect.iter().map(project).fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), v| (lo.min(v), hi.max(v)));
|
||||
if qmax < rmin || rmax < qmin {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Parent-space linear inverse (to convert a comp-space drag delta into a position delta).
|
||||
fn parent_inverse(ctx: &EvalCtx, layer: &Layer) -> Mat3 {
|
||||
match layer.parent.and_then(|p| ctx.comp.layer(p)) {
|
||||
@@ -860,6 +883,47 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
|
||||
// Interaction.
|
||||
let resp = ui.interact(area, egui::Id::new("viewer-interact"), Sense::click_and_drag());
|
||||
let menu_hits_id = egui::Id::new(("viewer-menu-hits", cid.0));
|
||||
if resp.secondary_clicked()
|
||||
&& let Some(pos) = resp.interact_pointer_pos()
|
||||
{
|
||||
// Picking an already selected layer preserves the group; an unselected hit
|
||||
// becomes the target, using the same visible/unlocked hit test as left-click.
|
||||
pick(app, &ectx, map.to_comp(pos), false);
|
||||
let point = map.to_comp(pos);
|
||||
let hits: Vec<(u64, String)> = selectable_layers(&comp, time)
|
||||
.filter(|l| layer_quad(&ectx, l).is_some_and(|(_, q, _)| point_in_quad(point, &q)))
|
||||
.map(|l| (l.id.0, l.name.clone()))
|
||||
.collect();
|
||||
ui.data_mut(|d| d.insert_temp(menu_hits_id, hits));
|
||||
}
|
||||
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();
|
||||
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() {
|
||||
ui.menu_button("Select", |ui| {
|
||||
for (id, name) in &hits {
|
||||
if ui.button(name).clicked() {
|
||||
context_actions.push(("layer.select".to_owned(), serde_json::json!({"layers":[id]})));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
}
|
||||
if context_layers.is_empty() {
|
||||
ui.label("No unlocked layer selected");
|
||||
} else {
|
||||
super::timeline::layer_menu(ui, &context_layers, &mut context_actions);
|
||||
}
|
||||
});
|
||||
for (id, params) in context_actions {
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
let gid = egui::Id::new("viewer-gesture");
|
||||
if let Some(hp) = resp.hover_pos() {
|
||||
app.pointer_comp = Some({
|
||||
@@ -1106,7 +1170,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
} else {
|
||||
// With path vertices on screen the marquee selects vertices (layers stay
|
||||
// selected); otherwise it starts from a clean selection.
|
||||
if !vertex_hits.iter().any(|h| h.tangent.is_none()) {
|
||||
if !mods.shift && !vertex_hits.iter().any(|h| h.tangent.is_none()) {
|
||||
let _ = app.session.execute("edit.deselectAll", json!({}));
|
||||
}
|
||||
Some(Gesture::Marquee { start: press })
|
||||
@@ -1353,13 +1417,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
Gesture::Marquee { start } => {
|
||||
let a = map.to_comp(start);
|
||||
let b = map.to_comp(pos);
|
||||
let (x0, x1) = (a[0].min(b[0]), a[0].max(b[0]));
|
||||
let (y0, y1) = (a[1].min(b[1]), a[1].max(b[1]));
|
||||
let hits: Vec<u64> = selectable_layers(&comp, time)
|
||||
.filter(|l| layer_quad(&ectx, l).is_some_and(|(_, q, _)| q.iter().any(|p| p[0] >= x0 && p[0] <= x1 && p[1] >= y0 && p[1] <= y1)))
|
||||
.filter(|l| layer_quad(&ectx, l).is_some_and(|(_, q, _)| quad_intersects_box(&q, a, b)))
|
||||
.map(|l| l.id.0)
|
||||
.collect();
|
||||
let _ = app.session.execute("layer.select", json!({"layers": hits}));
|
||||
let _ = app.session.execute("layer.select", json!({"layers": hits, "toggle": mods.shift}));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ pub fn hook(
|
||||
}
|
||||
|
||||
// ---- keyboard
|
||||
if app.session.state.text_edit.is_some() {
|
||||
if app.session.state.text_edit.is_some() && app.dialog.is_none() && ui.is_enabled() {
|
||||
ui.memory_mut(|m| {
|
||||
m.set_focus_lock_filter(focus_id(), egui::EventFilter { tab: true, horizontal_arrows: true, vertical_arrows: true, escape: true });
|
||||
});
|
||||
|
||||
@@ -711,7 +711,9 @@ pub(crate) fn bottom_bar(app: &mut EffectcraftApp, ui: &mut egui::Ui, bar: Rect,
|
||||
app.auto.add("viewer.timecode", tr, "Current time");
|
||||
// Right: render time.
|
||||
let ms = app.frames.last_ms.lock().map(|v| *v).unwrap_or(0.0);
|
||||
p.text(pos2(bar.max.x - 10.0, cy), Align2::RIGHT_CENTER, format!("{ms:.0} ms"), Tokens::ui(11.0), t.text_faint);
|
||||
if tr.max.x + 50.0 < bar.max.x {
|
||||
p.text(pos2(bar.max.x - 10.0, cy), Align2::RIGHT_CENTER, format!("{ms:.0} ms"), Tokens::ui(11.0), t.text_faint);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user