forge
Explore
Log in

Don't you dare go Hollow

✨ Effect keys get the easing picker and curve editor; the curve editor takes any key target

Browse files at this commit

91224b6e4ed804845b6618d72120c042153d545eAhmet Kaan GümüşParent: 29cb69f
crates/app/src/main.rsmodified+4 -4
@@ -1304,10 +1304,10 @@ struct Player {
1304 opacity_drag: bool,1304 opacity_drag: bool,
1305 /// The opacity row's bar, recorded at prepaint like the transform bars.1305 /// The opacity row's bar, recorded at prepaint like the transform bars.
1306 opacity_bar: Rc<Cell<Bounds<Pixels>>>,1306 opacity_bar: Rc<Cell<Bounds<Pixels>>>,
1307- /// Each easing curve editor's box, by key kind (placement, opacity, colour), recorded at1307+ /// Each easing curve editor's box, by the target it edits, recorded at prepaint: a press and
1308- /// prepaint: a press and a drag on an editor are read against its own box. The transform1308+ /// a drag on an editor are read against its own box. The transform card can show two editors
1309- /// card can show two editors at once, one per key row.1309+ /// at once, one per key row, and an effect's editor sits beside them.
1310- curve_bounds: [Rc<Cell<Bounds<Pixels>>>; 3],1310+ curve_bounds: std::cell::RefCell<HashMap<ui::cards::curve::CurveTarget, Rc<Cell<Bounds<Pixels>>>>>,
1311 /// A curve handle is held: its draft curve, written to the key when the button comes up.1311 /// A curve handle is held: its draft curve, written to the key when the button comes up.
1312 curve_drag: Option<ui::cards::curve::CurveDrag>,1312 curve_drag: Option<ui::cards::curve::CurveDrag>,
1313 /// Each slider's box, recorded at prepaint -- [`Self::color_bars`]' own1313 /// Each slider's box, recorded at prepaint -- [`Self::color_bars`]' own
crates/app/src/player/effects.rsmodified+25 -0
@@ -217,6 +217,31 @@ impl Player {
217 }217 }
218 }218 }
219 219
220+ /// The ease of the key the effect at stack position `slot` holds at the playhead, `None` with
221+ /// no key there.
222+ pub(crate) fn effect_key_ease_here(&self, slot: usize) -> Option<KeyEase> {
223+ let at = self.effects_src()?;
224+ let shown = self.effects_shown();
225+ let effect = shown.get(slot)?;
226+ effect.keys.iter().find(|k| k.at == at).map(|k| k.ease)
227+ }
228+
229+ /// Sets the ease of the key the effect at stack position `slot` holds at the playhead, as one
230+ /// undo step. Nothing changes with no key there, which the easing row shows as disabled.
231+ pub(crate) fn set_effect_key_ease_here(&mut self, slot: usize, ease: KeyEase, cx: &mut Context<Self>) {
232+ let Some(at) = self.effects_src() else {
233+ return cx.notify();
234+ };
235+ let mut stack = self.effects_shown();
236+ if let Some(e) = stack.get_mut(slot)
237+ && let Ok(pos) = e.keys.binary_search_by_key(&at, |k| k.at)
238+ {
239+ e.keys[pos].ease = ease;
240+ self.write_effects(stack, cx);
241+ }
242+ cx.notify();
243+ }
244+
220 /// Follows the mask at stack position `slot` of the open clip from the playhead to the245 /// Follows the mask at stack position `slot` of the open clip from the playhead to the
221 /// clip's end, or back to its start ([`engine::PlaybackSession::track_mask_start`]). The246 /// clip's end, or back to its start ([`engine::PlaybackSession::track_mask_start`]). The
222 /// keys land when the track ends ([`Self::poll_tracks`]).247 /// keys land when the track ends ([`Self::poll_tracks`]).
crates/app/src/ui/cards/curve.rsmodified+48 -14
@@ -20,10 +20,24 @@ const CURVE_STEPS: usize = 48;
20 /// A handle's radius in pixels.20 /// A handle's radius in pixels.
21 const HANDLE_R: f32 = 5.;21 const HANDLE_R: f32 = 5.;
22 22
23+/// Which key's ease a curve editor reads and writes. Each editor on screen has its own target,
24+/// so each reads its own box and its own drag.
25+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
26+pub(crate) enum CurveTarget {
27+ /// The key of this kind on the playhead of the open card's clip.
28+ Key(KeyKind),
29+ /// The key on the playhead of the effect at this stack slot of the open clip.
30+ Effect(usize),
31+ /// A title's key, by title index. No title key takes an ease yet, so a drag on this target
32+ /// is read but never written: a later change wires it up in `end_curve_drag`.
33+ #[allow(dead_code)]
34+ Title(usize),
35+}
36+
23 /// A handle being dragged: the key it belongs to, which control point it is, and the curve it37 /// A handle being dragged: the key it belongs to, which control point it is, and the curve it
24 /// has reached so far.38 /// has reached so far.
25 pub(crate) struct CurveDrag {39 pub(crate) struct CurveDrag {
26- pub(crate) kind: KeyKind,40+ pub(crate) target: CurveTarget,
27 /// `0` for the control point near the start of the curve, `1` for the one near its end.41 /// `0` for the control point near the start of the curve, `1` for the one near its end.
28 pub(crate) handle: usize,42 pub(crate) handle: usize,
29 pub(crate) draft: Bezier,43 pub(crate) draft: Bezier,
@@ -86,11 +100,11 @@ fn paint_handle(window: &mut Window, centre: Point<Pixels>, colour: Rgba) {
86 ));100 ));
87 }101 }
88 102
89-/// The curve editor for the key of `kind` whose ease is `shown`. `id` names it, and `bounds`103+/// The curve editor for the ease of `target` as `shown`. `id` names it, and `bounds` receives its
90-/// receives its box at prepaint, which the press and the drag are read against.104+/// box at prepaint, which the press and the drag are read against.
91 pub(super) fn curve_editor(105 pub(super) fn curve_editor(
92 id: impl Into<gpui::ElementId>,106 id: impl Into<gpui::ElementId>,
93- kind: KeyKind,107+ target: CurveTarget,
94 shown: Bezier,108 shown: Bezier,
95 bounds: Rc<Cell<Bounds<Pixels>>>,109 bounds: Rc<Cell<Bounds<Pixels>>>,
96 cx: &mut Context<Player>,110 cx: &mut Context<Player>,
@@ -138,31 +152,46 @@ pub(super) fn curve_editor(
138 .cursor_pointer()152 .cursor_pointer()
139 .on_mouse_down(153 .on_mouse_down(
140 MouseButton::Left,154 MouseButton::Left,
141- cx.listener(move |this, event: &MouseDownEvent, _, cx| this.press_curve(kind, event.position, cx)),155+ cx.listener(move |this, event: &MouseDownEvent, _, cx| this.press_curve(target, event.position, cx)),
142 )156 )
143 .child(paint)157 .child(paint)
144 .into_any_element()158 .into_any_element()
145 }159 }
146 160
147 impl Player {161 impl Player {
162+ /// The ease the target's key on the playhead holds, `None` with no key there. A title takes
163+ /// no ease yet, so its target has none.
164+ pub(crate) fn ease_here(&self, target: CurveTarget) -> Option<KeyEase> {
165+ match target {
166+ CurveTarget::Key(kind) => self.key_here(kind),
167+ CurveTarget::Effect(slot) => self.effect_key_ease_here(slot),
168+ CurveTarget::Title(_) => None,
169+ }
170+ }
171+
172+ /// The box of the editor for `target`, made on first use and recorded at prepaint.
173+ pub(crate) fn curve_bounds_for(&self, target: CurveTarget) -> Rc<Cell<Bounds<Pixels>>> {
174+ self.curve_bounds.borrow_mut().entry(target).or_default().clone()
175+ }
176+
148 /// A press on the editor takes the handle nearer to it and moves that handle to the press.177 /// A press on the editor takes the handle nearer to it and moves that handle to the press.
149 /// Nothing starts unless the key on the playhead has a custom ease.178 /// Nothing starts unless the key on the playhead has a custom ease.
150- pub(crate) fn press_curve(&mut self, kind: KeyKind, at: Point<Pixels>, cx: &mut Context<Self>) {179+ pub(crate) fn press_curve(&mut self, target: CurveTarget, at: Point<Pixels>, cx: &mut Context<Self>) {
151- let Some(KeyEase::Bezier(shown)) = self.key_here(kind) else {180+ let Some(KeyEase::Bezier(shown)) = self.ease_here(target) else {
152 return;181 return;
153 };182 };
154- let Some(unit) = unit_point(at, self.curve_bounds[super::keys::kind_id(kind)].get()) else {183+ let Some(unit) = unit_point(at, self.curve_bounds_for(target).get()) else {
155 return;184 return;
156 };185 };
157 let handle = nearest_handle(shown, unit);186 let handle = nearest_handle(shown, unit);
158- self.curve_drag = Some(CurveDrag { kind, handle, draft: shown });187+ self.curve_drag = Some(CurveDrag { target, handle, draft: shown });
159 self.drag_curve(at, cx);188 self.drag_curve(at, cx);
160 }189 }
161 190
162 /// Moves the held handle to the pointer. The draft is drawn until the button comes up.191 /// Moves the held handle to the pointer. The draft is drawn until the button comes up.
163 pub(crate) fn drag_curve(&mut self, at: Point<Pixels>, cx: &mut Context<Self>) {192 pub(crate) fn drag_curve(&mut self, at: Point<Pixels>, cx: &mut Context<Self>) {
164- let Some(kind) = self.curve_drag.as_ref().map(|d| d.kind) else { return cx.notify() };193+ let Some(target) = self.curve_drag.as_ref().map(|d| d.target) else { return cx.notify() };
165- let unit = unit_point(at, self.curve_bounds[super::keys::kind_id(kind)].get());194+ let unit = unit_point(at, self.curve_bounds_for(target).get());
166 if let (Some(unit), Some(drag)) = (unit, self.curve_drag.as_mut())195 if let (Some(unit), Some(drag)) = (unit, self.curve_drag.as_mut())
167 && let Some(draft) = moved(drag.draft, drag.handle, unit)196 && let Some(draft) = moved(drag.draft, drag.handle, unit)
168 {197 {
@@ -171,12 +200,17 @@ impl Player {
171 cx.notify();200 cx.notify();
172 }201 }
173 202
174- /// Ends the drag where the button came up: the draft is written to the key on the playhead203+ /// Ends the drag where the button came up: the draft is written to the target's key on the
175- /// as one undo step.204+ /// playhead as one undo step. A title's draft is dropped for now.
176 pub(crate) fn end_curve_drag(&mut self, at: Point<Pixels>, cx: &mut Context<Self>) {205 pub(crate) fn end_curve_drag(&mut self, at: Point<Pixels>, cx: &mut Context<Self>) {
177 self.drag_curve(at, cx);206 self.drag_curve(at, cx);
178 if let Some(drag) = self.curve_drag.take() {207 if let Some(drag) = self.curve_drag.take() {
179- self.set_key_ease_here(drag.kind, KeyEase::Bezier(drag.draft), cx);208+ let ease = KeyEase::Bezier(drag.draft);
209+ match drag.target {
210+ CurveTarget::Key(kind) => self.set_key_ease_here(kind, ease, cx),
211+ CurveTarget::Effect(slot) => self.set_effect_key_ease_here(slot, ease, cx),
212+ CurveTarget::Title(_) => {}
213+ }
180 }214 }
181 cx.notify();215 cx.notify();
182 }216 }
crates/app/src/ui/cards/effects.rsmodified+18 -0
@@ -9,6 +9,7 @@ use crate::ui::icons::{Icon, IconSize};
9 use crate::ui::type_scale::{self, Typeset};9 use crate::ui::type_scale::{self, Typeset};
10 use crate::ui::kit::{self, Segment};10 use crate::ui::kit::{self, Segment};
11 use crate::ui::widgets::{SliderRow, SliderTyped, slider_row};11 use crate::ui::widgets::{SliderRow, SliderTyped, slider_row};
12+use super::curve::CurveTarget;
12 use crate::*;13 use crate::*;
13 use engine::effects::{BlendMode, Effect, EffectKind, MAX_EFFECTS};14 use engine::effects::{BlendMode, Effect, EffectKind, MAX_EFFECTS};
14 15
@@ -438,6 +439,23 @@ impl Player {
438 controls.push(control);439 controls.push(control);
439 }440 }
440 }441 }
442+ // An effect with keys shows the easing of the one on the playhead under its settings, with
443+ // the same chips and curve as the transform card; with no key there the row is disabled.
444+ if !e.keys.is_empty() {
445+ controls.push(
446+ div()
447+ .flex()
448+ .flex_col()
449+ .gap(px(4.))
450+ .child(dark_row_label("Easing", false))
451+ .child(self.ease_picker(
452+ CurveTarget::Effect(i),
453+ move |this, ease, cx| this.set_effect_key_ease_here(i, ease, cx),
454+ cx,
455+ ))
456+ .into_any_element(),
457+ );
458+ }
441 // A mask follows the picture under it: the Track row sits under its controls.459 // A mask follows the picture under it: the Track row sits under its controls.
442 if matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask) {460 if matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask) {
443 controls.push(self.track_row(i, cx));461 controls.push(self.track_row(i, cx));
crates/app/src/ui/cards/keys.rsmodified+67 -48
@@ -6,7 +6,7 @@ use crate::ui::icons::Icon;
6 use crate::ui::kit::{self, Segment};6 use crate::ui::kit::{self, Segment};
7 use crate::ui::type_scale::{self, Typeset};7 use crate::ui::type_scale::{self, Typeset};
8 use crate::ui::widgets::*;8 use crate::ui::widgets::*;
9-use super::curve;9+use super::curve::{self, CurveTarget};
10 use crate::*;10 use crate::*;
11 use engine::project::KeyKind;11 use engine::project::KeyKind;
12 use engine::transform::{Bezier, KeyEase};12 use engine::transform::{Bezier, KeyEase};
@@ -138,10 +138,62 @@ impl Player {
138 .child(diamond(12., ink, here.is_some()));138 .child(diamond(12., ink, here.is_some()));
139 let (m1, m2) = (cx.entity(), cx.entity());139 let (m1, m2) = (cx.entity(), cx.entity());
140 let none = (!keyed).then_some("No keys yet");140 let none = (!keyed).then_some("No keys yet");
141+ let eases = self.ease_picker(
142+ CurveTarget::Key(kind),
143+ move |this, ease, cx| this.set_key_ease_here(kind, ease, cx),
144+ cx,
145+ );
146+ // The colour card's rows run to its edge; the transform card's sit 6px in.
147+ let inset = if kind == KeyKind::Color { 0. } else { 6. };
148+ div()
149+ .id(("key-row", kind_id(kind)))
150+ .w_full()
151+ .px(px(inset))
152+ .flex()
153+ .flex_col()
154+ .gap(px(4.))
155+ .child(
156+ div()
157+ .w_full()
158+ .flex()
159+ .items_center()
160+ .gap(px(2.))
161+ .child(
162+ div()
163+ .flex_1()
164+ .min_w(px(0.))
165+ .truncate()
166+ .type_style(type_scale::body())
167+ .text_color(rgb(if keyed { t.ink1 } else { t.ink2 }))
168+ .child(row_label(kind)),
169+ )
170+ .child(kit::icon_ghost("key-prev", Icon::ChevronLeft, "Previous key", none, move |_, app| {
171+ m1.update(app, |this, cx| this.jump_key(kind, false, cx));
172+ }))
173+ .child(diamond)
174+ .child(kit::icon_ghost("key-next", Icon::ChevronRight, "Next key", none, move |_, app| {
175+ m2.update(app, |this, cx| this.jump_key(kind, true, cx));
176+ })),
177+ )
178+ .child(eases)
179+ .into_any_element()
180+ }
181+
182+ /// The easing row of one target: the five presets and a sixth chip for the custom curve, then,
183+ /// under it, the curve editor while the key on the playhead is custom or a handle of this
184+ /// target is held. The row is always there: without a key on the playhead it is disabled, and
185+ /// its reason rides a clear layer over the chips (a tooltip on the row itself did not reach the
186+ /// pointer past the chips). `on_pick` writes the ease the row picked.
187+ pub(super) fn ease_picker(
188+ &self,
189+ target: CurveTarget,
190+ on_pick: impl Fn(&mut Player, KeyEase, &mut Context<Player>) + 'static,
191+ cx: &mut Context<Self>,
192+ ) -> AnyElement {
193+ let here = self.ease_here(target);
141 let me = cx.entity();194 let me = cx.entity();
142- // The ease of the key on the playhead gets a line of its own, whole words. The line is195+ // The ease of the key on the playhead gets a line of its own, whole words. The sixth chip
143- // always there: without a key on the playhead it is disabled (and says why), so setting196+ // is the custom curve.
144- // the first key never moves the rows under it. The sixth chip is the custom curve.
145 let mut labels: Vec<Segment> = KeyEase::ALL.iter().map(|e| Segment::text(ease_text(*e))).collect();197 let mut labels: Vec<Segment> = KeyEase::ALL.iter().map(|e| Segment::text(ease_text(*e))).collect();
146 labels.push(Segment::text("Custom"));198 labels.push(Segment::text("Custom"));
147 let custom_at = KeyEase::ALL.len();199 let custom_at = KeyEase::ALL.len();
@@ -150,7 +202,8 @@ impl Player {
150 Some(current) => KeyEase::ALL.iter().position(|e| *e == current).unwrap_or(usize::MAX),202 Some(current) => KeyEase::ALL.iter().position(|e| *e == current).unwrap_or(usize::MAX),
151 None => usize::MAX,203 None => usize::MAX,
152 };204 };
153- let eases = kit::segmented_equal("key-ease", &labels, selected, here.is_some(), None, move |pick, _, app| {205+ let on_pick = Rc::new(on_pick);
206+ let chips = kit::segmented_equal("key-ease", &labels, selected, here.is_some(), None, move |pick, _, app| {
154 // A custom pick keeps the curve the key already has, or starts from CSS `ease`.207 // A custom pick keeps the curve the key already has, or starts from CSS `ease`.
155 let ease = match (KeyEase::ALL.get(pick), here) {208 let ease = match (KeyEase::ALL.get(pick), here) {
156 (Some(preset), _) => Some(*preset),209 (Some(preset), _) => Some(*preset),
@@ -158,20 +211,18 @@ impl Player {
158 (None, _) => curve::css_ease().map(KeyEase::Bezier),211 (None, _) => curve::css_ease().map(KeyEase::Bezier),
159 };212 };
160 if let Some(ease) = ease {213 if let Some(ease) = ease {
161- me.update(app, |this, cx| this.set_key_ease_here(kind, ease, cx));214+ me.update(app, |this, cx| on_pick(this, ease, cx));
162 }215 }
163 });216 });
164- // With no key on the playhead the row is disabled, and its reason rides a clear layer217+ let chips = div()
165- // over the chips: a tooltip on the row itself did not reach the pointer past the chips.218+ .id("key-ease-row")
166- let eases = div()
167- .id(("key-ease-row", kind_id(kind)))
168 .relative()219 .relative()
169 .w_full()220 .w_full()
170- .child(eases)221+ .child(chips)
171 .when(here.is_none(), |d| {222 .when(here.is_none(), |d| {
172 d.child(223 d.child(
173 div()224 div()
174- .id(("key-ease-why", kind_id(kind)))225+ .id("key-ease-why")
175 .absolute()226 .absolute()
176 .top(px(0.))227 .top(px(0.))
177 .left(px(0.))228 .left(px(0.))
@@ -181,7 +232,7 @@ impl Player {
181 });232 });
182 // The curve shows the draft while a handle is held, else the key's own custom ease.233 // The curve shows the draft while a handle is held, else the key's own custom ease.
183 let shown: Option<Bezier> = match (self.curve_drag.as_ref(), here) {234 let shown: Option<Bezier> = match (self.curve_drag.as_ref(), here) {
184- (Some(drag), _) if drag.kind == kind => Some(drag.draft),235+ (Some(drag), _) if drag.target == target => Some(drag.draft),
185 (_, Some(KeyEase::Bezier(b))) => Some(b),236 (_, Some(KeyEase::Bezier(b))) => Some(b),
186 _ => None,237 _ => None,
187 };238 };
@@ -190,48 +241,16 @@ impl Player {
190 .w_full()241 .w_full()
191 .flex()242 .flex()
192 .justify_center()243 .justify_center()
193- .child(curve::curve_editor(244+ .child(curve::curve_editor("curve", target, shown, self.curve_bounds_for(target), cx))
194- ("key-curve", kind_id(kind)),
195- kind,
196- shown,
197- self.curve_bounds[kind_id(kind)].clone(),
198- cx,
199- ))
200 .into_any_element()245 .into_any_element()
201 });246 });
202- // The colour card's rows run to its edge; the transform card's sit 6px in.
203- let inset = if kind == KeyKind::Color { 0. } else { 6. };
204 div()247 div()
205- .id(("key-row", kind_id(kind)))248+ .id("ease-picker")
206 .w_full()249 .w_full()
207- .px(px(inset))
208 .flex()250 .flex()
209 .flex_col()251 .flex_col()
210 .gap(px(4.))252 .gap(px(4.))
211- .child(253+ .child(chips)
212- div()
213- .w_full()
214- .flex()
215- .items_center()
216- .gap(px(2.))
217- .child(
218- div()
219- .flex_1()
220- .min_w(px(0.))
221- .truncate()
222- .type_style(type_scale::body())
223- .text_color(rgb(if keyed { t.ink1 } else { t.ink2 }))
224- .child(row_label(kind)),
225- )
226- .child(kit::icon_ghost("key-prev", Icon::ChevronLeft, "Previous key", none, move |_, app| {
227- m1.update(app, |this, cx| this.jump_key(kind, false, cx));
228- }))
229- .child(diamond)
230- .child(kit::icon_ghost("key-next", Icon::ChevronRight, "Next key", none, move |_, app| {
231- m2.update(app, |this, cx| this.jump_key(kind, true, cx));
232- })),
233- )
234- .child(eases)
235 .children(editor)254 .children(editor)
236 .into_any_element()255 .into_any_element()
237 }256 }
crates/engine/src/project.rsmodified+1 -1
@@ -1104,7 +1104,7 @@ pub struct GainKey {
1104 /// Which animation a keyframe button or action is about: the placement1104 /// Which animation a keyframe button or action is about: the placement
1105 /// ([`Clip::transform_keys`]), the opacity ([`Clip::opacity_keys`]) or the grade1105 /// ([`Clip::transform_keys`]), the opacity ([`Clip::opacity_keys`]) or the grade
1106 /// ([`Clip::color_keys`]).1106 /// ([`Clip::color_keys`]).
1107-#[derive(Clone, Copy, PartialEq, Eq, Debug)]1107+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1108 pub enum KeyKind {1108 pub enum KeyKind {
1109 Placement,1109 Placement,
1110 Opacity,1110 Opacity,