forge
Explore
Log in

Don't you dare go Hollow

✨ Title card keyframes: diamond, prev/next, easing and curve, move/scale/opacity rows

Browse files at this commit

48a175d0a16e37b210c868e54307394300d98577Ahmet Kaan GümüşParent: 5e44881
crates/app/src/player/generators.rsmodified+8 -1
@@ -377,10 +377,12 @@ impl Player {
377 pub(crate) fn gen_key(&mut self, key: &str, ctrl: bool, alt: bool, key_char: Option<&str>, cx: &mut Context<Self>) {377 pub(crate) fn gen_key(&mut self, key: &str, ctrl: bool, alt: bool, key_char: Option<&str>, cx: &mut Context<Self>) {
378 let Some((paint, field)) = self.gen_hex.as_mut() else { return };378 let Some((paint, field)) = self.gen_hex.as_mut() else { return };
379 let number = matches!(paint, GenPaint::Width | GenPaint::Radius | GenPaint::Angle | GenPaint::Count | GenPaint::Title(_));379 let number = matches!(paint, GenPaint::Width | GenPaint::Radius | GenPaint::Angle | GenPaint::Count | GenPaint::Title(_));
380+ // A title's key shifts run both ways, so they may be typed negative.
381+ let signed = matches!(paint, GenPaint::Title(crate::player::titling::ScrubField::KeyX | crate::player::titling::ScrubField::KeyY));
380 let result = field.key(key, ctrl, alt, key_char, if number { 8 } else { 7 });382 let result = field.key(key, ctrl, alt, key_char, if number { 8 } else { 7 });
381 match paint {383 match paint {
382 GenPaint::Key(_) => field.text.retain(|c| c.is_ascii_hexdigit() || c == '#'),384 GenPaint::Key(_) => field.text.retain(|c| c.is_ascii_hexdigit() || c == '#'),
383- _ if number => field.text.retain(|c| c.is_ascii_digit() || c == '.' || c == ','),385+ _ if number => field.text.retain(|c| c.is_ascii_digit() || c == '.' || c == ',' || (signed && c == '-')),
384 _ => field.text.retain(|c| c.is_ascii_alphanumeric() || c == '#'),386 _ => field.text.retain(|c| c.is_ascii_alphanumeric() || c == '#'),
385 }387 }
386 match result {388 match result {
@@ -484,6 +486,9 @@ impl Player {
484 cx.notify();486 cx.notify();
485 return;487 return;
486 };488 };
489+ if field.is_key() {
490+ return self.set_title_key_percent(field, v, cx);
491+ }
487 let fps = self.session.as_ref().map_or(25., |s| s.meta().frame_rate).max(1.);492 let fps = self.session.as_ref().map_or(25., |s| s.meta().frame_rate).max(1.);
488 let frames = (v.max(0.) * fps).round() as u32;493 let frames = (v.max(0.) * fps).round() as u32;
489 self.write_title(494 self.write_title(
@@ -499,6 +504,8 @@ impl Player {
499 }504 }
500 F::AnimLength => t.anim_frames = frames.clamp(1, t.frames.max(1)),505 F::AnimLength => t.anim_frames = frames.clamp(1, t.frames.max(1)),
501 F::BoxOpacity => t.style.box_color[3] = ((v.round().clamp(0., 100.) as u32 * 255 + 50) / 100) as u8,506 F::BoxOpacity => t.style.box_color[3] = ((v.round().clamp(0., 100.) as u32 * 255 + 50) / 100) as u8,
507+ // The key fields were written by `set_title_key_percent` above.
508+ F::KeyX | F::KeyY | F::KeyScale | F::KeyOpacity => {}
502 },509 },
503 cx,510 cx,
504 );511 );
crates/app/src/player/titling.rsmodified+216 -17
@@ -9,6 +9,8 @@ use crate::*;
9 use engine::Title;9 use engine::Title;
10 use engine::project::{MAX_TITLE_CHARS, TitlePreset as Preset};10 use engine::project::{MAX_TITLE_CHARS, TitlePreset as Preset};
11 use engine::text::{DEFAULT_SIZE, SIZE_RANGE, TextStyle};11 use engine::text::{DEFAULT_SIZE, SIZE_RANGE, TextStyle};
12+use engine::titleanim::{KEY_SCALE_RANGE, TitleKey};
13+use engine::transform::{KeyEase, sample};
12 14
13 /// How long a new title is up, in seconds.15 /// How long a new title is up, in seconds.
14 pub(crate) const NEW_SECS: f64 = 5.0;16 pub(crate) const NEW_SECS: f64 = 5.0;
@@ -28,15 +30,32 @@ pub(crate) enum ScrubField {
28 BoxOpacity,30 BoxOpacity,
29 /// The title's block dragged along the timeline: `Start` in timeline pixels.31 /// The title's block dragged along the timeline: `Start` in timeline pixels.
30 Move,32 Move,
33+ /// The title's own key at the playhead: its horizontal shift, in percent of the width.
34+ KeyX,
35+ /// The key's vertical shift, in percent of the height, down positive.
36+ KeyY,
37+ /// The key's size multiplier, in percent.
38+ KeyScale,
39+ /// The key's opacity multiplier, in percent.
40+ KeyOpacity,
31 }41 }
32 42
33-/// A title number being scrubbed: where the press was, the value it had, and the value now.43+impl ScrubField {
44+ /// Whether the field is one of the title's key numbers, which write the key at the playhead.
45+ pub(crate) fn is_key(self) -> bool {
46+ matches!(self, ScrubField::KeyX | ScrubField::KeyY | ScrubField::KeyScale | ScrubField::KeyOpacity)
47+ }
48+}
49+
50+/// A title number being scrubbed: where the press was, the value it had, the value now, and the
51+/// title frame a key field writes its key at.
34 #[derive(Clone, Copy, Debug, PartialEq)]52 #[derive(Clone, Copy, Debug, PartialEq)]
35 pub(crate) struct TitleScrub {53 pub(crate) struct TitleScrub {
36 pub(crate) field: ScrubField,54 pub(crate) field: ScrubField,
37 pub(crate) x0: f32,55 pub(crate) x0: f32,
38 pub(crate) v0: i64,56 pub(crate) v0: i64,
39 pub(crate) cur: i64,57 pub(crate) cur: i64,
58+ pub(crate) at: u32,
40 }59 }
41 60
42 /// Which colour of the selected title a hex field is typing: the letters' or the box's.61 /// Which colour of the selected title a hex field is typing: the letters' or the box's.
@@ -82,6 +101,10 @@ pub(crate) fn scrub_value(field: ScrubField, v0: i64, dx: f32, fps: f64, pps: f6
82 ScrubField::Length => (v0 + by(4.)).clamp(1, max_end),101 ScrubField::Length => (v0 + by(4.)).clamp(1, max_end),
83 ScrubField::AnimLength => (v0 + by(4.)).clamp(1, i64::from(frames.max(1))),102 ScrubField::AnimLength => (v0 + by(4.)).clamp(1, i64::from(frames.max(1))),
84 ScrubField::BoxOpacity => (v0 + by(2.)).clamp(0, 100),103 ScrubField::BoxOpacity => (v0 + by(2.)).clamp(0, 100),
104+ ScrubField::KeyX | ScrubField::KeyY | ScrubField::KeyScale | ScrubField::KeyOpacity => {
105+ let (lo, hi) = key_range(field);
106+ (v0 + by(2.)).clamp(lo, hi)
107+ }
85 ScrubField::Move => {108 ScrubField::Move => {
86 let moved = if pps > 0. { (f64::from(dx) / pps * fps).round() as i64 } else { 0 };109 let moved = if pps > 0. { (f64::from(dx) / pps * fps).round() as i64 } else { 0 };
87 (v0 + moved).clamp(0, max_end - i64::from(frames))110 (v0 + moved).clamp(0, max_end - i64::from(frames))
@@ -123,7 +146,7 @@ impl Player {
123 t.text = field.text.clone();146 t.text = field.text.clone();
124 }147 }
125 if let Some(s) = self.title_scrub {148 if let Some(s) = self.title_scrub {
126- set_field(&mut t, s.field, s.cur);149+ set_field(&mut t, s.field, s.cur, s.at);
127 }150 }
128 t151 t
129 }152 }
@@ -263,6 +286,11 @@ impl Player {
263 self.named_step("Title text", |this| this.write_title_now(edit, cx))286 self.named_step("Title text", |this| this.write_title_now(edit, cx))
264 }287 }
265 288
289+ /// The same write as [`Self::write_title`], named as a keyframe change in the undo history.
290+ pub(crate) fn write_title_key(&mut self, edit: impl FnOnce(&mut Title), cx: &mut Context<Self>) -> bool {
291+ self.named_step("Title keyframe", |this| this.write_title_now(edit, cx))
292+ }
293+
266 fn write_title_now(&mut self, edit: impl FnOnce(&mut Title), cx: &mut Context<Self>) -> bool {294 fn write_title_now(&mut self, edit: impl FnOnce(&mut Title), cx: &mut Context<Self>) -> bool {
267 let Some(idx) = self.title_sel else {295 let Some(idx) = self.title_sel else {
268 return false;296 return false;
@@ -352,8 +380,9 @@ impl Player {
352 let Some((_, t)) = self.title_target() else {380 let Some((_, t)) = self.title_target() else {
353 return;381 return;
354 };382 };
355- let v0 = get_field(&t, field);383+ let at = self.title_key_frame(&t).unwrap_or(0);
356- self.title_scrub = Some(TitleScrub { field, x0: x, v0, cur: v0 });384+ let v0 = get_field(&t, field, at);
385+ self.title_scrub = Some(TitleScrub { field, x0: x, v0, cur: v0, at });
357 }386 }
358 387
359 /// The pointer moved with a title scrub in flight: the number follows, shown live.388 /// The pointer moved with a title scrub in flight: the number follows, shown live.
@@ -377,36 +406,196 @@ impl Player {
377 return false;406 return false;
378 };407 };
379 if s.cur != s.v0 {408 if s.cur != s.v0 {
380- self.write_title(|t| set_field(t, s.field, s.cur), cx);409+ match s.field.is_key() {
410+ true => self.write_title_key(|t| set_field(t, s.field, s.cur, s.at), cx),
411+ false => self.write_title(|t| set_field(t, s.field, s.cur, s.at), cx),
412+ };
381 }413 }
382 cx.notify();414 cx.notify();
383 true415 true
384 }416 }
417+
418+ /// The frame of the title's own keys the playhead is on, counted from the title's first frame.
419+ /// `None` when the playhead is outside the title, where no key can be written.
420+ pub(crate) fn title_key_frame(&self, t: &Title) -> Option<u32> {
421+ let now = self.key_frame();
422+ (t.start <= now && now < t.end()).then(|| now - t.start)
423+ }
424+
425+ /// The ease of the title's key on the playhead, `None` with no key there.
426+ pub(crate) fn title_key_here(&self, idx: usize) -> Option<KeyEase> {
427+ let t = self.session.as_ref()?.titles().get(idx)?;
428+ let at = self.title_key_frame(t)?;
429+ t.keys.iter().find(|k| k.at == at).map(|k| k.ease)
430+ }
431+
432+ /// The diamond: adds a key at the playhead holding what the title's keys give there, or takes
433+ /// the key that is there off. One undo step.
434+ pub(crate) fn toggle_title_key(&mut self, cx: &mut Context<Self>) {
435+ let Some((_, stored)) = self.title_target() else {
436+ return;
437+ };
438+ let Some(at) = self.title_key_frame(&stored) else {
439+ self.notify_user("The playhead is outside this title".into());
440+ cx.notify();
441+ return;
442+ };
443+ let there = stored.keys.iter().any(|k| k.at == at);
444+ self.write_title_key(
445+ |t| match there {
446+ true => t.keys.retain(|k| k.at != at),
447+ false => {
448+ key_index_at(t, at);
449+ }
450+ },
451+ cx,
452+ );
453+ }
454+
455+ /// Sets the ease of the title's key on the playhead to the one the ease row picked, one undo
456+ /// step. Nothing changes with no key there, where the row is disabled.
457+ pub(crate) fn set_title_key_ease_here(&mut self, idx: usize, ease: KeyEase, cx: &mut Context<Self>) {
458+ if self.title_sel != Some(idx) {
459+ return;
460+ }
461+ let Some((_, stored)) = self.title_target() else {
462+ return;
463+ };
464+ let Some(at) = self.title_key_frame(&stored) else {
465+ return;
466+ };
467+ self.write_title_key(
468+ |t| {
469+ if let Some(k) = t.keys.iter_mut().find(|k| k.at == at) {
470+ k.ease = ease;
471+ }
472+ },
473+ cx,
474+ );
475+ }
476+
477+ /// Seeks the playhead to the next (`forward`) or the previous key of the selected title, and
478+ /// says so when there is none that way.
479+ pub(crate) fn jump_title_key(&mut self, forward: bool, cx: &mut Context<Self>) {
480+ let Some((_, t)) = self.title_target() else {
481+ return;
482+ };
483+ let now = self.key_frame();
484+ let frames: Vec<u32> = t.keys.iter().filter(|k| k.at < t.frames).map(|k| t.start + k.at).collect();
485+ let hit = match forward {
486+ true => frames.iter().copied().find(|&f| f > now),
487+ false => frames.iter().copied().rev().find(|&f| f < now),
488+ };
489+ match hit {
490+ Some(f) => {
491+ let at = f64::from(f) / self.active_fps();
492+ self.seek(at, cx);
493+ }
494+ None => {
495+ self.notify_user(if forward { "No later key on this title" } else { "No earlier key on this title" }.into());
496+ cx.notify();
497+ }
498+ }
499+ }
500+
501+ /// Writes a typed percent as the title's key field at the playhead, one undo step. The key is
502+ /// added there if the title has none. Outside the title there is no key, so it says so.
503+ pub(crate) fn set_title_key_percent(&mut self, field: ScrubField, v: f64, cx: &mut Context<Self>) {
504+ let Some((_, stored)) = self.title_target() else {
505+ return;
506+ };
507+ let Some(at) = self.title_key_frame(&stored) else {
508+ self.notify_user("The playhead is outside this title".into());
509+ cx.notify();
510+ return;
511+ };
512+ self.write_title_key(|t| set_field(t, field, v.round() as i64, at), cx);
513+ }
385 }514 }
386 515
387-/// One scrubbable number of a title.516+/// One scrubbable number of a title. A key field reads the title's key at `at`, a frame counted
388-fn get_field(t: &Title, field: ScrubField) -> i64 {517+/// from the title's first frame, or the rest a title with no keys holds.
518+pub(crate) fn get_field(t: &Title, field: ScrubField, at: u32) -> i64 {
389 match field {519 match field {
390 ScrubField::Size => i64::from(t.style.size),520 ScrubField::Size => i64::from(t.style.size),
391 ScrubField::Start | ScrubField::Move => i64::from(t.start),521 ScrubField::Start | ScrubField::Move => i64::from(t.start),
392 ScrubField::Length => i64::from(t.frames),522 ScrubField::Length => i64::from(t.frames),
393 ScrubField::AnimLength => i64::from(t.anim_frames),523 ScrubField::AnimLength => i64::from(t.anim_frames),
394 ScrubField::BoxOpacity => (i64::from(t.style.box_color[3]) * 100 + 127) / 255,524 ScrubField::BoxOpacity => (i64::from(t.style.box_color[3]) * 100 + 127) / 255,
525+ ScrubField::KeyX | ScrubField::KeyY | ScrubField::KeyScale | ScrubField::KeyOpacity => {
526+ (f64::from(key_number(&held_at(&t.keys, at), field)) * 100.).round() as i64
527+ }
395 }528 }
396 }529 }
397 530
398-fn set_field(t: &mut Title, field: ScrubField, v: i64) {531+fn set_field(t: &mut Title, field: ScrubField, v: i64, at: u32) {
399- let v = v.max(0) as u32;532+ let u = v.max(0) as u32;
400 match field {533 match field {
401- ScrubField::Size => t.style.size = v,534+ ScrubField::KeyX | ScrubField::KeyY | ScrubField::KeyScale | ScrubField::KeyOpacity => set_key_field(t, field, v, at),
402- ScrubField::Start | ScrubField::Move => t.start = v,535+ ScrubField::Size => t.style.size = u,
536+ ScrubField::Start | ScrubField::Move => t.start = u,
403 ScrubField::Length => {537 ScrubField::Length => {
404- t.frames = v.max(1);538+ t.frames = u.max(1);
405 t.fade_in = t.fade_in.min(t.frames);539 t.fade_in = t.fade_in.min(t.frames);
406 t.fade_out = t.fade_out.min(t.frames);540 t.fade_out = t.fade_out.min(t.frames);
407 }541 }
408- ScrubField::AnimLength => t.anim_frames = v.clamp(1, t.frames.max(1)),542+ ScrubField::AnimLength => t.anim_frames = u.clamp(1, t.frames.max(1)),
409- ScrubField::BoxOpacity => t.style.box_color[3] = ((v.min(100) * 255 + 50) / 100) as u8,543+ ScrubField::BoxOpacity => t.style.box_color[3] = ((u.min(100) * 255 + 50) / 100) as u8,
544+ }
545+}
546+
547+/// The least and the most a key field may read, in percent: the engine's limits as the card shows
548+/// them. A shift runs both ways, the scale and the opacity do not.
549+fn key_range(field: ScrubField) -> (i64, i64) {
550+ match field {
551+ ScrubField::KeyScale => ((KEY_SCALE_RANGE.0 * 100.).round() as i64, (KEY_SCALE_RANGE.1 * 100.).round() as i64),
552+ ScrubField::KeyOpacity => (0, 100),
553+ _ => (-100, 100),
554+ }
555+}
556+
557+/// The number a key holds for a key field: a share of the width or height for the shifts, a
558+/// multiple for the scale and the opacity.
559+fn key_number(k: &TitleKey, field: ScrubField) -> f32 {
560+ match field {
561+ ScrubField::KeyX => k.x,
562+ ScrubField::KeyY => k.y,
563+ ScrubField::KeyScale => k.scale,
564+ _ => k.opacity,
565+ }
566+}
567+
568+/// The key the title's keys give at `at`: the interpolated one, or the rest a title with no keys
569+/// holds (no shift, full size, full opacity).
570+fn held_at(keys: &[TitleKey], at: u32) -> TitleKey {
571+ sample(keys, f64::from(at)).unwrap_or(TitleKey { at, x: 0., y: 0., scale: 1., opacity: 1., ease: KeyEase::Linear })
572+}
573+
574+/// The index of the key at `at`, adding one first when there is none. A new key holds what the
575+/// title's keys give there, so adding it moves nothing.
576+fn key_index_at(t: &mut Title, at: u32) -> usize {
577+ match t.keys.binary_search_by_key(&at, |k| k.at) {
578+ Ok(i) => i,
579+ Err(i) => {
580+ let held = held_at(&t.keys, at);
581+ t.keys.insert(i, TitleKey { at, ease: KeyEase::Linear, ..held });
582+ i
583+ }
584+ }
585+}
586+
587+/// Writes a key field's percent into the title's key at `at`, adding that key when there is none.
588+/// The value is held to the engine's limits.
589+fn set_key_field(t: &mut Title, field: ScrubField, v: i64, at: u32) {
590+ let (lo, hi) = key_range(field);
591+ let share = v.clamp(lo, hi) as f32 / 100.;
592+ let i = key_index_at(t, at);
593+ let k = &mut t.keys[i];
594+ match field {
595+ ScrubField::KeyX => k.x = share.clamp(-1., 1.),
596+ ScrubField::KeyY => k.y = share.clamp(-1., 1.),
597+ ScrubField::KeyScale => k.scale = share.clamp(KEY_SCALE_RANGE.0, KEY_SCALE_RANGE.1),
598+ _ => k.opacity = share.clamp(0., 1.),
410 }599 }
411 }600 }
412 601
@@ -468,10 +657,20 @@ mod tests {
468 let mut t = title();657 let mut t = title();
469 t.fade_in = 40;658 t.fade_in = 40;
470 t.fade_out = 60;659 t.fade_out = 60;
471- set_field(&mut t, ScrubField::Length, 30);660+ set_field(&mut t, ScrubField::Length, 30, 0);
472 assert_eq!((t.frames, t.fade_in, t.fade_out), (30, 30, 30));661 assert_eq!((t.frames, t.fade_in, t.fade_out), (30, 30, 30));
473 }662 }
474 663
664+ #[test]
665+ fn a_key_field_adds_its_key_at_the_playhead_and_holds_the_limits() {
666+ let mut t = title();
667+ set_field(&mut t, ScrubField::KeyX, 150, 10);
668+ assert_eq!((t.keys.len(), t.keys[0].at, t.keys[0].x), (1, 10, 1.));
669+ assert_eq!(get_field(&t, ScrubField::KeyX, 10), 100);
670+ set_field(&mut t, ScrubField::KeyScale, 0, 10);
671+ assert_eq!(t.keys[0].scale, KEY_SCALE_RANGE.0);
672+ }
673+
475 #[test]674 #[test]
476 fn the_lower_third_is_bold_bottom_left_and_a_hex_colour_parses_or_is_refused() {675 fn the_lower_third_is_bold_bottom_left_and_a_hex_colour_parses_or_is_refused() {
477 let mut t = title();676 let mut t = title();
@@ -484,9 +683,9 @@ mod tests {
484 assert_eq!(parse_hex(bad), None, "{bad}");683 assert_eq!(parse_hex(bad), None, "{bad}");
485 }684 }
486 let mut t = title();685 let mut t = title();
487- set_field(&mut t, ScrubField::BoxOpacity, 50);686+ set_field(&mut t, ScrubField::BoxOpacity, 50, 0);
488 assert_eq!(t.style.box_color[3], 128);687 assert_eq!(t.style.box_color[3], 128);
489- assert_eq!(get_field(&t, ScrubField::BoxOpacity), 50);688+ assert_eq!(get_field(&t, ScrubField::BoxOpacity, 0), 50);
490 }689 }
491 690
492 #[test]691 #[test]
crates/app/src/ui/cards/curve.rsmodified+5 -8
@@ -28,9 +28,7 @@ pub(crate) enum CurveTarget {
28 Key(KeyKind),28 Key(KeyKind),
29 /// The key on the playhead of the effect at this stack slot of the open clip.29 /// The key on the playhead of the effect at this stack slot of the open clip.
30 Effect(usize),30 Effect(usize),
31- /// A title's key, by title index. No title key takes an ease yet, so a drag on this target31+ /// The title's key on the playhead, by title index.
32- /// is read but never written: a later change wires it up in `end_curve_drag`.
33- #[allow(dead_code)]
34 Title(usize),32 Title(usize),
35 }33 }
36 34
@@ -159,13 +157,12 @@ pub(super) fn curve_editor(
159 }157 }
160 158
161 impl Player {159 impl Player {
162- /// The ease the target's key on the playhead holds, `None` with no key there. A title takes160+ /// The ease the target's key on the playhead holds, `None` with no key there.
163- /// no ease yet, so its target has none.
164 pub(crate) fn ease_here(&self, target: CurveTarget) -> Option<KeyEase> {161 pub(crate) fn ease_here(&self, target: CurveTarget) -> Option<KeyEase> {
165 match target {162 match target {
166 CurveTarget::Key(kind) => self.key_here(kind),163 CurveTarget::Key(kind) => self.key_here(kind),
167 CurveTarget::Effect(slot) => self.effect_key_ease_here(slot),164 CurveTarget::Effect(slot) => self.effect_key_ease_here(slot),
168- CurveTarget::Title(_) => None,165+ CurveTarget::Title(idx) => self.title_key_here(idx),
169 }166 }
170 }167 }
171 168
@@ -201,7 +198,7 @@ impl Player {
201 }198 }
202 199
203 /// Ends the drag where the button came up: the draft is written to the target's key on the200 /// Ends the drag where the button came up: the draft is written to the target's key on the
204- /// playhead as one undo step. A title's draft is dropped for now.201+ /// playhead as one undo step.
205 pub(crate) fn end_curve_drag(&mut self, at: Point<Pixels>, cx: &mut Context<Self>) {202 pub(crate) fn end_curve_drag(&mut self, at: Point<Pixels>, cx: &mut Context<Self>) {
206 self.drag_curve(at, cx);203 self.drag_curve(at, cx);
207 if let Some(drag) = self.curve_drag.take() {204 if let Some(drag) = self.curve_drag.take() {
@@ -209,7 +206,7 @@ impl Player {
209 match drag.target {206 match drag.target {
210 CurveTarget::Key(kind) => self.set_key_ease_here(kind, ease, cx),207 CurveTarget::Key(kind) => self.set_key_ease_here(kind, ease, cx),
211 CurveTarget::Effect(slot) => self.set_effect_key_ease_here(slot, ease, cx),208 CurveTarget::Effect(slot) => self.set_effect_key_ease_here(slot, ease, cx),
212- CurveTarget::Title(_) => {}209+ CurveTarget::Title(idx) => self.set_title_key_ease_here(idx, ease, cx),
213 }210 }
214 }211 }
215 cx.notify();212 cx.notify();
crates/app/src/ui/cards/title.rsmodified+63 -2
@@ -4,7 +4,9 @@
4 //! step through [`Player::write_title`], and the viewer shows the words and numbers live.4 //! step through [`Player::write_title`], and the viewer shows the words and numbers live.
5 5
6 use super::common::*;6 use super::common::*;
7-use crate::player::titling::{HexTarget, ScrubField, anim_default_frames, hex_of, preset_label};7+use super::curve::CurveTarget;
8+use super::keys::diamond;
9+use crate::player::titling::{HexTarget, ScrubField, anim_default_frames, get_field, hex_of, preset_label};
8 use engine::titleanim::TitleAnim;10 use engine::titleanim::TitleAnim;
9 use engine::project::TitlePreset as Preset;11 use engine::project::TitlePreset as Preset;
10 use crate::ui::icons::Icon;12 use crate::ui::icons::Icon;
@@ -276,7 +278,7 @@ impl Player {
276 278
277 /// The Title section, or nothing while no title is selected.279 /// The Title section, or nothing while no title is selected.
278 pub(crate) fn title_card(&self, room: Size<Pixels>, cx: &mut Context<Self>) -> Option<impl IntoElement> {280 pub(crate) fn title_card(&self, room: Size<Pixels>, cx: &mut Context<Self>) -> Option<impl IntoElement> {
279- let (_, stored) = self.title_target()?;281+ let (idx, stored) = self.title_target()?;
280 let t = self.shown_title(&stored);282 let t = self.shown_title(&stored);
281 let fps = self.session.as_ref().map_or(25., |s| s.meta().frame_rate).max(1.);283 let fps = self.session.as_ref().map_or(25., |s| s.meta().frame_rate).max(1.);
282 // Every time reads in seconds with one decimal and its unit.284 // Every time reads in seconds with one decimal and its unit.
@@ -440,6 +442,59 @@ impl Player {
440 this.write_title(|t| t.style.boxed = !t.style.boxed, cx);442 this.write_title(|t| t.style.boxed = !t.style.boxed, cx);
441 }));443 }));
442 444
445+ // The title's keys: the section reads and writes the key at the playhead, so the playhead has
446+ // to be inside the title. Outside it the section dims and says why on hover.
447+ let at = self.title_key_frame(&t);
448+ let why_out: Option<&'static str> = at.is_none().then_some("Move the playhead into the title");
449+ let keyed = self.title_key_here(idx).is_some();
450+ let ink = match (keyed, !t.keys.is_empty()) {
451+ (true, _) => tk.accent,
452+ (false, true) => tk.ink1,
453+ _ => tk.ink3,
454+ };
455+ let tip: &str = match (at.is_some(), keyed) {
456+ (false, _) => "Move the playhead into the title",
457+ (true, true) => "Remove the title's key at the playhead",
458+ (true, false) => "Key the title at the playhead",
459+ };
460+ let key_dot = div()
461+ .id("title-key-diamond")
462+ .flex_none()
463+ .size(px(crate::layout::redesign::CONTROL_M))
464+ .flex()
465+ .items_center()
466+ .justify_center()
467+ .rounded(px(crate::layout::redesign::R_CONTROL))
468+ .cursor_pointer()
469+ .hover(|s| s.bg(rgb(tk.e3)))
470+ .tooltip(crate::ui::widgets::overlay_tip_hover(tip, "", None))
471+ .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_title_key(cx)))
472+ .child(diamond(12., ink, keyed));
473+ let (m_prev, m_next) = (cx.entity(), cx.entity());
474+ let nav = div()
475+ .flex()
476+ .items_center()
477+ .gap(px(2.))
478+ .child(kit::icon_ghost("title-key-prev", Icon::ChevronLeft, "Previous key", why_out, move |_, app| {
479+ m_prev.update(app, |this, cx| this.jump_title_key(false, cx));
480+ }))
481+ .child(key_dot)
482+ .child(kit::icon_ghost("title-key-next", Icon::ChevronRight, "Next key", why_out, move |_, app| {
483+ m_next.update(app, |this, cx| this.jump_title_key(true, cx));
484+ }))
485+ .when(at.is_none(), |d| d.opacity(0.5));
486+ let keys_row = row("Keyframes", nav);
487+ let eases = div().w_full().when(at.is_none(), |d| d.opacity(0.5)).child(self.ease_picker(
488+ CurveTarget::Title(idx),
489+ move |this, ease, cx| this.set_title_key_ease_here(idx, ease, cx),
490+ cx,
491+ ));
492+ // The four numbers read the key at the playhead, or the rest a title holds with no key there.
493+ let key_val = |field: ScrubField| match at {
494+ Some(at) => get_field(&t, field, at).to_string(),
495+ None => "-".to_string(),
496+ };
497+
443 // The header (icon, words, length) is the dock's, like a clip's; the remove verb ends the card.498 // The header (icon, words, length) is the dock's, like a clip's; the remove verb ends the card.
444 let remove = kit::Button::new("title-remove")499 let remove = kit::Button::new("title-remove")
445 .label("Remove title")500 .label("Remove title")
@@ -491,6 +546,12 @@ impl Player {
491 DRAG_HINT,546 DRAG_HINT,
492 cx,547 cx,
493 ))548 ))
549+ .child(keys_row)
550+ .child(eases)
551+ .child(self.title_scrub_row("title-key-x", "Move across", key_val(ScrubField::KeyX), Some("%"), ScrubField::KeyX, why_out, DRAG_HINT, cx))
552+ .child(self.title_scrub_row("title-key-y", "Move down", key_val(ScrubField::KeyY), Some("%"), ScrubField::KeyY, why_out, DRAG_HINT, cx))
553+ .child(self.title_scrub_row("title-key-scale", "Scale", key_val(ScrubField::KeyScale), Some("%"), ScrubField::KeyScale, why_out, DRAG_HINT, cx))
554+ .child(self.title_scrub_row("title-key-opacity", "Opacity", key_val(ScrubField::KeyOpacity), Some("%"), ScrubField::KeyOpacity, why_out, DRAG_HINT, cx))
494 .child(div().flex().justify_start().child(remove)),555 .child(div().flex().justify_start().child(remove)),
495 ),556 ),
496 )557 )