forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

tools.rs715 lines, 29.4 KiBHistoryRawDownload
1//! The creator tools card: four tabs (Normalize, Captions, Fillers, Voiceover) over the
2//! engine's shared tools. Choices are dropdowns and segmented rows, the numbers are a slider
3//! with a number field (drag it to scrub, click it to type), and a tool that cannot run says
4//! why and offers the way to get what it lacks.
5
6use super::common::*;
7use crate::creator::{self, LANGUAGES, Said};
8use crate::player::tools::{Cycle, NumField, Tool, Tools};
9use crate::player::transcript;
10use crate::ui::icons::Icon;
11use crate::ui::kit::{self, Segment};
12use crate::*;
13use engine::speech::Hear;
14use crate::layout::redesign as r;
15use crate::ui::type_scale::{self, Typeset};
16use gpui::{DispatchPhase, Entity, canvas, deferred};
17
18/// The pick (clip, caption, title) and the scope a result was read under.
19type ResultPick = (Option<(engine::project::Lane, usize)>, Option<(engine::project::Lane, usize, usize)>, Option<usize>, bool);
20
21thread_local! {
22 /// The pick and scope the Normalize line on screen was first drawn under, with the line. The
23 /// line is drawn only while those still hold (see `result_shown`).
24 static NORMALIZE_SEEN: std::cell::RefCell<Option<(ResultPick, String)>> = const { std::cell::RefCell::new(None) };
25}
26
27/// A window-wide pointer catcher for a drag that began on one of this card's controls: while
28/// `live`, every move goes to `on_move` (window x, Shift held) and the release to `on_up`, even
29/// when the pointer has left the control. Paints nothing; nothing is registered while idle.
30pub(super) fn drag_catcher(
31 me: Entity<Player>,
32 live: bool,
33 on_move: impl Fn(&mut Player, f32, bool, &mut Context<Player>) + 'static,
34 on_up: impl Fn(&mut Player, &mut Context<Player>) + 'static,
35) -> impl IntoElement {
36 let (me_up, on_move, on_up) = (me.clone(), Rc::new(on_move), Rc::new(on_up));
37 canvas(
38 |_, _, _| (),
39 move |_, _, window, _| {
40 if !live {
41 return;
42 }
43 window.on_mouse_event(move |e: &MouseMoveEvent, phase, _, cx| {
44 if phase == DispatchPhase::Capture {
45 me.update(cx, |this, cx| on_move(this, f32::from(e.position.x), e.modifiers.shift, cx));
46 }
47 });
48 window.on_mouse_event(move |_: &MouseUpEvent, phase, _, cx| {
49 if phase == DispatchPhase::Capture {
50 me_up.update(cx, |this, cx| on_up(this, cx));
51 }
52 });
53 },
54 )
55 .absolute()
56 .size_full()
57}
58
59/// A 4px track with a 14px thumb at `fraction`, the whole thing `HIT_MIN` tall to hit. A press
60/// is `on_press(window x)`; the caller's catcher carries the drag on from there.
61pub(super) fn slider_track(
62 id: &'static str,
63 fraction: f32,
64 bar: Rc<Cell<Bounds<Pixels>>>,
65 on_press: impl Fn(&mut Player, Pixels, &mut Context<Player>) + 'static,
66 cx: &mut Context<Player>,
67) -> Stateful<Div> {
68 const THUMB: f32 = 14.;
69 let t = tokens();
70 let fraction = slider_fraction(fraction, 0., 1.);
71 div()
72 .id(id)
73 .relative()
74 .w_full()
75 .h(px(HIT_MIN))
76 .flex()
77 .items_center()
78 .cursor_pointer()
79 .on_mouse_down(
80 MouseButton::Left,
81 cx.listener(move |this, event: &MouseDownEvent, _, cx| on_press(this, event.position.x, cx)),
82 )
83 .child(bounds_probe(bar))
84 .child(
85 div()
86 .w_full()
87 .h(px(4.))
88 .rounded(px(2.))
89 .bg(rgb(t.e3))
90 .child(div().h_full().w(relative(fraction)).rounded(px(2.)).bg(rgb(t.accent))),
91 )
92 .child(
93 div()
94 .absolute()
95 .top(px((HIT_MIN - THUMB) / 2.))
96 .left(relative(fraction))
97 .ml(px(-THUMB / 2.))
98 .size(px(THUMB))
99 .rounded_full()
100 .bg(rgb(t.ink1)),
101 )
102}
103
104/// A dropdown row: the label, then the closed field; the open list hangs from the field's foot,
105/// and a press anywhere else shuts it.
106#[allow(clippy::too_many_arguments)]
107fn drop_row(
108 id: &'static str,
109 label: &'static str,
110 items: Vec<SharedString>,
111 current: usize,
112 open: bool,
113 what: Cycle,
114 list_w: f32,
115 busy: bool,
116 cx: &mut Context<Player>,
117) -> Div {
118 // A picker holds still while a run it feeds is going.
119 let enabled = !items.is_empty() && !busy;
120 let value: SharedString = items.get(current).cloned().unwrap_or_else(|| "None installed".into());
121 let me = cx.entity();
122 let field = kit::dropdown_field(id, value, enabled).when(enabled, |d| {
123 d.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| this.tools_toggle_drop(what, cx)))
124 });
125 let list = (open && enabled).then(|| {
126 let backdrop = div().absolute().top(px(-4000.)).left(px(-4000.)).size(px(8000.)).on_mouse_down(
127 MouseButton::Left,
128 cx.listener(move |this, _: &MouseDownEvent, _, cx| {
129 this.tools_toggle_drop(what, cx);
130 cx.stop_propagation();
131 }),
132 );
133 let pick = {
134 let me = me.clone();
135 move |i: usize, _: &mut Window, app: &mut App| me.update(app, |this, cx| this.tools_pick(what, i, cx))
136 };
137 deferred(
138 div()
139 .absolute()
140 .top(px(0.))
141 .left(px(0.))
142 .child(backdrop)
143 .child(div().absolute().top(px(r::CONTROL_M + 2.)).left(px(0.)).child(kit::choice_list(id, list_w, &items, current, pick))),
144 )
145 });
146 div()
147 .flex()
148 .items_center()
149 .gap(px(8.))
150 .min_h(px(r::CONTROL_M))
151 .child(div().flex_none().w(px(84.)).child(dark_row_label(label, false)))
152 .child(div().relative().flex_1().min_w(px(0.)).child(field).children(list))
153}
154
155/// One Normalize number: the label and a number field (with its unit and reset slot) on a line,
156/// the slider under it.
157fn num_row(
158 id: &'static str,
159 label: &'static str,
160 unit: &'static str,
161 field: NumField,
162 t: &Tools,
163 cx: &mut Context<Player>,
164) -> Div {
165 let me = cx.entity();
166 let (value, default) = match field {
167 NumField::Target => (t.lufs, creator::LUFS_PRESETS[0].1),
168 NumField::Ceiling => (t.ceiling, engine::normalize::TARGET_TRUE_PEAK),
169 };
170 let (lo, hi) = field.range();
171 let editing = t.num.as_ref().filter(|(f, _)| *f == field).map(|(_, e)| e);
172 let scrubbing = t.drag.is_some_and(|d| d.field == field);
173 let sliding = t.slide == Some(field);
174 let bar = Rc::new(Cell::new(Bounds::default()));
175 let probe = Rc::clone(&bar);
176 let probe2 = Rc::clone(&bar);
177 let num = kit::number_field(id, 112., field.shown(value), Some(unit), editing, true)
178 .tooltip(crate::ui::widgets::overlay_tip_hover(
179 label,
180 "",
181 Some(match field {
182 NumField::Target => "YouTube and Spotify use \u{2212}14. Drag to change, click to type.",
183 NumField::Ceiling => "Drag to change, click to type",
184 }),
185 ))
186 .on_mouse_down(
187 MouseButton::Left,
188 cx.listener(move |this, event: &MouseDownEvent, _, cx| {
189 cx.stop_propagation();
190 this.begin_num_drag(field, f32::from(event.position.x));
191 }),
192 );
193 let reset = kit::reset_slot(
194 // One slot id per field: an id the number's own never repeats.
195 if field == NumField::Target { "tools-target-reset" } else { "tools-ceiling-reset" },
196 (value - default).abs() > 1e-9,
197 {
198 let me = me.clone();
199 move |_, app| me.update(app, |this, cx| this.tools_set_num(field, default, cx))
200 },
201 );
202 let slide_id = if field == NumField::Target { "tools-target-bar" } else { "tools-ceiling-bar" };
203 div()
204 .flex()
205 .flex_col()
206 .child(
207 div()
208 .flex()
209 .items_center()
210 .justify_between()
211 .min_h(px(r::CONTROL_M))
212 .child(dark_row_label(label, false))
213 .child(div().flex().items_center().gap(px(2.)).child(num).child(reset)),
214 )
215 .child(slider_track(
216 slide_id,
217 slider_fraction(value as f32, lo as f32, hi as f32),
218 bar,
219 move |this: &mut Player, x: Pixels, cx: &mut Context<Player>| {
220 this.begin_slide(field);
221 this.tools_slide(field, frac_along(x, probe.get()), cx);
222 },
223 cx,
224 ))
225 .child(drag_catcher(
226 me.clone(),
227 scrubbing || sliding,
228 {
229 move |this, x, fine, cx| match this.tools.as_ref().is_some_and(|t| t.slide.is_some()) {
230 true => this.tools_slide(field, frac_along(px(x), probe2.get()), cx),
231 false => this.num_drag_move(x, fine, cx),
232 }
233 },
234 |this, cx| this.num_drag_end(cx),
235 ))
236}
237
238/// The progress line of a running job, with its Cancel.
239fn running_row(t: &Tools, cx: &mut Context<Player>) -> Option<Div> {
240 let running = t.running.as_ref()?;
241 let fraction = running.job.fraction();
242 Some(
243 div()
244 .flex()
245 .flex_col()
246 .gap(px(4.))
247 .child(
248 div()
249 .flex()
250 .items_center()
251 .justify_between()
252 .child(dark_row_label(running.what, true))
253 .child(dark_row_value(format!("{:.0}%", fraction * 100.), true)),
254 )
255 .child(
256 div()
257 .h(px(6.))
258 .rounded(px(2.))
259 .bg(rgb(tokens().ink4))
260 .child(div().h_full().w(relative(fraction.clamp(0.0, 1.0))).rounded(px(2.)).bg(rgb(tokens().accent))),
261 )
262 .child(div().flex().child(dark_ghost_button(
263 "tools-cancel",
264 "Cancel",
265 "esc",
266 false,
267 cx.listener(|this, _: &ClickEvent, _, cx| this.cancel_tools_job(cx)),
268 ))),
269 )
270}
271
272/// A kit button that can be off. Off it ignores input and its tooltip gives `why`; on, its
273/// tooltip is the name alone (no key shown on the button or beside it).
274fn gated_button(
275 id: &'static str,
276 label: SharedString,
277 why: Option<&str>,
278 on_click: impl Fn(&mut Player, &mut Context<Player>) + 'static,
279 cx: &mut Context<Player>,
280) -> Stateful<Div> {
281 let b = kit::Button::new(id).label(label.clone()).enabled(why.is_none()).build();
282 match why {
283 Some(why) => b.tooltip(crate::ui::widgets::overlay_tip_hover(label.as_ref(), "", Some(why))),
284 None => b
285 .tooltip(crate::ui::widgets::overlay_tip_hover(label.as_ref(), "", None))
286 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| on_click(this, cx))),
287 }
288}
289
290/// A full-width action button (see [`gated_button`]).
291fn action_button(
292 id: &'static str,
293 label: &'static str,
294 why: Option<&str>,
295 on_click: impl Fn(&mut Player, &mut Context<Player>) + 'static,
296 cx: &mut Context<Player>,
297) -> Stateful<Div> {
298 gated_button(id, label.into(), why, on_click, cx).w_full()
299}
300
301/// A filler's tick: the Lucide check on an accent square when it is ticked, the empty square
302/// when it is not.
303fn tick_box(on: bool) -> Div {
304 let t = tokens();
305 match on {
306 true => div()
307 .size(px(14.))
308 .rounded(px(3.))
309 .bg(rgb(t.accent))
310 .flex()
311 .items_center()
312 .justify_center()
313 .child(Icon::Check.el_px(px(11.), t.on_accent)),
314 false => div()
315 .size(px(14.))
316 .flex()
317 .items_center()
318 .justify_center()
319 .child(Icon::Square.el_px(px(14.), t.ink3)),
320 }
321}
322
323/// What a tool says when it has nothing to work with: the sentence, then the way to get it.
324fn missing(text: &'static str, actions: Vec<Stateful<Div>>) -> Div {
325 div()
326 .flex()
327 .flex_col()
328 .gap(px(6.))
329 .p(px(8.))
330 .rounded(px(r::R_CONTROL))
331 .bg(rgb(tokens().e2))
332 .child(dark_help(text))
333 .child(div().flex().gap(px(6.)).children(actions))
334}
335
336impl Player {
337 /// The tools card. A click on a head folds it; keys: left and right switch tool, Enter runs it.
338 pub(crate) fn tools_card(&self, viewport: Size<Pixels>, cx: &mut Context<Self>) -> Option<impl IntoElement> {
339 let t = self.tools.as_ref()?;
340 // Two rows of two, so a plain name never clips and the one in force stands out: the
341 // row it is in marks it with the accent ring, the other row has none lit.
342 let tab_row = |id: &'static str, tools: [Tool; 2], cx: &mut Context<Self>| {
343 let at = tools.iter().position(|x| *x == t.tool);
344 let me = cx.entity();
345 kit::segmented_equal(
346 id,
347 &tools.map(|tool| Segment::text(tool.label())),
348 at.unwrap_or(usize::MAX),
349 true,
350 at.map(|i| (i, kit::Look::Focus)),
351 move |i, _, app| me.update(app, |this, cx| this.tools_tab(tools[i], cx)),
352 )
353 };
354 let tabs = div()
355 .flex()
356 .flex_col()
357 .gap(px(4.))
358 .child(tab_row("tools-tab-a", [Tool::Normalize, Tool::Captions], cx))
359 .child(tab_row("tools-tab-b", [Tool::Fillers, Tool::Voiceover], cx));
360 let list_w = (f32::from(viewport.width) - 96.).max(120.);
361 let body = match t.tool {
362 Tool::Normalize => self.normalize_body(t, cx),
363 Tool::Captions => self.listen_body(t, false, list_w, cx),
364 Tool::Fillers => self.listen_body(t, true, list_w, cx),
365 Tool::Voiceover => self.voiceover_body(t, list_w, cx),
366 };
367 let help_text = "Left and right switch tool, Enter runs it. Esc stops a run in progress.";
368 Some(
369 self.card_outer(viewport, cx).child(
370 div()
371 .w_full()
372 .max_w(px(card_max_w(COLOR_W, self.card_maximized, f32::from(viewport.width))))
373 .on_mouse_down(MouseButton::Left, swallow)
374 .flex()
375 .flex_col()
376 .gap(px(CARD_GAP))
377 .map(|d| self.card_surface(d))
378 .child(dark_card_head("Tools", None, Some(help_text.into()), Some(self.card_maximized), cx))
379 .child(tabs)
380 .child(div().id("tools-rows").flex().flex_col().gap(px(4.)).child(body))
381 .when(self.result_shown(t), |d| d.child(self.status_row(t.said(t.tool), cx))),
382 ),
383 )
384 }
385
386 /// Whether the tool's last word is drawn. A Normalize result is for the pick and the scope it
387 /// was read under: once either changes, its line is let go rather than left naming the old one.
388 fn result_shown(&self, t: &Tools) -> bool {
389 let said = t.said(t.tool);
390 if said.line.is_empty() {
391 return false;
392 }
393 if t.tool != Tool::Normalize {
394 return true;
395 }
396 let pick = (self.selected.anchor(), self.sel_cue, self.title_sel, t.each);
397 NORMALIZE_SEEN.with(|seen| {
398 let mut seen = seen.borrow_mut();
399 match seen.as_ref() {
400 Some((at, line)) if *line == said.line => *at == pick,
401 _ => {
402 *seen = Some((pick, said.line.clone()));
403 true
404 }
405 }
406 })
407 }
408
409 /// The tool's last word: its sentence (the whole error in the tooltip when the sentence cut it
410 /// short), and a Relink when the refusal is for files that are gone.
411 fn status_row(&self, said: &Said, cx: &mut Context<Self>) -> Div {
412 let mut line = div().id("tools-status").w_full().child(dark_help(said.line.clone()));
413 if let Some(full) = &said.detail {
414 line = line.tooltip(crate::ui::widgets::overlay_tip_hover("Why", "", Some(full.as_str())));
415 }
416 let mut row = div().flex().flex_col().gap(px(6.)).child(line);
417 let offline = self.session.as_ref().and_then(|s| s.sources().iter().find(|src| !src.path.exists()).map(|src| src.path.clone()));
418 if let (true, Some(path)) = (said.offline, offline) {
419 row = row.child(
420 div().flex().child(
421 kit::Button::new("tools-relink")
422 .label("Relink")
423 .build()
424 .tooltip(crate::ui::widgets::overlay_tip_hover("Relink", "", Some("Point the first offline file at its new place")))
425 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| this.relink_pick(path.clone(), cx))),
426 ),
427 );
428 }
429 row
430 }
431
432 fn normalize_body(&self, t: &Tools, cx: &mut Context<Self>) -> Div {
433 let presets = kit::segmented_equal(
434 "tools-preset",
435 &creator::LUFS_PRESETS.map(|(name, _)| Segment::text(name)),
436 creator::LUFS_PRESETS.iter().position(|(_, lufs)| (t.lufs - lufs).abs() < 0.05).unwrap_or(usize::MAX),
437 true,
438 None,
439 {
440 let me = cx.entity();
441 move |i, _, app| me.update(app, |this, cx| this.tools_set_target(creator::LUFS_PRESETS[i].1, cx))
442 },
443 );
444 let scopes = kit::segmented_equal(
445 "tools-scope",
446 &[Segment::text("Whole mix"), Segment::text("Each track")],
447 usize::from(t.each),
448 true,
449 None,
450 {
451 let me = cx.entity();
452 move |i, _, app| {
453 me.update(app, |this, cx| {
454 // A result names the scope it ran on: the old line goes with the switch.
455 if let Some(t) = this.tools.as_mut() {
456 t.set_said(Tool::Normalize, Said::default());
457 }
458 this.tools_set_each(i == 1, cx)
459 })
460 }
461 },
462 );
463 let silent = self.session.as_ref().is_none_or(|s| creator::normalizable_lanes(s).is_empty());
464 div()
465 .flex()
466 .flex_col()
467 .gap(px(4.))
468 .child(presets)
469 .child(num_row("tools-target", "Target loudness", "LUFS", NumField::Target, t, cx))
470 .child(num_row("tools-ceiling", "Peak limit", "dB peak", NumField::Ceiling, t, cx))
471 .child(scopes)
472 .child(action_button(
473 "tools-normalize",
474 match t.each {
475 true => "Normalize each track",
476 false => "Normalize whole mix",
477 },
478 silent.then_some("Nothing to normalize: no unmuted audio track has clips."),
479 |this, cx| this.run_normalize(cx),
480 cx,
481 ))
482 .child(dark_help(match t.each {
483 true => "Each track is set on its own to the target. Measures before and after. One undo step.",
484 false => "The whole mix moves by one amount, so the tracks keep their balance. Measures before and after. One undo step.",
485 }))
486 }
487
488 /// Captions and Fillers share their pickers and their run row; the rest is their own. With a
489 /// transcript to read from, "From the transcript" is the first and default choice (instant);
490 /// "Listen again" keeps the sound pickers under it.
491 fn listen_body(&self, t: &Tools, fillers: bool, list_w: f32, cx: &mut Context<Self>) -> Div {
492 let no_model = transcript::speech_target(self.session.as_ref()).is_none();
493 let hears = self.tools_hears();
494 let downloading = self.transcript.download.is_some();
495 let from_transcript = self.transcript_words().is_some() && !t.relisten;
496 let hear_items: Vec<SharedString> = hears.iter().map(|h| creator::hear_label(*h).into()).collect();
497 let lang_items: Vec<SharedString> = LANGUAGES.iter().map(|(_, name)| (*name).into()).collect();
498 let _ = Hear::Mix;
499 let why = match (no_model && !from_transcript, t.running.is_some()) {
500 (true, _) => Some("Install a speech model first"),
501 (false, true) => Some("Already listening"),
502 _ => None,
503 };
504 let go = match running_row(t, cx) {
505 Some(row) => row,
506 None => div().flex().child(action_button(
507 if fillers { "tools-find-fillers" } else { "tools-captions" },
508 if fillers { "Find filler words" } else { "Generate captions" },
509 why,
510 move |this, cx| this.start_listening(fillers, cx),
511 cx,
512 )),
513 };
514 let busy = t.running.is_some();
515 let mut body = div().flex().flex_col().gap(px(4.));
516 if self.transcript_words().is_some() {
517 body = body.child(kit::segmented_equal(
518 "tools-source",
519 &[Segment::text("From the transcript"), Segment::text("Listen again")],
520 usize::from(t.relisten),
521 t.running.is_none(),
522 None,
523 {
524 let me = cx.entity();
525 move |i, _, app| me.update(app, |this, cx| this.tools_set_relisten(i == 1, cx))
526 },
527 ));
528 }
529 if !from_transcript {
530 body = body
531 .child(drop_row("tools-hear", "Listen to", hear_items, t.hear, t.open == Some(Cycle::Hear), Cycle::Hear, list_w, busy, cx))
532 .child(drop_row("tools-lang", "Language", lang_items, t.lang, t.open == Some(Cycle::Language), Cycle::Language, list_w, busy, cx));
533 }
534 if no_model && !from_transcript {
535 body = body.child(missing(
536 "No speech model is installed yet. Download one, or put one in the models folder.",
537 vec![
538 kit::Button::new("tools-download-model")
539 .label(if downloading { "Downloading\u{2026}" } else { "Download model" })
540 .style(kit::ButtonStyle::Primary)
541 .enabled(!downloading)
542 .build()
543 .when(!downloading, |d| d.on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.start_model_download(cx)))),
544 kit::Button::new("tools-models-folder")
545 .label("Open models folder")
546 .build()
547 .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.open_models_folder(cx))),
548 ],
549 ));
550 }
551 // The go button sits above the filler list, so it stays put when the list appears.
552 body = body.child(go);
553 if fillers && !t.found.is_empty() {
554 body = body.child(self.filler_rows(t, cx));
555 }
556 body.child(dark_help(match (fillers, from_transcript) {
557 (true, _) => "Ticked filler words are cut from every track, closing each gap. One undo step.",
558 (false, true) => "Instant: the words already in the transcript become one caption track. One undo step.",
559 (false, false) => "The words become one caption track. One undo step.",
560 }))
561 }
562
563 fn filler_rows(&self, t: &Tools, cx: &mut Context<Self>) -> Div {
564 let fps = self.fps;
565 let ticked = t.found.iter().filter(|(_, on)| *on).count();
566 let cut = match ticked {
567 0 => "Cut fillers".to_string(),
568 1 => "Cut 1 filler".to_string(),
569 n => format!("Cut {n} fillers"),
570 };
571 let cut_why = (ticked == 0).then_some("Tick the filler words to cut");
572 let rows: Vec<_> = t
573 .found
574 .iter()
575 .enumerate()
576 .map(|(i, (f, on))| {
577 let picked = t.pick == i;
578 div()
579 .id(("tools-filler", i))
580 .flex_none()
581 .flex()
582 .items_center()
583 .gap(px(8.))
584 .min_h(px(KEYS_ROW_H))
585 .px(px(6.))
586 .rounded(px(3.))
587 .when(picked, |d| d.bg(rgb(DARK_RAISED())))
588 .child(
589 div()
590 .id(("tools-filler-box", i))
591 .flex_none()
592 .w(px(HIT_MIN / 2.))
593 .flex()
594 .justify_center()
595 .cursor_pointer()
596 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| this.toggle_filler(i, cx)))
597 .child(tick_box(*on)),
598 )
599 .child(
600 div()
601 .id(("tools-filler-go", i))
602 .flex_none()
603 .cursor_pointer()
604 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| this.seek_filler(i, cx)))
605 .tooltip(crate::ui::widgets::overlay_tip_hover("Go to filler", "", None))
606 .child(dark_row_value(frames_timecode(f.start_f, fps), picked)),
607 )
608 .child(div().flex_1().min_w(px(0.)).overflow_hidden().child(dark_row_label(f.text.to_lowercase(), picked)))
609 .into_any_element()
610 })
611 .collect();
612 div()
613 .flex()
614 .flex_col()
615 .gap(px(2.))
616 .child(
617 div()
618 .id("tools-fillers")
619 .flex()
620 .flex_col()
621 .gap(px(2.))
622 .max_h(px(120.))
623 .overflow_y_scroll()
624 .children(rows),
625 )
626 .child(
627 div()
628 .flex()
629 .gap(px(4.))
630 .child(dark_ghost_button(
631 "tools-fillers-all",
632 "All",
633 "",
634 false,
635 cx.listener(|this, _: &ClickEvent, _, cx| this.set_all_fillers(true, cx)),
636 ))
637 .child(dark_ghost_button(
638 "tools-fillers-none",
639 "None",
640 "",
641 false,
642 cx.listener(|this, _: &ClickEvent, _, cx| this.set_all_fillers(false, cx)),
643 ))
644 .child(gated_button(
645 "tools-cut-fillers",
646 cut.into(),
647 cut_why,
648 |this, cx| this.cut_ticked_fillers(cx),
649 cx,
650 )),
651 )
652 }
653
654 fn voiceover_body(&self, t: &Tools, list_w: f32, cx: &mut Context<Self>) -> Div {
655 let t_ = tokens();
656 let voices = self.tools_voices();
657 let voice_items: Vec<SharedString> = voices.iter().map(|v| v.name.clone().into()).collect();
658 let typing_text = t.typing && t.num.is_none();
659 let shown: SharedString = match (typing_text, t.text.is_empty()) {
660 (true, _) => format!("{}\u{258f}", t.text).into(),
661 (false, true) => "Type what the voice should say".into(),
662 (false, false) => t.text.clone().into(),
663 };
664 let at = self.session.as_ref().map_or(0.0, |s| s.now());
665 let why = match (voices.is_empty(), t.text.trim().is_empty()) {
666 (true, _) => Some("Install a voice first"),
667 (false, true) => Some("Type what the voice should say first"),
668 _ => None,
669 };
670 let go = match running_row(t, cx) {
671 Some(row) => row,
672 None => div()
673 .flex()
674 .flex_col()
675 .gap(px(2.))
676 .child(action_button("tools-speak", "Add voiceover at playhead", why, |this, cx| this.start_voiceover(cx), cx))
677 .child(div().flex().justify_center().child(dark_help(format!("Placed at the playhead ({})", creator::clock(at))).w_auto())),
678 };
679 let mut body = div()
680 .flex()
681 .flex_col()
682 .gap(px(4.))
683 .child(
684 div()
685 .id("tools-text")
686 .min_h(px(KEYS_ROW_H * 2.))
687 .p(px(8.))
688 .rounded(px(r::R_CONTROL))
689 .border_1()
690 .border_color(if typing_text { rgb(t_.accent) } else { rgba(t_.line) })
691 .bg(rgb(t_.e2))
692 .cursor_text()
693 .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.begin_voiceover_text(cx)))
694 .child(
695 div()
696 .type_style(type_scale::body())
697 .text_color(rgb(if t.text.is_empty() && !typing_text { t_.ink3 } else { t_.ink1 }))
698 .child(shown),
699 ),
700 )
701 .child(drop_row("tools-voice", "Voice", voice_items, t.voice, t.open == Some(Cycle::Voice), Cycle::Voice, list_w, t.running.is_some(), cx));
702 if voices.is_empty() {
703 body = body.child(missing(
704 "No voice is installed yet. Put a voice in the voices folder.",
705 vec![
706 kit::Button::new("tools-voices-folder")
707 .label("Open voices folder")
708 .build()
709 .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.open_voices_folder(cx))),
710 ],
711 ));
712 }
713 body.child(go).child(dark_help("The voice reads your text aloud, then the clip lands on the first free audio track. One undo step."))
714 }
715}