Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge branch 'fix/f3': community issue fixes

Claude09b3dbaad98e
diff --cc crates/ui-egui/src/panels/essential.rs
index ce6121a76,2496b2381..048b0b58d
--- a/crates/ui-egui/src/panels/essential.rs
+++ b/crates/ui-egui/src/panels/essential.rs
@@@ -374,10 -375,41 +374,41 @@@ fn value_widget(app: &mut EffectcraftAp
});
r.response.rect
}
+ // Scale keeps its Constrain Proportions link, on by default, as in After Effects (#338).
+ // The link is the property's own, shared with the Timeline's chain link.
+ ControlType::Point if p.match_id == "scale" && matches!(p.ui, ParamUi::Percent) => {
+ let comps = v.components();
+ let linked = !app.ui.timeline.unlinked.contains(&p.uid);
+ let (lr, link) = ui.allocate_exact_size(egui::vec2(14.0, 14.0), egui::Sense::click());
+ let t = app.tokens;
+ crate::icons::paint(ui.painter(), lr, crate::icons::Icon::Link, if linked { t.accent } else { t.text_faint });
+ let link = link.on_hover_text(tr("Constrain Proportions"));
+ app.auto.add(&format!("{auto}.link"), lr, "Constrain Proportions");
+ if link.clicked() && !app.ui.timeline.unlinked.remove(&p.uid) {
+ app.ui.timeline.unlinked.insert(p.uid);
+ }
+ let mut rect = lr;
+ for (d, &old) in comps.iter().enumerate() {
+ let mut x = old;
+ let r = ui.add(egui::DragValue::new(&mut x).speed(0.5).suffix(if d + 1 == comps.len() { "%" } else { "" }).max_decimals(1));
+ app.auto.add(&format!("{auto}.{d}"), r.rect, &p.name);
+ rect = rect.union(r.rect);
+ if r.changed() {
+ // Alt edits one value of a linked pair, as in the Timeline.
+ let next = if linked && !ui.input(|i| i.modifiers.alt) {
+ widgets::constrained(&comps, d, x)
+ } else {
+ comps.iter().enumerate().map(|(e, &c)| if e == d { x } else { c }).collect()
+ };
+ out = Some(json!(next));
+ }
+ }
+ rect
+ }
ControlType::Point => {
let mut a = v.as_vec2();
- let r1 = ui.add(egui::DragValue::new(&mut a[0]).speed(1.0).max_decimals(1));
- let r2 = ui.add(egui::DragValue::new(&mut a[1]).speed(1.0).max_decimals(1));
+ let r1 = ui.add(crate::widgets::drag_value(egui::DragValue::new(&mut a[0]).speed(1.0).max_decimals(1)));
+ let r2 = ui.add(crate::widgets::drag_value(egui::DragValue::new(&mut a[1]).speed(1.0).max_decimals(1)));
if r1.changed() || r2.changed() {
out = Some(json!(a));
}
diff --cc crates/ui-egui/src/widgets.rs
index ea76f06b1,fdb8287b4..364a2472d
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@@ -568,26 -560,22 +568,46 @@@ pub fn open_popup(ui: &Ui, id: egui::Id
ui.data_mut(|d| d.insert_temp(id.with("open"), true));
}
+ /// Linked values after component `d` of `c` became `v`: the others scale by the same ratio
+ /// (Constrain Proportions); from 0 the others that are 0 too follow the value.
+ pub(crate) fn constrained(c: &[f64], d: usize, v: f64) -> Vec<f64> {
+ let Some(&old) = c.get(d) else { return c.to_vec() };
+ c.iter()
+ .enumerate()
+ .map(|(e, &x)| {
+ if e == d {
+ v
+ } else if old.abs() > 1e-9 {
+ x * v / old
+ } else if x.abs() <= 1e-9 {
+ v
+ } else {
+ x
+ }
+ })
+ .collect()
+ }
++
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// #581: a field's text edit fills it, so its text and hint sit on the field's middle line
+ /// (it was a row at the top of the field, its text high).
+ #[test]
+ fn field_text_is_vertically_centred() {
+ let ctx = egui::Context::default();
+ let t = Tokens::for_kind(Default::default());
+ for h in [22.0, 26.0, 30.0] {
+ let field = Rect::from_min_size(pos2(20.0, 40.0), vec2(220.0, h));
+ let mut text = String::new();
+ let mut got = None;
+ let mut out = ctx.run_ui(Default::default(), |ui| {
+ got = Some(search_field(ui, field, &mut text, "Filter recent files", &t).rect);
+ });
+ out.textures_delta.clear();
+ let r = got.expect("the field was drawn");
+ assert!((r.center().y - field.center().y).abs() < 0.5 && r.height() >= h - 2.5, "{h}: {r:?} in {field:?}");
+ }
+ }
+}