forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

export.rs1588 lines, 64.4 KiBHistoryRawDownload
1//! The export panel (DESIGN §9): the dock's third tab, Media | Clip | Export.
2//! One panel, four faces -- the settings, the overwrite question inside them,
3//! the running export and the finished (or failed) file. It is in flow in the
4//! dock like every other tab, so nothing floats over the viewer or the lanes.
5
6use super::common::*;
7use crate::ui::icons::{Icon, IconSize};
8use crate::ui::kit::{self, Button, ButtonSize, ButtonStyle};
9use crate::ui::theme::tokens;
10use crate::ui::type_scale::{self, Typeset};
11use crate::*;
12
13/// A clickable surface on the sheet.
14type OnClick = Box<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>;
15
16impl Player {
17 /// The export panel (DESIGN §9): presets first, then the range, the
18 /// destination and a plain-words summary, with every detailed setting one
19 /// closed "More settings" disclosure away -- simplified, never hidden.
20 /// While an export runs the same panel is its progress, and when it lands
21 /// it offers the file.
22 pub(crate) fn export_panel(&self, cx: &mut Context<Self>) -> AnyElement {
23 let folder = dest_dir_text(&self.export_path);
24 let face: AnyElement = match (self.exporting(), &self.export_sheet.done, &self.export_sheet.failed) {
25 (Some(export), ..) => self.sheet_progress(export, cx).into_any_element(),
26 (None, Some(done), _) => sheet_done(done, cx).into_any_element(),
27 (None, None, Some(why)) => sheet_failed(why, &folder, cx).into_any_element(),
28 (None, None, None) if self.export_sheet.cancelled => sheet_cancelled(cx).into_any_element(),
29 _ => self.sheet_settings(cx).into_any_element(),
30 };
31 // The settings face carries the queue inside its own scroll; the other faces (progress,
32 // done, failed, cancelled) keep it under them, so a person who left the sheet up still sees it.
33 let settings_face = self.exporting().is_none()
34 && self.export_sheet.done.is_none()
35 && self.export_sheet.failed.is_none()
36 && !self.export_sheet.cancelled;
37 div()
38 .id("export-panel")
39 .flex_1()
40 .min_h(px(0.))
41 .flex()
42 .flex_col()
43 .child(face)
44 .when(!settings_face && !self.queue.jobs.is_empty(), |d| {
45 d.child(
46 div()
47 .id("export-queue-foot")
48 .flex_none()
49 .max_h(px(260.))
50 .overflow_y_scroll()
51 .border_t_1()
52 .border_color(rgba(tokens().line))
53 .px(px(8.))
54 .py(px(8.))
55 .child(self.sheet_queue(cx)),
56 )
57 })
58 .into_any_element()
59 }
60
61 /// The queue: one row per job and the three controls. Queued jobs keep the
62 /// timeline as it was when they were added, and the section says so.
63 fn sheet_queue(&self, cx: &mut Context<Self>) -> impl IntoElement {
64 use crate::export_queue::JobState;
65 let t = tokens();
66 let q = &self.queue;
67 let going = q.is_going();
68 let (go_label, go_why) = match (going, q.waiting()) {
69 (true, _) => ("Pause after this job", None),
70 (false, 0) => ("Start queue", Some("Nothing is waiting")),
71 (false, _) => ("Start queue", None),
72 };
73 let go_btn = Button::new("queue-go")
74 .label(go_label)
75 .style(if going { ButtonStyle::Secondary } else { ButtonStyle::Primary })
76 .size(ButtonSize::Default)
77 .enabled(go_why.is_none())
78 .build()
79 .tooltip(crate::ui::widgets::overlay_tip_hover(go_label, "", go_why));
80 let go_btn = go_btn.when(go_why.is_none(), |b| {
81 b.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| match going {
82 true => this.queue_pause(cx),
83 false => this.queue_start(cx),
84 }))
85 });
86 let clear_why = (q.finished() == 0).then_some("No finished exports to clear");
87 let clear_btn = Button::new("queue-clear")
88 .label("Clear finished")
89 .style(ButtonStyle::Ghost)
90 .size(ButtonSize::Default)
91 .enabled(clear_why.is_none())
92 .build()
93 .tooltip(crate::ui::widgets::overlay_tip_hover("Clear finished", "", clear_why));
94 let clear_btn = clear_btn.when(clear_why.is_none(), |b| {
95 b.on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.queue_clear_finished(cx)))
96 });
97 let rows = q.jobs.iter().map(|job| {
98 let id = job.id;
99 let (state_text, state_color) = match &job.state {
100 JobState::Waiting => ("Waiting".to_string(), t.ink2),
101 JobState::Running if job.cancelling => ("Stopping\u{2026}".to_string(), t.ink2),
102 JobState::Running => {
103 let p = job.handle.as_ref().map_or(0., ExportHandle::progress).clamp(0., 1.);
104 (format!("Exporting {}%", (p * 100.) as u32), t.ink1)
105 }
106 JobState::Done { bytes, .. } => (format!("Done \u{b7} {}", bytes_words(*bytes)), t.ok),
107 JobState::Failed(why) => (format!("Failed \u{b7} {why}"), t.warn),
108 JobState::Cancelled => ("Cancelled".to_string(), t.ink3),
109 };
110 let progress = match (&job.state, &job.handle) {
111 (JobState::Running, Some(h)) => Some(h.progress().clamp(0., 1.)),
112 _ => None,
113 };
114 let (tip, icon_id) = match job.state {
115 JobState::Running => ("Cancel this export", "queue-cancel"),
116 JobState::Waiting => ("Remove from the queue", "queue-remove"),
117 _ => ("Remove from the list", "queue-remove"),
118 };
119 let running = job.state == JobState::Running;
120 let waiting = job.state == JobState::Waiting;
121 let done = matches!(job.state, JobState::Done { .. });
122 div()
123 .id(("queue-row", id as usize))
124 .flex()
125 .flex_col()
126 .gap(px(2.))
127 .p(px(8.))
128 .rounded(px(6.))
129 .bg(rgb(t.e2))
130 .child(
131 div()
132 .flex()
133 .items_center()
134 .gap(px(4.))
135 .child(
136 div()
137 .flex_1()
138 .min_w(px(0.))
139 .truncate()
140 .type_style(type_scale::body_strong())
141 .text_color(rgb(t.ink1))
142 .child(file_name(&job.out)),
143 )
144 .child(
145 div()
146 .id((icon_id, id as usize))
147 .flex_none()
148 .size(px(24.))
149 .flex()
150 .items_center()
151 .justify_center()
152 .rounded(px(4.))
153 .cursor_pointer()
154 .hover(|d| d.bg(rgb(t.e3)))
155 .tooltip(crate::ui::widgets::overlay_tip_hover(tip, "", None))
156 .child(Icon::X.el(IconSize::Inline, t.ink2))
157 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| match running {
158 true => this.queue_cancel(id, cx),
159 false => this.queue_remove(id, cx),
160 })),
161 ),
162 )
163 .child(dark_help(job.summary.clone()))
164 .child(
165 div()
166 .flex()
167 .items_center()
168 .gap(px(8.))
169 .child(
170 div()
171 .id(("queue-state", id as usize))
172 .flex_1()
173 .min_w(px(0.))
174 .truncate()
175 .type_style(type_scale::caption())
176 .text_color(rgb(state_color))
177 .tooltip(crate::ui::widgets::overlay_tip_hover(&state_text, "", None))
178 .child(state_text.clone()),
179 )
180 .when(done, |d| {
181 d.child(
182 div()
183 .id(("queue-show", id as usize))
184 .flex_none()
185 .type_style(type_scale::caption())
186 .text_color(rgb(t.accent))
187 .cursor_pointer()
188 .child("Show in folder")
189 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| this.queue_show_in_folder(id, cx))),
190 )
191 }),
192 )
193 // Always there, so a row keeps its height from Waiting to Done.
194 .child(
195 div()
196 .h(px(4.))
197 .rounded(px(2.))
198 .when(waiting || running, |d| d.bg(rgb(t.e3)))
199 .children(progress.map(|p| div().h_full().w(relative(p)).rounded(px(2.)).bg(rgb(t.accent)))),
200 )
201 });
202 div()
203 .id("export-queue")
204 .flex()
205 .flex_col()
206 .gap(px(6.))
207 .child(div().type_style(type_scale::section()).text_color(rgb(t.ink2)).child(format!("Queue ({})", q.jobs.len())))
208 .child(dark_help("Queued exports use the timeline as it was when they were added."))
209 .children(rows)
210 .child(div().flex().items_center().gap(px(8.)).child(go_btn).child(clear_btn))
211 }
212
213 /// The settings face, simple layer first: the preset, where it goes, the
214 /// range and a two-line summary of what will be written. Every detailed
215 /// setting is one closed "Details" disclosure away -- simplified, never
216 /// hidden -- and the Export button is pinned under the scrolling body.
217 fn sheet_settings(&self, cx: &mut Context<Self>) -> impl IntoElement {
218 let blocked = self
219 .session
220 .as_ref()
221 .and_then(|s| format_refusal(s, self.format))
222 .map(|why| why.split(" \u{2014} ").next().unwrap_or("cannot export").to_string());
223 let more = self.folds.contains(EXPORT_MORE_FOLD);
224 let off = self.export_block_reason().or_else(|| self.export_source_clash());
225 let missing = self.export_missing();
226 let body = div()
227 .id("export-panel-body")
228 .track_scroll(&self.export_scroll)
229 .flex_1()
230 .min_h(px(0.))
231 .overflow_y_scroll()
232 .track_scroll(&self.export_body_scroll)
233 .flex()
234 .flex_col()
235 .gap(px(12.))
236 .px(px(8.))
237 .py(px(8.))
238 .child(self.sheet_preset(cx))
239 .child(self.sheet_destination(cx))
240 .child(self.sheet_range(cx))
241 .children((!missing.is_empty()).then(|| sheet_missing(&missing, cx)))
242 .child(self.sheet_summary(blocked.as_deref()))
243 .children((!self.queue.jobs.is_empty()).then(|| self.sheet_queue(cx)))
244 .child(more_toggle(more, cx))
245 .children(more.then(|| self.sheet_more(cx)));
246 div()
247 .flex_1()
248 .min_h(px(0.))
249 .flex()
250 .flex_col()
251 .child(
252 div()
253 .relative()
254 .flex_1()
255 .min_h(px(0.))
256 .flex()
257 .flex_col()
258 .child(body)
259 .child(crate::ui::widgets::more_below(self.export_body_scroll.clone())),
260 )
261 .child(match self.export_ask {
262 true => self.sheet_overwrite(cx).into_any_element(),
263 false => sheet_footer(off, self, cx).into_any_element(),
264 })
265 }
266
267 /// Why the export would write over one of the project's own sources, if it
268 /// would: the Export button is off and says so, and no question is asked.
269 fn export_source_clash(&self) -> Option<String> {
270 self.is_source_path(&self.export_path).then(|| SOURCE_NAME_TAKEN.to_string())
271 }
272
273 /// The preset: one dropdown in the shared popup look. Lit as "Custom (from
274 /// X)" whenever the settings match no preset, so a change is never silent.
275 fn sheet_preset(&self, cx: &mut Context<Self>) -> impl IntoElement {
276 let text = preset_box_text(self.preset_now(), self.export_sheet.preset);
277 div()
278 .flex()
279 .flex_col()
280 .gap(px(4.))
281 .child(section("Preset"))
282 .child(drop_box("export-preset", text, Some(Self::pick_open(ExportRow::Preset, cx))))
283 }
284
285 /// The click that opens one Details list where it was pressed.
286 fn pick_open(row: ExportRow, cx: &mut Context<Self>) -> OnClick {
287 Box::new(cx.listener(move |this, e: &ClickEvent, _, cx| {
288 this.picker_at_control(Pick::Export(row), e.position(), cx);
289 }))
290 }
291
292 /// The range: the whole timeline or the marks, as two segments with one
293 /// dim line under them (always there, so nothing moves); the marks dim
294 /// with the reason when they cannot be used.
295 fn sheet_range(&self, cx: &mut Context<Self>) -> impl IntoElement {
296 let frames = self
297 .session
298 .as_ref()
299 .map_or(0, |s| crate::subs::frame_at(s.timeline_duration(), self.fps));
300 let valid = self.export_range();
301 let opts = range_options(valid, self.range.is_some(), frames, self.fps);
302 let on_marks = self.export_span().is_some();
303 let note = match (&opts.marks, on_marks) {
304 (Some(span), true) => span.clone(),
305 _ => opts.whole.clone(),
306 };
307 div()
308 .flex()
309 .flex_col()
310 .gap(px(4.))
311 .child(section("Range"))
312 .child(
313 seg_track()
314 .child(seg(
315 "export-range-whole",
316 "Whole timeline",
317 !on_marks,
318 None,
319 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
320 this.export_sheet.whole = true;
321 cx.notify();
322 })),
323 ))
324 .child(seg(
325 "export-range-marks",
326 "In\u{2013}Out",
327 on_marks,
328 match valid {
329 Some(_) => None,
330 None => Some(opts.marks_off.unwrap_or("Set In and Out on the timeline first").to_string()),
331 },
332 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
333 if this.export_range().is_some() {
334 this.export_sheet.whole = false;
335 }
336 cx.notify();
337 })),
338 )),
339 )
340 .child(dim_line(note))
341 }
342
343 /// The destination: the file's name with its extension beside it, and the
344 /// folder shortened (the full path on hover) with a Change button for the
345 /// desktop's own dialog. Both fields can still be typed into.
346 fn sheet_destination(&self, cx: &mut Context<Self>) -> impl IntoElement {
347 let typing = self.export_sheet.field.as_ref();
348 // How many characters of the dock's width a field shows; a longer
349 // path is cut on its left, so the folder you are in stays in view.
350 let dock = f32::from_bits(crate::ui::widgets::DOCK_W_BITS.load(std::sync::atomic::Ordering::Relaxed));
351 let dock = if dock > 0. { dock } else { 320. };
352 let chars = (((dock - 16. - 64. - 14. - 34. - 20.) / 7.4) as usize).clamp(12, 80);
353 let shown = |field: SheetField, text: String| match typing {
354 Some((f, t)) if *f == field => (format!("{}\u{258f}", tail_of(t, chars)), true),
355 _ => (text, false),
356 };
357 let stem = self
358 .export_path
359 .file_stem()
360 .map_or_else(String::new, |s| s.to_string_lossy().into_owned());
361 // The typed name, checked while it is typed: a source's name is said under the field.
362 let typed_clash = match typing {
363 Some((SheetField::Name, text)) => parse_stem(text).is_ok_and(|stem| {
364 self.is_source_path(&self.export_path.with_file_name(crate::export_ui::typed_name(&stem, self.format)))
365 }),
366 _ => false,
367 };
368 let (name, name_on) = shown(SheetField::Name, stem);
369 let full = dest_dir_text(&self.export_path);
370 let (folder, folder_on) = shown(SheetField::Folder, tail_of(&full, chars));
371 div()
372 .flex()
373 .flex_col()
374 .gap(px(6.))
375 .child(section("Save as"))
376 .child(field_row(
377 "export-name",
378 "Name",
379 name,
380 (self.format != Format::PngSequence).then(|| format!(".{}", self.format.ext())),
381 name_on,
382 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
383 this.begin_field(SheetField::Name);
384 cx.notify();
385 })),
386 ))
387 .child(
388 div()
389 .flex()
390 .items_center()
391 .gap(px(6.))
392 .child(
393 div()
394 .id("export-folder-wrap")
395 .flex_1()
396 .min_w(px(0.))
397 .tooltip(crate::ui::widgets::overlay_tip_hover(&full, "", None))
398 .child(field_row(
399 "export-folder",
400 "Folder",
401 folder,
402 None,
403 folder_on,
404 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
405 this.begin_field(SheetField::Folder);
406 cx.notify();
407 })),
408 )),
409 )
410 .child(
411 Button::new("export-destination")
412 .icon(Icon::FolderOpen)
413 .style(ButtonStyle::Ghost)
414 .size(ButtonSize::Default)
415 .build()
416 .tooltip(crate::ui::widgets::overlay_tip_hover("Choose folder\u{2026}", "", None))
417 .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))),
418 ),
419 )
420 // A typed name or folder that was refused: why, under the fields, until it is fixed.
421 .children(match typed_clash {
422 true => Some(warn_line(SOURCE_NAME_TAKEN.to_string())),
423 false => self.export_sheet.note.clone().map(warn_line),
424 })
425 }
426
427 /// What will be written, in plain words: the file kind, codec, size, rate
428 /// and bitrate; then the sound, the encoder and the size on disk; then how
429 /// long it takes. The warnings and the reason the button is off sit under.
430 fn sheet_summary(&self, blocked: Option<&str>) -> impl IntoElement {
431 let seconds = self.export_seconds();
432 let sound = self.export_has_sound();
433 let target = self.export_canvas();
434 let project = self.session.as_ref().map_or(target, PlaybackSession::resolution);
435 let rate = self
436 .session
437 .as_ref()
438 .and_then(PlaybackSession::sample_rate)
439 .unwrap_or(48_000);
440 // A GPU seat writes AV1 to a quality and not to the budget, so the
441 // picture's part of the size is a span there.
442 let seat = self.encoder_seat();
443 let hardware = self
444 .export_seat
445 .as_ref()
446 .and_then(|(.., seats)| *seats)
447 .and_then(|(video, _)| video)
448 .is_some_and(|seat| seat.contains("VA-API") || seat.contains("GPU"));
449 let video_fixed = seat == EncoderSeat::Software || !hardware;
450 let size = size_estimate(
451 self.format,
452 self.budget_bps(),
453 self.audio_kbps,
454 sound,
455 seconds,
456 rate,
457 video_fixed,
458 );
459 let time = export_time_words(seconds, self.sheet_pace(), self.pace_pending());
460 let size_text = size_words(size);
461 let rows = summary_rows(&SummaryIn {
462 format: self.format,
463 target,
464 fps: self.fps,
465 bps: self.budget_bps(),
466 audio_kbps: self.audio_kbps,
467 sound,
468 seat,
469 depth: self.export_sheet.bit_depth,
470 prores: self.export_sheet.prores,
471 hdr: self.export_sheet.hdr,
472 hevc_speed: self.export_sheet.hevc_speed,
473 sound_bits: self.export_sheet.sound_bits,
474 size: &size_text,
475 gif: self.export_sheet.gif,
476 }, &time_short(&time));
477 let warns = warnings(&WarnCtx {
478 format: self.format,
479 target,
480 project,
481 fps: self.fps,
482 video_bps: self.budget_bps(),
483 timeline_has_picture: self.export_has_picture(),
484 timeline_has_sound: sound,
485 seconds,
486 });
487 // WebM carries no subtitle track: the engine's own reason, said here.
488 let subtitle_note = self
489 .session
490 .as_ref()
491 .filter(|_| self.format == Format::Webm)
492 .map(|s| s.planned_subtitles(self.format, 0..s.subtitles().len()))
493 .filter(|why| why != "none");
494 div()
495 .id("export-summary")
496 .flex()
497 .flex_col()
498 .gap(px(4.))
499 .child(section("Summary"))
500 .child(
501 div()
502 .id("export-summary-box")
503 .flex()
504 .flex_col()
505 .gap(px(4.))
506 .p(px(12.))
507 .rounded(px(6.))
508 .bg(rgb(tokens().e2))
509 .children(rows.into_iter().map(|(label, text)| summary_row(label, text))),
510 )
511 // One reserved line: a warning shows here and never moves anything.
512 .child(
513 div()
514 .id("export-warning")
515 .h(px(18.))
516 .overflow_hidden()
517 .whitespace_nowrap()
518 .type_style(type_scale::caption())
519 .text_color(rgb(tokens().warn))
520 .when(warns.len() > 1, |d| {
521 d.tooltip(crate::ui::widgets::overlay_tip_hover("Notes", "", Some(&warns.join(". "))))
522 })
523 .child(warns.first().cloned().unwrap_or_default()),
524 )
525 .children(subtitle_note.map(warn_line))
526 .children(blocked.map(|why| {
527 warn_line(format!("Cannot export: {why}. Pick another format under Details."))
528 }))
529 }
530
531 /// The Details: grouped, labelled rows, each a direct choice. A codec's own
532 /// rows (quality, bit depth, HDR, speed) are only listed for the codecs
533 /// they can change.
534 fn sheet_more(&self, cx: &mut Context<Self>) -> impl IntoElement {
535 let video = self.format.has_video();
536 let mut col = div().id("export-more").flex().flex_col().gap(px(10.));
537 // Video.
538 let seat = self.encoder_seat();
539 let budget = match &self.budget_edit {
540 // Empty, the field shows its example, and the caret sits before it.
541 Some(text) if text.is_empty() => "\u{258f}e.g. 8 Mb/s".to_string(),
542 Some(text) => format!("{text}\u{258f} Mb/s"),
543 None => format!("{} Mb/s", rate_label(self.budget_bps()).trim_end_matches(".0")),
544 };
545 let size = match self.export_sheet.size {
546 Some((w, h)) => format!("{w}\u{d7}{h}"),
547 None => self
548 .session
549 .as_ref()
550 .map_or("Same as project".to_string(), |s| {
551 let (w, h) = s.resolution();
552 format!("{w}\u{d7}{h} (project)")
553 }),
554 };
555 let av1 = matches!(self.format, Format::Av1 | Format::Av1Mp4 | Format::Webm);
556 let prores = self.format == Format::ProRes;
557 let hevc = self.format.is_hevc();
558 let depth = match self.export_sheet.bit_depth {
559 Some(d) => format!("{d}-bit"),
560 None => "Same as source".to_string(),
561 };
562 // A sound-only file has no picture settings at all, so the group is
563 // just the file kind; a video file lists the picture settings it has.
564 col = col
565 .child(sub_head(if video { "Video" } else { "Format" }))
566 .child(detail_row("export-d-container", "Container", drop_box("export-c-container", container_word(self.format).into(), Some(Self::pick_open(ExportRow::Container, cx))), None))
567 .child(detail_row("export-d-codec", "Codec", drop_box("export-c-codec", codec_word(self.format).into(), Some(Self::pick_open(ExportRow::Codec, cx))), None));
568 if video {
569 col = col
570 .child(detail_row("export-d-seat", "Encoder", drop_box("export-c-seat", encoder_label(seat).into(), Some(Self::pick_open(ExportRow::Seat, cx))), None))
571 .child(dim_line(seat_plain(seat).to_string()))
572 .child(detail_row(
573 "export-d-bitrate",
574 "Bitrate",
575 drop_box("export-c-bitrate", budget, (!prores).then(|| Self::pick_open(ExportRow::Bitrate, cx))),
576 prores.then(|| "ProRes sets its own rate: pick a quality".to_string()),
577 ))
578 .child(detail_row("export-d-size", "Resolution", drop_box("export-c-size", size, Some(Self::pick_open(ExportRow::Size, cx))), None))
579 .child(detail_row("export-d-fps", "Frame rate", info_note(format!("{} fps", fps_label(self.fps)), "follows the project"), None));
580 // A row only shows for a codec it can change: a setting with no
581 // possible value for this file is noise, so it is left out, not dimmed.
582 if prores {
583 col = col.child(detail_row(
584 "export-d-profile",
585 "Quality",
586 drop_box("export-c-profile", self.export_sheet.prores.name().into(), Some(Self::pick_open(ExportRow::Profile, cx))),
587 None,
588 ));
589 }
590 if av1 || hevc || prores {
591 col = col.child(detail_row(
592 "export-d-depth",
593 "Bit depth",
594 drop_box(
595 "export-c-depth",
596 if prores { "Always 10-bit".to_string() } else { depth },
597 (!prores).then(|| Self::pick_open(ExportRow::Depth, cx)),
598 ),
599 prores.then(|| "ProRes is always 10-bit".to_string()),
600 ));
601 }
602 if hevc {
603 col = col
604 .child(detail_row(
605 "export-d-hdr",
606 "HDR",
607 drop_box("export-c-hdr", hdr_row_word(self.export_sheet.hdr).into(), Some(Self::pick_open(ExportRow::Hdr, cx))),
608 None,
609 ))
610 .child(self.speed_row(seat, cx))
611 .child(dim_line(match self.hevc_on_gpu(seat) {
612 true => "Only for the software encoder".to_string(),
613 false => hevc_speed_plain(self.export_sheet.hevc_speed).to_string(),
614 }));
615 }
616 }
617 // Pictures and no sound: no encoder and no audio rows, only the picture's own settings.
618 if is_picture_set(self.format) {
619 if self.format == Format::Gif {
620 let looping = if self.export_sheet.gif.loop_forever { "Loop forever" } else { "Play once" };
621 col = col
622 .child(sub_head("GIF"))
623 .child(detail_row(
624 "export-d-gifwidth",
625 "Width",
626 drop_box("export-c-gifwidth", format!("{} px", self.export_sheet.gif.width), Some(Self::pick_open(ExportRow::GifWidth, cx))),
627 None,
628 ))
629 .child(detail_row(
630 "export-d-giffps",
631 "Frame rate",
632 drop_box("export-c-giffps", format!("{} fps", self.export_sheet.gif.fps), Some(Self::pick_open(ExportRow::GifFps, cx))),
633 None,
634 ))
635 .child(detail_row(
636 "export-d-gifloop",
637 "Loop",
638 drop_box("export-c-gifloop", looping.to_string(), Some(Self::pick_open(ExportRow::GifLoop, cx))),
639 None,
640 ));
641 }
642 return col.child(dim_line("These settings are remembered for next time.".to_string()));
643 }
644 // Audio.
645 let rated = self.audio_rate_refusal().is_none();
646 let rate = self.session.as_ref().and_then(PlaybackSession::sample_rate).unwrap_or(48_000);
647 let loud = match self.export_sheet.loudness {
648 None => "Off".to_string(),
649 Some(t) => LOUDNESS_CHOICES
650 .iter()
651 .find(|&&(_, lufs, peak)| t.lufs == lufs && t.true_peak_dbtp == peak)
652 .map_or_else(|| format!("{} LUFS", t.lufs), |&(label, ..)| label.to_string()),
653 };
654 let lossless = matches!(self.format, Format::Wav | Format::Flac);
655 col = col
656 .child(sub_head("Audio"))
657 .child(detail_row("export-d-acodec", "Codec", info_note(sound_codec_word(self.format).to_string(), "set by the file kind"), None));
658 // A lossless codec has no bitrate to choose.
659 if !lossless {
660 // Sound that is copied or coded by quality has no rate to pick: the row
661 // says why in plain words, both on hover and in a caption under it.
662 let why = self.audio_rate_refusal().map(audio_rate_words);
663 col = col.child(detail_row(
664 "export-d-kbps",
665 "Bitrate",
666 drop_box("export-c-kbps", format!("{} kb/s", self.audio_kbps), rated.then(|| Self::pick_open(ExportRow::Kbps, cx))),
667 why.clone(),
668 ));
669 col = col.children(why.map(dim_line));
670 }
671 col = col.child(detail_row("export-d-rate", "Sample rate", info_note(format!("{} kHz", f64::from(rate) / 1000.), "follows the project"), None));
672 if prores {
673 col = col.child(detail_row(
674 "export-d-soundbits",
675 "Sound depth",
676 drop_box(
677 "export-c-soundbits",
678 format!("{}-bit", self.export_sheet.sound_bits.unwrap_or(24)),
679 Some(Self::pick_open(ExportRow::SoundDepth, cx)),
680 ),
681 None,
682 ));
683 } else if self.format == Format::Wav {
684 col = col.child(detail_row("export-d-soundbits", "Sound depth", info_note("16-bit".to_string(), "set by the file kind"), None));
685 }
686 col = col
687 .child(detail_row("export-d-channels", "Channels", info_note("Stereo".to_string(), "the mix is stereo"), None))
688 .child(detail_row("export-d-loud", "Loudness", drop_box("export-c-loud", loud, Some(Self::pick_open(ExportRow::Loudness, cx))), None));
689 // Extras.
690 let chapters = self.session.as_ref().map_or(0, |s| s.chapters().len());
691 let tracks = self.export_subs().len();
692 let captions = match (tracks, self.export_sheet.no_captions) {
693 (_, true) => "Leave out",
694 _ => "Keep as a track",
695 };
696 // The chapters as description text ("00:00 Intro" lines), for a video's description.
697 let copy_chapters = kit::Button::new("export-copy-chapters")
698 .label("Copy chapters as text")
699 .style(ButtonStyle::Secondary)
700 .enabled(chapters > 0)
701 .build()
702 .tooltip(crate::ui::widgets::overlay_tip_hover(
703 "Copy chapters as text",
704 "",
705 (chapters == 0).then_some("Add chapters first: timeline markers"),
706 ))
707 .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.copy_chapters(cx)));
708 col = col.child(sub_head("Extras")).child(detail_row(
709 "export-d-chapters",
710 "Chapters",
711 info_note(
712 match chapters {
713 0 => "None".to_string(),
714 n => n.to_string(),
715 },
716 "from timeline markers",
717 ),
718 None,
719 ));
720 col = col.child(detail_row("export-d-chapters-copy", "", copy_chapters, None));
721 // No captions on the timeline: there is nothing to keep or leave out.
722 if tracks > 0 {
723 col = col.child(detail_row(
724 "export-d-captions",
725 "Captions",
726 drop_box("export-c-captions", captions.to_string(), Some(Self::pick_open(ExportRow::Captions, cx))),
727 None,
728 ));
729 }
730 col
731 .child(dim_line("These settings are remembered for next time.".to_string()))
732 }
733
734 /// Whether the picture is written by the GPU: Hardware picked, or Auto with a seat found.
735 fn hevc_on_gpu(&self, seat: EncoderSeat) -> bool {
736 let found = self
737 .export_seat
738 .as_ref()
739 .and_then(|(.., seats)| *seats)
740 .and_then(|(video, _)| video)
741 .is_some_and(|seat| seat.contains("VA-API") || seat.contains("GPU"));
742 seat == EncoderSeat::Hardware || (seat == EncoderSeat::Auto && found)
743 }
744
745 /// Encoding speed for an HEVC file: a segmented control, disabled with the
746 /// reason on hover when the GPU encodes it.
747 fn speed_row(&self, seat: EncoderSeat, cx: &mut Context<Self>) -> gpui::Stateful<Div> {
748 let gpu = self.hevc_on_gpu(seat);
749 let segments: Vec<kit::Segment> = HEVC_SPEEDS.iter().map(|&s| kit::Segment::text(hevc_speed_label(s))).collect();
750 let at = HEVC_SPEEDS.iter().position(|&s| s == self.export_sheet.hevc_speed).unwrap_or(0);
751 let me = cx.entity();
752 let on_select = move |i: usize, _: &mut Window, cx: &mut App| {
753 if let Some(&s) = HEVC_SPEEDS.get(i) {
754 me.update(cx, |this, cx| this.apply_export_pick(ExportPick::HevcSpeed(s), cx));
755 }
756 };
757 detail_row(
758 "export-d-speed",
759 "Speed",
760 kit::segmented_equal("export-c-speed", &segments, at, !gpu, None, on_select),
761 gpu.then(|| "Only for the software encoder".to_string()),
762 )
763 }
764
765 /// "That file already exists": three answers as buttons, in the footer's
766 /// place, so the question sits where the press that raised it was.
767 fn sheet_overwrite(&self, cx: &mut Context<Self>) -> impl IntoElement {
768 div()
769 .id("export-overwrite")
770 .flex_none()
771 .flex()
772 .flex_col()
773 .gap(px(8.))
774 .px(px(8.))
775 .py(px(12.))
776 .border_t_1()
777 .border_color(rgba(tokens().line))
778 .child(
779 div()
780 .type_style(type_scale::body_strong())
781 .text_color(rgb(tokens().warn))
782 .child(format!(
783 "{} already exists in this folder.",
784 file_name(&self.export_path)
785 )),
786 )
787 .child(
788 div()
789 .flex()
790 .flex_wrap()
791 .gap(px(8.))
792 .child(sheet_button(
793 "export-overwrite-cancel",
794 "Cancel",
795 Some("esc"),
796 false,
797 true,
798 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
799 this.answer_overwrite(Overwrite::Cancel, cx);
800 })),
801 ))
802 .child(sheet_button(
803 "export-overwrite-keep",
804 "Keep both",
805 Some("k"),
806 false,
807 true,
808 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
809 this.answer_overwrite(Overwrite::KeepBoth, cx);
810 })),
811 ))
812 .child(sheet_button(
813 "export-overwrite-replace",
814 "Replace",
815 Some("\u{21b5}"),
816 true,
817 true,
818 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
819 this.answer_overwrite(Overwrite::Replace, cx);
820 })),
821 )),
822 )
823 }
824
825 /// The running export: the bar, the two clocks, the route, and the way
826 /// out -- Keep editing closes the sheet and the export carries on (the
827 /// Export chip and the status bar keep its percentage); Cancel is two
828 /// presses, never one.
829 fn sheet_progress(&self, export: &ExportHandle, cx: &mut Context<Self>) -> impl IntoElement {
830 let progress = export.progress().clamp(0., 1.);
831 let elapsed = self.export_started.map_or(0., |t| t.elapsed().as_secs_f32());
832 // A stage before the encode (a stabilised clip's shake being measured)
833 // fills the bar with its own fraction and says its name; the encode's
834 // guess at what is left means nothing until it starts.
835 let stage = export.stage();
836 // The clock that counts up is measured; the one that counts down is a
837 // rolling estimate and says so until it has one.
838 let left = eta_secs(&self.export_marks, elapsed, progress)
839 .map_or_else(|| "estimating\u{2026}".to_owned(), |s| format!("about {} left", left_words(s)));
840 let percent_line = progress_words(stage, progress, &left);
841 let progress = stage.map_or(progress, |(_, f)| f.clamp(0., 1.));
842 let armed = self.cancel_armed;
843 // The engine's seat names are jargon; the only part worth saying is
844 // its notice about frames past the last picture.
845 let route = plain_route(sheet_format_name(self.format), export.encoders().as_deref());
846 let t = tokens();
847 div()
848 .id("export-progress")
849 .flex_1()
850 .flex()
851 .flex_col()
852 .gap(px(10.))
853 .px(px(8.))
854 .py(px(16.))
855 .child(
856 div()
857 .flex()
858 .items_center()
859 .gap(px(8.))
860 .type_style(type_scale::title())
861 .text_color(rgb(t.ink1))
862 .child(Icon::Upload.el(IconSize::Toolbar, t.accent))
863 .child("Exporting"),
864 )
865 .child(
866 div()
867 .truncate()
868 .type_style(type_scale::body())
869 .text_color(rgb(t.ink2))
870 .child(file_name(&self.export_path)),
871 )
872 .child(
873 // The bar only moves forward: the worker's progress is monotone.
874 div().h(px(6.)).rounded(px(3.)).bg(rgb(t.e3)).child(
875 div()
876 .h_full()
877 .w(relative(progress))
878 .rounded(px(3.))
879 .bg(rgb(t.accent)),
880 ),
881 )
882 .child(
883 div()
884 .type_style(type_scale::body())
885 .text_color(rgb(t.ink1))
886 .child(percent_line),
887 )
888 .child(dark_help(route))
889 .child(
890 div()
891 .flex()
892 .flex_wrap()
893 .gap(px(8.))
894 .pt(px(6.))
895 .when(armed, |d| {
896 d.child(sheet_button(
897 "export-keep",
898 "Keep exporting",
899 None,
900 false,
901 true,
902 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
903 this.cancel_armed = false;
904 cx.notify();
905 })),
906 ))
907 })
908 .child(sheet_button(
909 "export-cancel",
910 if armed { "Yes, cancel export" } else { "Cancel export" },
911 None,
912 false,
913 true,
914 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
915 match this.cancel_armed {
916 true => this.cancel_export(),
917 false => this.cancel_armed = true,
918 }
919 cx.notify();
920 })),
921 ))
922 )
923 }
924}
925
926/// The settings face's foot: one full-width Export button.
927fn sheet_footer(off: Option<String>, player: &Player, cx: &mut Context<Player>) -> impl IntoElement {
928 let enabled = off.is_none();
929 div()
930 .flex_none()
931 .px(px(8.))
932 .py(px(8.))
933 .border_t_1()
934 .border_color(rgba(tokens().line))
935 .flex()
936 .flex_col()
937 .gap(px(6.))
938 // Why the button is off, beside it and in words (the tooltip says it too).
939 .children(off.as_ref().map(|why| {
940 div()
941 .id("export-off-why")
942 .type_style(type_scale::caption())
943 .text_color(rgb(tokens().ink2))
944 .child(why.clone())
945 }))
946 .child({
947 let key = player.keymap.chord(ActionId::Export);
948 let queued = player.queue.is_going();
949 let b = Button::new("export-confirm")
950 .label("Export")
951 .style(ButtonStyle::Primary)
952 .size(ButtonSize::Hero)
953 .enabled(enabled)
954 .build()
955 .flex_1()
956 .tooltip(crate::ui::widgets::overlay_tip_hover(
957 if queued { "Add to the end of the queue" } else { "Export" },
958 key.as_ref(),
959 off.as_deref(),
960 ));
961 let q = Button::new("export-enqueue")
962 .label("Add to queue")
963 .style(ButtonStyle::Secondary)
964 .size(ButtonSize::Hero)
965 .enabled(enabled)
966 .build()
967 .flex_1()
968 .tooltip(crate::ui::widgets::overlay_tip_hover(
969 "Add to queue",
970 "",
971 off.as_deref(),
972 ));
973 div()
974 .flex()
975 .gap(px(8.))
976 .child(b.when(enabled, |b| {
977 b.on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.start_export(cx)))
978 }))
979 .child(q.when(enabled, |b| {
980 b.on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.enqueue_export(cx)))
981 }))
982 })
983}
984
985/// The calm warning for files the chosen range reads that are not on disk: how many, a Relink
986/// button for the first, and each one by name.
987fn sheet_missing(missing: &[PathBuf], cx: &mut Context<Player>) -> impl IntoElement {
988 let t = tokens();
989 let first = missing[0].clone();
990 div()
991 .id("export-missing")
992 .flex()
993 .flex_col()
994 .gap(px(4.))
995 .child(
996 div()
997 .flex()
998 .items_center()
999 .gap(px(8.))
1000 .child(
1001 div()
1002 .flex_1()
1003 .min_w(px(0.))
1004 .type_style(type_scale::body())
1005 .text_color(rgb(t.warn))
1006 .child(match missing.len() {
1007 1 => "1 file missing".to_string(),
1008 n => format!("{n} files missing"),
1009 }),
1010 )
1011 .child(chip(
1012 "export-relink",
1013 "Relink\u{2026}".to_string(),
1014 false,
1015 Box::new(cx.listener(move |this, _: &ClickEvent, _, cx| this.relink_pick(first.clone(), cx))),
1016 )),
1017 )
1018 .children(missing.iter().take(4).map(|p| {
1019 div()
1020 .truncate()
1021 .type_style(type_scale::caption())
1022 .text_color(rgb(t.ink3))
1023 .child(file_name(p))
1024 }))
1025 .children((missing.len() > 4).then(|| {
1026 div().type_style(type_scale::caption()).text_color(rgb(t.ink3)).child(format!("and {} more", missing.len() - 4))
1027 }))
1028}
1029
1030/// The finished file: where it is, how big, how long it took, and the two
1031/// things a person does next.
1032fn sheet_done(done: &ExportDone, cx: &mut Context<Player>) -> impl IntoElement {
1033 let t = tokens();
1034 let took = match done.wall_secs {
1035 w if w < 1. => "Done in under a second".to_string(),
1036 w if w < 60. => format!("Done in {} s", w.round() as u64),
1037 w => format!("Done in {}", left_words(w as f32)),
1038 };
1039 div()
1040 .id("export-done")
1041 .flex_1()
1042 .flex()
1043 .flex_col()
1044 .gap(px(10.))
1045 .px(px(8.))
1046 .py(px(16.))
1047 .child(
1048 div()
1049 .flex()
1050 .items_center()
1051 .gap(px(8.))
1052 .type_style(type_scale::title())
1053 .text_color(rgb(t.ink1))
1054 .child(Icon::CircleCheck.el(IconSize::Toolbar, t.ok))
1055 .child("Exported"),
1056 )
1057 .child(
1058 div()
1059 .truncate()
1060 .type_style(type_scale::body_strong())
1061 .text_color(rgb(t.ink1))
1062 .child(file_name(&done.path)),
1063 )
1064 .child(dark_help(format!("{} \u{b7} {took}", bytes_words(done.bytes))))
1065 .child(
1066 div()
1067 .id("export-done-folder")
1068 .truncate()
1069 .type_style(type_scale::caption())
1070 .text_color(rgb(t.ink3))
1071 .tooltip(crate::ui::widgets::overlay_tip_hover(
1072 &dest_dir_text(&done.path),
1073 "",
1074 None,
1075 ))
1076 .child(saved_in(&dest_dir_text(&done.path))),
1077 )
1078 .child(
1079 div()
1080 .flex()
1081 .flex_wrap()
1082 .gap(px(8.))
1083 .pt(px(6.))
1084 .child(sheet_button(
1085 "export-show-file",
1086 "Show in folder",
1087 None,
1088 false,
1089 true,
1090 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| this.show_export_in_folder(cx))),
1091 ))
1092 .child(sheet_button(
1093 "export-play",
1094 "Open",
1095 None,
1096 false,
1097 true,
1098 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| this.play_export(cx))),
1099 ))
1100 .child(sheet_button(
1101 "export-finish",
1102 "Done",
1103 Some("\u{21b5}"),
1104 true,
1105 true,
1106 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
1107 this.leave_sheet_face();
1108 cx.notify();
1109 })),
1110 )),
1111 )
1112}
1113
1114/// The folder a finished file landed in, in words: "Saved in Home" for the home folder.
1115fn saved_in(folder: &str) -> String {
1116 match folder {
1117 "~" => "Saved in Home".to_string(),
1118 f => format!("Saved in {}", short_folder(f)),
1119 }
1120}
1121
1122/// A cancelled export: said in the sheet, with the way back to the settings.
1123fn sheet_cancelled(cx: &mut Context<Player>) -> impl IntoElement {
1124 let t = tokens();
1125 div()
1126 .id("export-cancelled")
1127 .flex_1()
1128 .flex()
1129 .flex_col()
1130 .gap(px(10.))
1131 .px(px(8.))
1132 .py(px(16.))
1133 .child(
1134 div()
1135 .flex()
1136 .items_center()
1137 .gap(px(8.))
1138 .type_style(type_scale::title())
1139 .text_color(rgb(t.ink1))
1140 .child(Icon::X.el(IconSize::Toolbar, t.ink2))
1141 .child("Export cancelled"),
1142 )
1143 .child(
1144 div()
1145 .type_style(type_scale::body())
1146 .text_color(rgb(t.ink2))
1147 .child("Nothing was kept."),
1148 )
1149 .child(
1150 div().flex().flex_wrap().gap(px(8.)).pt(px(6.)).child(sheet_button(
1151 "export-back",
1152 "Back to settings",
1153 None,
1154 true,
1155 true,
1156 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
1157 this.leave_sheet_face();
1158 cx.notify();
1159 })),
1160 )),
1161 )
1162}
1163
1164/// A failed export in plain words, with the raw error on hover; the way back is
1165/// Retry or the settings, both in the Export tab.
1166fn sheet_failed(why: &str, folder: &str, cx: &mut Context<Player>) -> impl IntoElement {
1167 div()
1168 .id("export-failed")
1169 .flex_1()
1170 .flex()
1171 .flex_col()
1172 .gap(px(10.))
1173 .px(px(8.))
1174 .py(px(16.))
1175 .child(
1176 div()
1177 .flex()
1178 .items_center()
1179 .gap(px(8.))
1180 .type_style(type_scale::title())
1181 .text_color(rgb(tokens().ink1))
1182 .child(Icon::TriangleAlert.el(IconSize::Toolbar, tokens().warn))
1183 .child("Export did not finish"),
1184 )
1185 .child(
1186 // The raw engine text is kept for the hover; the sheet says what to do.
1187 div()
1188 .id("export-failed-why")
1189 .type_style(type_scale::body())
1190 .text_color(rgb(tokens().ink2))
1191 .tooltip(crate::ui::widgets::overlay_tip_hover(why, "", None))
1192 .child(crate::export_ui::failure_words(why, folder)),
1193 )
1194 .child(
1195 div()
1196 .flex()
1197 .flex_wrap()
1198 .gap(px(8.))
1199 .pt(px(6.))
1200 .child(sheet_button(
1201 "export-retry",
1202 "Retry",
1203 None,
1204 true,
1205 true,
1206 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
1207 this.export_sheet.failed = None;
1208 this.start_export(cx);
1209 })),
1210 ))
1211 .child(sheet_button(
1212 "export-back",
1213 "Back to settings",
1214 None,
1215 false,
1216 true,
1217 Box::new(cx.listener(|this, _: &ClickEvent, _, cx| {
1218 this.leave_sheet_face();
1219 cx.notify();
1220 })),
1221 )),
1222 )
1223}
1224
1225/// "Details": the one closed disclosure, remembered in the folds file.
1226fn more_toggle(open: bool, cx: &mut Context<Player>) -> impl IntoElement {
1227 let t = tokens();
1228 div()
1229 .id("export-more-toggle")
1230 .flex()
1231 .items_center()
1232 .gap(px(4.))
1233 .h(px(HIT_MIN))
1234 .cursor_pointer()
1235 .hover(|s| s.text_color(rgb(tokens().ink1)))
1236 .type_style(type_scale::section())
1237 .text_color(rgb(t.ink2))
1238 .on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
1239 toggle_fold(&mut this.folds, EXPORT_MORE_FOLD);
1240 save_folds(&this.folds);
1241 cx.notify();
1242 }))
1243 .child(
1244 match open {
1245 true => Icon::ChevronDown,
1246 false => Icon::ChevronRight,
1247 }
1248 .el(IconSize::Inline, t.ink2),
1249 )
1250 .child("Details")
1251}
1252
1253/// Time left in words: "6 s", "1 min 5 s" -- never a clock face.
1254pub(crate) fn length_words(secs: f32) -> String {
1255 left_words(secs)
1256}
1257
1258fn left_words(secs: f32) -> String {
1259 let secs = secs.max(0.).round() as u64;
1260 match secs {
1261 0..=59 => format!("{secs} s"),
1262 _ => format!("{} min {} s", secs / 60, secs % 60),
1263 }
1264}
1265
1266/// The running line in plain words: "42% \u{b7} about 12 s left" under the
1267/// heading, or the stage's own name while one runs before the encode.
1268pub(crate) fn progress_words(stage: Option<(&str, f32)>, progress: f32, left: &str) -> String {
1269 match stage {
1270 Some((name, f)) => format!("{name} \u{b7} {}%", (f.clamp(0., 1.) * 100.) as u32),
1271 None => format!("{}% \u{b7} {left}", (progress.clamp(0., 1.) * 100.) as u32),
1272 }
1273}
1274
1275/// The line under the bar: the format, and the engine's truncation notice if
1276/// it has one; never the encoder's internal name.
1277pub(crate) fn plain_route(format_name: &str, encoders: Option<&str>) -> String {
1278 match encoders.and_then(|e| e.split(" \u{b7} ").find(|p| p.contains("past the last picture"))) {
1279 Some(notice) => format!("{format_name} \u{b7} {notice}"),
1280 None => format_name.to_string(),
1281 }
1282}
1283
1284/// A folder shortened to its last two parts, `\u{2026}/Videos/exports`.
1285pub(crate) fn short_folder(dir: &str) -> String {
1286 let parts: Vec<&str> = dir.split('/').filter(|p| !p.is_empty()).collect();
1287 match parts.len() {
1288 0..=2 => dir.to_string(),
1289 n => format!("\u{2026}/{}/{}", parts[n - 2], parts[n - 1]),
1290 }
1291}
1292
1293/// The last `max` characters of `text`, led by an ellipsis when something was cut: what a field
1294/// being typed into shows, so the caret is always in view.
1295pub(crate) fn tail_of(text: &str, max: usize) -> String {
1296 let n = text.chars().count();
1297 match n > max {
1298 true => format!("\u{2026}{}", text.chars().skip(n - (max - 1)).collect::<String>()),
1299 false => text.to_string(),
1300 }
1301}
1302
1303fn section(text: &'static str) -> impl IntoElement {
1304 div().type_style(type_scale::section()).text_color(rgb(tokens().ink2)).child(text)
1305}
1306
1307fn sub_head(text: &'static str) -> impl IntoElement {
1308 div().pt(px(4.)).type_style(type_scale::section()).text_color(rgb(tokens().ink2)).child(text)
1309}
1310
1311fn warn_line(text: impl Into<SharedString>) -> impl IntoElement {
1312 div()
1313 .type_style(type_scale::caption())
1314 .text_color(rgb(tokens().warn))
1315 .child(text.into())
1316}
1317
1318/// A destination field: its name, the text (with a caret while typed into),
1319/// and a fixed suffix such as the extension.
1320fn field_row(
1321 id: &'static str,
1322 label: &'static str,
1323 text: String,
1324 suffix: Option<String>,
1325 typing: bool,
1326 on_click: OnClick,
1327) -> Div {
1328 let t = tokens();
1329 div()
1330 .flex()
1331 .items_center()
1332 .gap(px(8.))
1333 .child(
1334 div()
1335 .flex_none()
1336 .w(px(56.))
1337 .type_style(type_scale::body())
1338 .text_color(rgb(t.ink2))
1339 .child(label),
1340 )
1341 .child(
1342 div()
1343 .id(id)
1344 .flex_1()
1345 .min_w(px(0.))
1346 .h(px(28.))
1347 .flex()
1348 .items_center()
1349 .px(px(8.))
1350 .rounded(px(4.))
1351 .border_1()
1352 .border_color(match typing {
1353 true => rgb(t.accent).into(),
1354 false => gpui::hsla(0., 0., 0., 0.),
1355 })
1356 .bg(rgb(t.e2))
1357 .cursor_text()
1358 .hover(|s| s.bg(rgb(tokens().e3)))
1359 .on_click(on_click)
1360 .type_style(type_scale::body())
1361 .text_color(rgb(t.ink1))
1362 .child(div().min_w(px(0.)).truncate().child(text))
1363 .children(suffix.map(|s| div().flex_none().text_color(rgb(t.ink3)).child(s))),
1364 )
1365}
1366
1367/// A dropdown box: the value in force and a chevron; a click opens its list
1368/// where it was pressed. `None` is a box that takes no click.
1369fn drop_box(id: &'static str, text: String, on_click: Option<OnClick>) -> gpui::Stateful<Div> {
1370 let t = tokens();
1371 let live = on_click.is_some();
1372 div()
1373 .id(id)
1374 .w_full()
1375 .flex()
1376 .items_center()
1377 .gap(px(6.))
1378 .h(px(28.))
1379 .type_style(type_scale::body())
1380 .text_color(rgb(if live { t.ink1 } else { t.ink3 }))
1381 // A box that takes no click is not a field: plain muted text, no inset.
1382 .when(live, |d| {
1383 d.px(px(8.)).rounded(px(4.)).bg(rgb(t.e2)).cursor_pointer().hover(|s| s.bg(rgb(tokens().e3)))
1384 })
1385 .when(!live, |d| d.cursor_not_allowed())
1386 .when_some(on_click, |d, f| d.on_click(f))
1387 .child(crate::ui::anchor::probe(id))
1388 .child(div().flex_1().min_w(px(0.)).truncate().child(text))
1389 .when(live, |d| d.child(Icon::ChevronDown.el(IconSize::Inline, t.ink3)))
1390}
1391
1392/// A value the project owns, as plain text with a short dim note.
1393fn info_note(text: String, note: &'static str) -> gpui::Stateful<Div> {
1394 let t = tokens();
1395 div()
1396 .id(SharedString::from(format!("info-{note}-{text}")))
1397 .w_full()
1398 .h(px(28.))
1399 .flex()
1400 .items_center()
1401 .gap(px(6.))
1402 .overflow_hidden()
1403 .whitespace_nowrap()
1404 .type_style(type_scale::body())
1405 .text_color(rgb(t.ink1))
1406 .child(div().flex_none().child(text))
1407 .child(
1408 div()
1409 .min_w(px(0.))
1410 .truncate()
1411 .type_style(type_scale::caption())
1412 .text_color(rgb(t.ink3))
1413 .child(format!("\u{b7} {note}")),
1414 )
1415}
1416
1417/// One Details row: a fixed-width label, then the value. `off` is the reason
1418/// the row does not apply: the row dims and says so on hover; it never moves.
1419fn detail_row(id: &'static str, label: &'static str, value: impl IntoElement, off: Option<String>) -> gpui::Stateful<Div> {
1420 let tip: SharedString = off.clone().unwrap_or_default().into();
1421 div()
1422 .id(id)
1423 .flex()
1424 .items_center()
1425 .gap(px(8.))
1426 .child(
1427 div()
1428 .flex_none()
1429 .w(px(84.))
1430 .type_style(type_scale::body())
1431 .text_color(rgb(if off.is_some() { tokens().ink3 } else { tokens().ink2 }))
1432 .child(label),
1433 )
1434 .child(div().flex_1().min_w(px(0.)).child(value))
1435 .when(off.is_some(), |d| {
1436 d.cursor_not_allowed().tooltip(crate::ui::widgets::overlay_tip_hover(label, "", Some(&tip)))
1437 })
1438}
1439
1440/// One summary row: a dim fixed label column and the value on one line. A value
1441/// that does not fit is cut at its end, never wrapped, so no number is split
1442/// across two lines ("30 / Mb/s").
1443fn summary_row(label: &'static str, text: String) -> Div {
1444 let t = tokens();
1445 div()
1446 .flex()
1447 .gap(px(6.))
1448 .type_style(type_scale::caption())
1449 .child(div().flex_none().w(px(40.)).text_color(rgb(t.ink3)).child(label))
1450 .child(
1451 div()
1452 .flex_1()
1453 .min_w(px(0.))
1454 .whitespace_nowrap()
1455 .truncate()
1456 .text_color(rgb(t.ink1))
1457 .child(text),
1458 )
1459}
1460
1461/// One dim helper line, a single line that truncates rather than wraps.
1462fn dim_line(text: String) -> impl IntoElement {
1463 div()
1464 .truncate()
1465 .type_style(type_scale::caption())
1466 .text_color(rgb(tokens().ink3))
1467 .child(text)
1468}
1469
1470/// One half of a two-way segmented control (the kit's look: pills on an `e2`
1471/// track); `off` is the reason it cannot be picked (dim, on hover, no click).
1472fn seg(id: &'static str, label: &'static str, active: bool, off: Option<String>, on_click: OnClick) -> gpui::Stateful<Div> {
1473 let t = tokens();
1474 let live = off.is_none();
1475 let tip: SharedString = off.unwrap_or_default().into();
1476 div()
1477 .id(id)
1478 .flex_1()
1479 .flex()
1480 .items_center()
1481 .justify_center()
1482 .h(px(24.))
1483 .rounded(px(3.))
1484 .when(active, |d| d.bg(rgb(t.e3)))
1485 .type_style(type_scale::body_strong())
1486 .text_color(rgb(match (active, live) {
1487 (_, false) => t.ink4,
1488 (true, _) => t.ink1,
1489 _ => t.ink2,
1490 }))
1491 .when(live, |d| {
1492 d.cursor_pointer()
1493 .when(!active, |d| d.hover(|s| s.bg(rgba(crate::ui::theme::WASH_HOVER)).text_color(rgb(tokens().ink1))))
1494 .on_click(on_click)
1495 })
1496 .when(!live, |d| {
1497 d.cursor_not_allowed().tooltip(crate::ui::widgets::overlay_tip_hover(label, "", Some(&tip)))
1498 })
1499 .child(label)
1500}
1501
1502/// The track a [`seg`] pair sits in.
1503fn seg_track() -> Div {
1504 div().flex().gap(px(2.)).p(px(2.)).h(px(28.)).rounded(px(4.)).bg(rgb(tokens().e2))
1505}
1506
1507/// A small ghost button with an icon and a word.
1508fn chip(id: &'static str, label: String, _active: bool, on_click: OnClick) -> gpui::Stateful<Div> {
1509 Button::new(id)
1510 .icon(Icon::FolderOpen)
1511 .label(label)
1512 .style(ButtonStyle::Ghost)
1513 .size(ButtonSize::Default)
1514 .build()
1515 .on_click(on_click)
1516}
1517
1518/// A sheet button: a label and, where there is one, its key (in the tooltip,
1519/// not on the button). `primary` is the press the face is for.
1520fn sheet_button(
1521 id: &'static str,
1522 label: &'static str,
1523 chord: Option<&str>,
1524 primary: bool,
1525 enabled: bool,
1526 on_click: OnClick,
1527) -> impl IntoElement {
1528 let b = Button::new(id)
1529 .label(label)
1530 .style(if primary { ButtonStyle::Primary } else { ButtonStyle::Secondary })
1531 .size(ButtonSize::Large)
1532 .enabled(enabled)
1533 .build()
1534 .flex_1();
1535 let b = match (enabled, chord) {
1536 (true, Some(k)) if !k.is_empty() => {
1537 b.tooltip(crate::ui::widgets::overlay_tip_hover(label, k, None))
1538 }
1539 _ => b,
1540 };
1541 b.when(enabled, |b| b.on_click(on_click))
1542}
1543
1544#[cfg(test)]
1545mod plain_words_tests {
1546 use super::*;
1547
1548 #[test]
1549 fn progress_speaks_plainly_and_names_the_measuring_stage() {
1550 assert_eq!(progress_words(None, 0.42, "about 12 s left"), "42% \u{b7} about 12 s left");
1551 assert_eq!(progress_words(Some(("Measuring shake", 0.4)), 0.9, "x"), "Measuring shake \u{b7} 40%");
1552 }
1553
1554 #[test]
1555 fn the_route_never_prints_an_encoder_name() {
1556 let line = plain_route("MP4 \u{b7} H.264", Some("SW encode (ec-h264) \u{b7} AAC"));
1557 assert_eq!(line, "MP4 \u{b7} H.264");
1558 assert!(!plain_route("MP4", Some("SW encode (ec-h264)")).contains("ec-"));
1559 assert!(plain_route("MP4", Some("x \u{b7} 3 frames of the edit past the last picture")).contains("past the last picture"));
1560 }
1561
1562 #[test]
1563 fn a_long_folder_is_shortened_to_its_last_two_parts() {
1564 assert_eq!(short_folder("~/Videos/exports/2026/final"), "\u{2026}/2026/final");
1565 assert_eq!(short_folder("~/Videos"), "~/Videos");
1566 assert_eq!(tail_of("/tmp/sweep/f/out", 14), "\u{2026}p/sweep/f/out");
1567 assert_eq!(tail_of("abcdef", 4), "\u{2026}def");
1568 }
1569
1570 #[test]
1571 fn a_failed_write_says_what_to_do_and_keeps_the_raw_error_out_of_sight() {
1572 use crate::export_ui::failure_words;
1573 assert_eq!(failure_words("Permission denied (os error 13)", "~/ro"), "edith can't write to ~/ro. Pick another folder.");
1574 assert_eq!(failure_words("No space left on device (os error 28)", "~"), "The disk is full.");
1575 assert_eq!(failure_words("No such file or directory (os error 2)", "/gone"), "The folder /gone no longer exists.");
1576 assert_eq!(
1577 failure_words("No such file or directory (os error 2) \u{2014} missing: a.mp4, b.mp4", "~"),
1578 "A file is missing: a.mp4, b.mp4."
1579 );
1580 assert_eq!(failure_words("encoder stalled", "~"), "Something went wrong while writing the file.");
1581 }
1582
1583 #[test]
1584 fn the_done_line_says_where_the_file_landed_never_a_bare_tilde() {
1585 assert_eq!(saved_in("~"), "Saved in Home");
1586 assert_eq!(saved_in("~/Videos/exports/2026/final"), "Saved in \u{2026}/2026/final");
1587 }
1588}