edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching·0 forks·Rust·18.3 MiB·ff99ad6·Tahinli·6 days ago·1055 commits
| 1 | //! The File menu's project dialogs, drawn: Save version, Versions, Collect media. One plate |
| 2 | //! ([`kit::plate`]) centred over the picture, one scrim, kit buttons. The state and the keys |
| 3 | //! are `player::project_dialogs`. |
| 4 | |
| 5 | use gpui::SharedString; |
| 6 | |
| 7 | use crate::player::project_dialogs::{Collect, Dialog}; |
| 8 | use crate::ui::kit::{self, ButtonSize, ButtonStyle}; |
| 9 | use crate::ui::theme::tokens; |
| 10 | use crate::ui::type_scale::{self, Typeset}; |
| 11 | use crate::*; |
| 12 | |
| 13 | const W: f32 = 460.; |
| 14 | /// The record sheet's gap above the transport bar, in px. |
| 15 | const RECORD_CLEAR: f32 = 6.; |
| 16 | /// Below this much room over the viewer the record sheet drops its caption and hint. |
| 17 | const RECORD_ROOM: f32 = 380.; |
| 18 | /// Where the record sheet's room starts: under the menu bar, so it can cover the viewer's header too. |
| 19 | const RECORD_TOP: f32 = crate::layout::MENU_BAR_H; |
| 20 | /// Rows of the version list that show before it scrolls. |
| 21 | const ROWS: f32 = 6.; |
| 22 | const ROW_H: f32 = 40.; |
| 23 | |
| 24 | /// How many characters the path sheet's field shows before it starts cutting from the front. |
| 25 | const PATH_SHOWN: usize = 56; |
| 26 | |
| 27 | /// A face whose title is fixed text, as the shared plate wants it. |
| 28 | /// A source as the sheet names it: its description, else its name. |
| 29 | fn input_label(source: &engine::pulse::Source) -> String { |
| 30 | if source.description.is_empty() { source.name.clone() } else { source.description.clone() } |
| 31 | } |
| 32 | |
| 33 | fn titled((head, body, foot): (&'static str, AnyElement, Vec<AnyElement>)) -> (SharedString, AnyElement, Vec<AnyElement>) { |
| 34 | (head.into(), body, foot) |
| 35 | } |
| 36 | |
| 37 | fn plural(n: usize) -> &'static str { |
| 38 | if n == 1 { "" } else { "s" } |
| 39 | } |
| 40 | |
| 41 | impl Player { |
| 42 | pub(crate) fn project_dialog_card(&self, viewport: Size<Pixels>, cx: &mut Context<Self>) -> Option<AnyElement> { |
| 43 | let dialog = self.proj_dialog.as_ref()?; |
| 44 | let busy = self.collect_running(); |
| 45 | let area_h = crate::ui::stance::below_picture_floor(f32::from(viewport.height), self.split_px(Split::Bench, viewport)); |
| 46 | // The record sheet's room: from the viewer's top (under the menu bar and the |
| 47 | // viewer's title row) to just above the transport band, which is measured. |
| 48 | let band_top = crate::ui::anchor::box_of("record-band").map_or( |
| 49 | f32::from(viewport.height) - area_h - crate::layout::redesign::TRANSPORT_H, |
| 50 | |b| f32::from(b.origin.y), |
| 51 | ); |
| 52 | let over_viewer = band_top - RECORD_TOP - RECORD_CLEAR; |
| 53 | let (head, body, foot): (SharedString, AnyElement, Vec<AnyElement>) = match dialog { |
| 54 | Dialog::NewProject(d) => titled(self.new_project_face(d, cx)), |
| 55 | Dialog::SaveTemplate(d) => titled(self.save_template_face(d, cx)), |
| 56 | Dialog::SaveVersion(d) => titled(self.save_version_face(d, cx)), |
| 57 | Dialog::Captions(d) => titled(self.captions_face(d, cx)), |
| 58 | Dialog::Versions(d) => titled(self.versions_face(d, cx)), |
| 59 | Dialog::Collect(c) => titled(self.collect_face(c, cx)), |
| 60 | Dialog::PathEntry(d) => self.path_entry_face(d, cx), |
| 61 | Dialog::Notes(d) => titled(self.notes_face(d, cx)), |
| 62 | Dialog::Record(d) => titled(self.record_face(d, over_viewer < RECORD_ROOM, cx)), |
| 63 | }; |
| 64 | let plate = kit::dialog("project-dialog", W) |
| 65 | .child(kit::dialog_title(head)) |
| 66 | .child(body) |
| 67 | .child(kit::dialog_actions().children(foot)) |
| 68 | .when(busy, |d| d); |
| 69 | if let Dialog::Record(_) = dialog { |
| 70 | // The record sheet hangs over the viewer, above the transport bar, with no scrim: |
| 71 | // the timeline under it stays in view while the take runs. Clicks outside it do not |
| 72 | // close it; Cancel, Stop, its X and Esc do. |
| 73 | let right = self.split_px(Split::Inspector, viewport); |
| 74 | // Top and height, not bottom: the window's content is not as tall as the viewport |
| 75 | // size it is laid out against, so a bottom inset would land below the band. |
| 76 | let room = (band_top - RECORD_CLEAR - RECORD_TOP).max(0.); |
| 77 | return Some( |
| 78 | div() |
| 79 | .absolute() |
| 80 | .top(px(RECORD_TOP)) |
| 81 | .h(px(room)) |
| 82 | .left_0() |
| 83 | .right(px(right)) |
| 84 | .occlude() |
| 85 | .flex() |
| 86 | .flex_col() |
| 87 | .items_center() |
| 88 | .justify_end() |
| 89 | .child(plate) |
| 90 | .into_any_element(), |
| 91 | ); |
| 92 | } |
| 93 | let bottom = (f32::from(viewport.height) - area_h).max(0.); |
| 94 | Some( |
| 95 | kit::dialog_layer(bottom) |
| 96 | .on_mouse_down( |
| 97 | MouseButton::Left, |
| 98 | cx.listener(move |this, _: &MouseDownEvent, _, cx| { |
| 99 | // A copy under way is ended by its Cancel, not by a stray click. |
| 100 | if !this.collect_running() { |
| 101 | this.close_project_dialog(cx); |
| 102 | } |
| 103 | cx.stop_propagation(); |
| 104 | }), |
| 105 | ) |
| 106 | .child(plate) |
| 107 | .into_any_element(), |
| 108 | ) |
| 109 | } |
| 110 | |
| 111 | fn caption(text: impl Into<SharedString>) -> Div { |
| 112 | div().type_style(type_scale::caption()).text_color(rgb(tokens().ink3)).child(text.into()) |
| 113 | } |
| 114 | |
| 115 | fn new_project_face(&self, d: &crate::player::project_dialogs::NewProject, cx: &mut Context<Self>) -> (&'static str, AnyElement, Vec<AnyElement>) { |
| 116 | use crate::player::project_dialogs::{NEW_RATES, NEW_SIZES}; |
| 117 | use crate::ui::kit::Segment; |
| 118 | let t = tokens(); |
| 119 | let target = d.target(); |
| 120 | // The folder as the whole path, cut in the middle to fit; the tooltip has all of it. |
| 121 | let full_dir = d.dir.display().to_string(); |
| 122 | // One reserved line under the fields: a refusal, or where the file will land. |
| 123 | let note = match (&d.error, &target) { |
| 124 | (Some(e), _) => (e.clone(), t.err), |
| 125 | (None, Some(path)) if d.template.is_some() => (format!("{} is created in this folder", crate::files::file_name(path)), t.ink3), |
| 126 | (None, Some(path)) => { |
| 127 | let (w, h) = NEW_SIZES[d.size].1; |
| 128 | (format!("{w}\u{d7}{h} \u{b7} {} is created in this folder when you add footage", crate::files::file_name(path)), t.ink3) |
| 129 | } |
| 130 | _ => (String::new(), t.ink3), |
| 131 | }; |
| 132 | let all = d.field.all && !d.field.text.is_empty(); |
| 133 | let shown: AnyElement = match all { |
| 134 | true => div().bg(rgba(t.accent_wash)).child(d.field.text.clone()).into_any_element(), |
| 135 | false => SharedString::from(format!("{}▏", d.field.text)).into_any_element(), |
| 136 | }; |
| 137 | let row = |label: &'static str, control: AnyElement| { |
| 138 | div() |
| 139 | .flex() |
| 140 | .items_center() |
| 141 | .gap(px(12.)) |
| 142 | .child(div().flex_none().w(px(84.)).type_style(type_scale::body()).text_color(rgb(t.ink2)).child(label)) |
| 143 | .child(div().flex_1().min_w(px(0.)).flex().child(control)) |
| 144 | }; |
| 145 | let me = cx.entity(); |
| 146 | let sizes: Vec<Segment> = NEW_SIZES.iter().map(|(label, _)| Segment::text(*label)).collect(); |
| 147 | let rates: Vec<Segment> = NEW_RATES.iter().map(|r| Segment::text(format!("{r:.0}"))).collect(); |
| 148 | let body = div() |
| 149 | .flex() |
| 150 | .flex_col() |
| 151 | .gap(px(10.)) |
| 152 | .child(row( |
| 153 | "Name", |
| 154 | div() |
| 155 | .id("new-project-name") |
| 156 | .flex_1() |
| 157 | .h(px(ButtonSize::Large.height())) |
| 158 | .px(px(8.)) |
| 159 | .flex() |
| 160 | .items_center() |
| 161 | .rounded(px(crate::layout::redesign::R_CONTROL)) |
| 162 | .bg(rgb(t.e2)) |
| 163 | .border_1() |
| 164 | .border_color(rgb(t.accent)) |
| 165 | .cursor(CursorStyle::IBeam) |
| 166 | .type_style(type_scale::body()) |
| 167 | .text_color(rgb(t.ink1)) |
| 168 | .child(shown) |
| 169 | .into_any_element(), |
| 170 | )) |
| 171 | .child(row( |
| 172 | "Folder", |
| 173 | div() |
| 174 | .flex_1() |
| 175 | .min_w(px(0.)) |
| 176 | .flex() |
| 177 | .items_center() |
| 178 | .gap(px(8.)) |
| 179 | .child( |
| 180 | div() |
| 181 | .id("new-project-folder") |
| 182 | .flex_1() |
| 183 | .min_w(px(0.)) |
| 184 | .truncate() |
| 185 | .type_style(type_scale::body()) |
| 186 | .text_color(rgb(t.ink1)) |
| 187 | .tooltip(crate::ui::widgets::overlay_tip_hover(&full_dir, "", None)) |
| 188 | .child(crate::recent::middle(&full_dir, 28)), |
| 189 | ) |
| 190 | .child( |
| 191 | kit::Button::new("new-project-change") |
| 192 | .label("Change…") |
| 193 | .style(ButtonStyle::Secondary) |
| 194 | .build() |
| 195 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.choose_new_project_folder(cx))), |
| 196 | ) |
| 197 | .into_any_element(), |
| 198 | )) |
| 199 | .when(d.template.is_none(), |b| b.child(row( |
| 200 | "Size", |
| 201 | div() |
| 202 | .flex() |
| 203 | .items_center() |
| 204 | .gap(px(10.)) |
| 205 | .child(kit::segmented("new-project-size", &sizes, d.size, true, None, { |
| 206 | let me = me.clone(); |
| 207 | move |i, _, app| me.update(app, |this, cx| this.new_project_pick(Some(i), None, cx)) |
| 208 | })) |
| 209 | .into_any_element(), |
| 210 | )) |
| 211 | .child(row( |
| 212 | "Frame rate", |
| 213 | div() |
| 214 | .flex() |
| 215 | .items_center() |
| 216 | .gap(px(10.)) |
| 217 | .child(kit::segmented("new-project-rate", &rates, d.rate, true, None, { |
| 218 | let me = me.clone(); |
| 219 | move |i, _, app| me.update(app, |this, cx| this.new_project_pick(None, Some(i), cx)) |
| 220 | })) |
| 221 | .child(Self::caption("frames per second")) |
| 222 | .into_any_element(), |
| 223 | ))) |
| 224 | .when_some(d.template.clone(), |b, name| { |
| 225 | b.child(row( |
| 226 | "Template", |
| 227 | div() |
| 228 | .flex_1() |
| 229 | .min_w(px(0.)) |
| 230 | .truncate() |
| 231 | .type_style(type_scale::body()) |
| 232 | .text_color(rgb(t.ink1)) |
| 233 | .child(name) |
| 234 | .into_any_element(), |
| 235 | )) |
| 236 | }) |
| 237 | .child(div().h(px(16.)).type_style(type_scale::caption()).text_color(rgb(note.1)).child(note.0)) |
| 238 | .into_any_element(); |
| 239 | let foot = vec![ |
| 240 | kit::Button::new("new-project-cancel") |
| 241 | .label("Cancel") |
| 242 | .build() |
| 243 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 244 | .into_any_element(), |
| 245 | kit::Button::new("new-project-create") |
| 246 | .label("Create project") |
| 247 | .style(ButtonStyle::Primary) |
| 248 | .enabled(target.is_some()) |
| 249 | .build() |
| 250 | .tooltip(crate::ui::widgets::overlay_tip_hover("Create project", "", target.is_none().then_some("Type a name first"))) |
| 251 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.commit_new_project(cx))) |
| 252 | .into_any_element(), |
| 253 | ]; |
| 254 | (if d.template.is_some() { "New from template" } else { "New project" }, body, foot) |
| 255 | } |
| 256 | |
| 257 | /// Save as template: the name, the Keep clips switch and what it keeps. |
| 258 | fn save_template_face(&self, d: &crate::player::project_dialogs::SaveTemplate, cx: &mut Context<Self>) -> (&'static str, AnyElement, Vec<AnyElement>) { |
| 259 | let t = tokens(); |
| 260 | let name = d.field.text.trim(); |
| 261 | let note = match &d.error { |
| 262 | Some(e) => (e.clone(), t.err), |
| 263 | None => (String::new(), t.ink3), |
| 264 | }; |
| 265 | let all = d.field.all && !d.field.text.is_empty(); |
| 266 | let shown: AnyElement = match all { |
| 267 | true => div().bg(rgba(t.accent_wash)).child(d.field.text.clone()).into_any_element(), |
| 268 | false => SharedString::from(format!("{}▏", d.field.text)).into_any_element(), |
| 269 | }; |
| 270 | let me = cx.entity(); |
| 271 | let on = d.keep_clips; |
| 272 | let keep = kit::switch_row( |
| 273 | "template-keep-clips", |
| 274 | "Keep clips", |
| 275 | Some("Off: the settings only. On: the clips and their media too".into()), |
| 276 | on, |
| 277 | None, |
| 278 | move |_, app| me.update(app, |this, cx| this.set_template_keep_clips(!on, cx)), |
| 279 | ); |
| 280 | let body = div() |
| 281 | .flex() |
| 282 | .flex_col() |
| 283 | .gap(px(8.)) |
| 284 | .child(Self::caption("Keeps the frame rate, size, lanes, lane names, caption style and export preset for new projects.")) |
| 285 | .child( |
| 286 | div() |
| 287 | .id("template-name") |
| 288 | .h(px(ButtonSize::Large.height())) |
| 289 | .px(px(8.)) |
| 290 | .flex() |
| 291 | .items_center() |
| 292 | .rounded(px(crate::layout::redesign::R_CONTROL)) |
| 293 | .bg(rgb(t.e2)) |
| 294 | .border_1() |
| 295 | .border_color(rgb(t.accent)) |
| 296 | .cursor(CursorStyle::IBeam) |
| 297 | .type_style(type_scale::body()) |
| 298 | .text_color(rgb(t.ink1)) |
| 299 | .child(shown), |
| 300 | ) |
| 301 | .child(keep) |
| 302 | .child( |
| 303 | div() |
| 304 | .h(px(16.)) |
| 305 | .type_style(type_scale::caption()) |
| 306 | .text_color(rgb(note.1)) |
| 307 | .child(note.0), |
| 308 | ) |
| 309 | .into_any_element(); |
| 310 | let foot = vec![ |
| 311 | kit::Button::new("template-cancel") |
| 312 | .label("Cancel") |
| 313 | .build() |
| 314 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 315 | .into_any_element(), |
| 316 | kit::Button::new("template-save") |
| 317 | .label("Save template") |
| 318 | .style(ButtonStyle::Primary) |
| 319 | .enabled(!name.is_empty()) |
| 320 | .build() |
| 321 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.commit_save_template(cx))) |
| 322 | .into_any_element(), |
| 323 | ]; |
| 324 | ("Save as template", body, foot) |
| 325 | } |
| 326 | |
| 327 | /// File > Project notes: a box of several lines, the caret at its end, scrolling when the |
| 328 | /// notes run past it. Enter starts a line; Save (or Ctrl+Enter) keeps them. |
| 329 | fn notes_face(&self, d: &crate::player::project_dialogs::Notes, cx: &mut Context<Self>) -> (&'static str, AnyElement, Vec<AnyElement>) { |
| 330 | let t = tokens(); |
| 331 | let all = d.field.all && !d.field.text.is_empty(); |
| 332 | let caret = if all { "" } else { "▏" }; |
| 333 | let text = format!("{}{caret}", d.field.text); |
| 334 | let lines: Vec<AnyElement> = text |
| 335 | .split('\n') |
| 336 | .map(|line| div().min_h(px(20.)).when(all, |l| l.bg(rgba(t.accent_wash))).child(line.to_string()).into_any_element()) |
| 337 | .collect(); |
| 338 | let body = div() |
| 339 | .flex() |
| 340 | .flex_col() |
| 341 | .gap(px(8.)) |
| 342 | .child(Self::caption("Saved with the project. Enter starts a new line.")) |
| 343 | .child( |
| 344 | div() |
| 345 | .id("project-notes-field") |
| 346 | .h(px(180.)) |
| 347 | .w_full() |
| 348 | .p(px(8.)) |
| 349 | .rounded(px(crate::layout::redesign::R_CONTROL)) |
| 350 | .bg(rgb(t.e2)) |
| 351 | .border_1() |
| 352 | .border_color(rgb(t.accent)) |
| 353 | .overflow_y_scroll() |
| 354 | .cursor(CursorStyle::IBeam) |
| 355 | .type_style(type_scale::body()) |
| 356 | .text_color(rgb(t.ink1)) |
| 357 | .children(lines), |
| 358 | ) |
| 359 | .into_any_element(); |
| 360 | let foot = vec![ |
| 361 | kit::Button::new("notes-cancel") |
| 362 | .label("Cancel") |
| 363 | .build() |
| 364 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 365 | .into_any_element(), |
| 366 | kit::Button::new("notes-save") |
| 367 | .label("Save notes") |
| 368 | .style(ButtonStyle::Primary) |
| 369 | .build() |
| 370 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.commit_project_notes(cx))) |
| 371 | .into_any_element(), |
| 372 | ]; |
| 373 | ("Project notes", body, foot) |
| 374 | } |
| 375 | |
| 376 | /// The Record voice-over sheet: the input, the lane, whether the timeline is heard, a |
| 377 | /// level meter and the clock while a take runs, and Record or Stop. |
| 378 | fn record_face(&self, d: &crate::player::project_dialogs::RecordVoiceover, compact: bool, cx: &mut Context<Self>) -> (&'static str, AnyElement, Vec<AnyElement>) { |
| 379 | use crate::ui::kit::Segment; |
| 380 | let t = tokens(); |
| 381 | let me = cx.entity(); |
| 382 | let running = d.take.is_some(); |
| 383 | let lanes = self.audio_lanes(); |
| 384 | let mut inputs = vec![Segment::text("Default")]; |
| 385 | inputs.extend(d.inputs.iter().map(|s| Segment::text(input_label(s)))); |
| 386 | let input_pick = d.input.map_or(0, |i| i + 1); |
| 387 | let mut lane_names: Vec<Segment> = lanes.iter().map(|l| Segment::text(l.label())).collect(); |
| 388 | lane_names.push(Segment::text("New lane")); |
| 389 | let lane_pick = d.lane.and_then(|l| lanes.iter().position(|x| *x == l)).unwrap_or(lanes.len()); |
| 390 | let (level_db, elapsed) = match &d.take { |
| 391 | Some(take) => { |
| 392 | let status = take.recorder.status(); |
| 393 | (status.level_db, status.elapsed_secs) |
| 394 | } |
| 395 | None => (crate::player::voice_record::SILENT_DB, 0.0), |
| 396 | }; |
| 397 | let fill = ((level_db + 60.0) / 60.0).clamp(0.0, 1.0); |
| 398 | let fill_color = match level_db { |
| 399 | db if db > -1.0 => t.err, |
| 400 | db if db > -9.0 => t.warn, |
| 401 | _ => t.accent, |
| 402 | }; |
| 403 | let readout = match level_db <= crate::player::voice_record::SILENT_DB { |
| 404 | true => "silent".to_string(), |
| 405 | false => format!("{level_db:.0} dBFS"), |
| 406 | }; |
| 407 | let clock = format!("{}:{:04.1}", (elapsed / 60.0) as u32, elapsed % 60.0); |
| 408 | let row = |label: &'static str, control: AnyElement| { |
| 409 | div() |
| 410 | .flex() |
| 411 | .items_center() |
| 412 | .gap(px(12.)) |
| 413 | .child(div().flex_none().w(px(84.)).type_style(type_scale::body()).text_color(rgb(t.ink2)).child(label)) |
| 414 | .child(div().flex_1().min_w(px(0.)).flex().items_center().child(control)) |
| 415 | }; |
| 416 | let meter = div() |
| 417 | .relative() |
| 418 | .h(px(10.)) |
| 419 | .w_full() |
| 420 | .rounded(px(5.)) |
| 421 | .bg(rgb(t.e2)) |
| 422 | .border_1() |
| 423 | .border_color(rgb(t.edge)) |
| 424 | .child(div().absolute().top_0().left_0().h_full().w(relative(fill)).rounded(px(5.)).bg(rgb(fill_color))); |
| 425 | let note = match (&d.error, running) { |
| 426 | (Some(e), _) => (e.clone(), t.err), |
| 427 | _ if compact => (String::new(), t.ink3), |
| 428 | (None, true) => ("Stop places the take on its lane at the start point.".to_string(), t.ink3), |
| 429 | (None, false) => ("Recording starts at the playhead, and the timeline plays along.".to_string(), t.ink3), |
| 430 | }; |
| 431 | let on_input = { |
| 432 | let me = me.clone(); |
| 433 | move |i: usize, _: &mut Window, app: &mut App| me.update(app, |this, cx| this.record_pick_input(i, cx)) |
| 434 | }; |
| 435 | let on_lane = { |
| 436 | let me = me.clone(); |
| 437 | move |i: usize, _: &mut Window, app: &mut App| me.update(app, |this, cx| this.record_pick_lane(i, cx)) |
| 438 | }; |
| 439 | // Short windows keep the switch in the footer, beside the buttons, to save a row. |
| 440 | let hear = kit::switch_row( |
| 441 | "record-hear", |
| 442 | if compact { "Hear timeline" } else { "Hear the timeline while recording" }, |
| 443 | None, |
| 444 | d.hear, |
| 445 | None, |
| 446 | { |
| 447 | let me = me.clone(); |
| 448 | move |_: &mut Window, app: &mut App| me.update(app, |this, cx| this.record_toggle_hear(cx)) |
| 449 | }, |
| 450 | ); |
| 451 | // Short windows: the caption and hint go, and the clock joins the level row, so the |
| 452 | // sheet fits over the viewer at 720 lines. |
| 453 | let level = div() |
| 454 | .w_full() |
| 455 | .flex() |
| 456 | .items_center() |
| 457 | .gap(px(10.)) |
| 458 | .child(div().flex_1().min_w(px(0.)).child(meter)) |
| 459 | .child(div().flex_none().w(px(72.)).type_style(type_scale::body()).text_color(rgb(t.ink2)).child(readout)); |
| 460 | let mut body = div().flex().flex_col().gap(px(if compact { 6. } else { 10. })); |
| 461 | if !compact { |
| 462 | body = body.child(Self::caption("A voice-over from the microphone, placed on an audio lane at the playhead.")); |
| 463 | } |
| 464 | body = body |
| 465 | .child(row("Input", kit::segmented_wrap("record-input", &inputs, input_pick, !running, None, on_input).into_any_element())) |
| 466 | .child(row("Lane", kit::segmented_wrap("record-lane", &lane_names, lane_pick, !running, None, on_lane).into_any_element())); |
| 467 | let hear_in_foot = if compact { |
| 468 | Some(hear) |
| 469 | } else { |
| 470 | body = body.child(hear); |
| 471 | None |
| 472 | }; |
| 473 | body = match compact { |
| 474 | true => body.child(row("Level", level.child(div().flex_none().w(px(44.)).type_style(type_scale::body()).text_color(rgb(t.ink1)).child(clock)).into_any_element())), |
| 475 | false => body |
| 476 | .child(row("Level", level.into_any_element())) |
| 477 | .child(row("Time", div().type_style(type_scale::body()).text_color(rgb(t.ink1)).child(clock).into_any_element())) |
| 478 | .child(div().h(px(16.)).type_style(type_scale::caption()).text_color(rgb(note.1)).child(note.0.clone())), |
| 479 | }; |
| 480 | if compact && !note.0.is_empty() { |
| 481 | body = body.child(div().type_style(type_scale::caption()).text_color(rgb(note.1)).child(note.0)); |
| 482 | } |
| 483 | let body = body.into_any_element(); |
| 484 | let mut foot = match running { |
| 485 | true => vec![ |
| 486 | kit::Button::new("record-stop") |
| 487 | .label("Stop") |
| 488 | .style(ButtonStyle::Primary) |
| 489 | .build() |
| 490 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.record_stop(cx))) |
| 491 | .into_any_element(), |
| 492 | ], |
| 493 | false => { |
| 494 | let reason = if self.project_path.as_os_str().is_empty() { Some("Save the project first") } else { None }; |
| 495 | vec![ |
| 496 | kit::Button::new("record-cancel") |
| 497 | .label("Cancel") |
| 498 | .build() |
| 499 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 500 | .into_any_element(), |
| 501 | kit::Button::new("record-start") |
| 502 | .label("Record") |
| 503 | .style(ButtonStyle::Primary) |
| 504 | .enabled(reason.is_none()) |
| 505 | .build() |
| 506 | .tooltip(crate::ui::widgets::overlay_tip_hover("Record", "", reason)) |
| 507 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.record_start(cx))) |
| 508 | .into_any_element(), |
| 509 | ] |
| 510 | } |
| 511 | }; |
| 512 | if let Some(hear) = hear_in_foot { |
| 513 | foot.insert(0, div().flex_none().w(px(170.)).child(hear).into_any_element()); |
| 514 | } |
| 515 | ("Record voice-over", body, foot) |
| 516 | } |
| 517 | |
| 518 | fn captions_face(&self, d: &crate::player::project_dialogs::CaptionsExport, cx: &mut Context<Self>) -> (&'static str, AnyElement, Vec<AnyElement>) { |
| 519 | use crate::player::project_dialogs::CaptionFormat; |
| 520 | use crate::ui::kit::Segment; |
| 521 | let t = tokens(); |
| 522 | let typed = d.field.text.trim().to_string(); |
| 523 | let name_ok = !typed.is_empty() && !typed.contains(['/', '\\']); |
| 524 | let file = format!("{typed}.{}", d.format.ext()); |
| 525 | let folder = d.dir.display().to_string(); |
| 526 | let has_cues = self.session.as_ref().is_some_and(|s| !s.caption_cues().is_empty()); |
| 527 | // One reserved line under the fields: a refusal, where the file goes, or that it replaces one. |
| 528 | let note = match (&d.error, name_ok) { |
| 529 | (Some(e), _) => (e.clone(), t.err), |
| 530 | (None, false) => ("Type a name for the file".to_string(), t.ink3), |
| 531 | (None, true) if d.dir.join(&file).exists() => (format!("Replaces the file already in {}", crate::recent::middle(&folder, 28)), t.warn), |
| 532 | (None, true) => (format!("Writes {file} in {}", crate::recent::middle(&folder, 28)), t.ink3), |
| 533 | }; |
| 534 | let all = d.field.all && !d.field.text.is_empty(); |
| 535 | let shown: AnyElement = match all { |
| 536 | true => div().bg(rgba(t.accent_wash)).child(d.field.text.clone()).into_any_element(), |
| 537 | false => SharedString::from(format!("{}▏", d.field.text)).into_any_element(), |
| 538 | }; |
| 539 | let formats: Vec<Segment> = CaptionFormat::ALL |
| 540 | .iter() |
| 541 | .map(|f| Segment::text(match f { |
| 542 | CaptionFormat::Srt => "SRT", |
| 543 | CaptionFormat::Vtt => "WebVTT", |
| 544 | })) |
| 545 | .collect(); |
| 546 | let selected = CaptionFormat::ALL.iter().position(|f| *f == d.format).unwrap_or(0); |
| 547 | let me = cx.entity(); |
| 548 | let row = |label: &'static str, control: AnyElement| { |
| 549 | div() |
| 550 | .flex() |
| 551 | .items_center() |
| 552 | .gap(px(12.)) |
| 553 | .child(div().flex_none().w(px(84.)).type_style(type_scale::body()).text_color(rgb(t.ink2)).child(label)) |
| 554 | .child(div().flex_1().min_w(px(0.)).flex().child(control)) |
| 555 | }; |
| 556 | let body = div() |
| 557 | .flex() |
| 558 | .flex_col() |
| 559 | .gap(px(10.)) |
| 560 | .child(Self::caption("The timeline's captions as a text file that players and video sites read.")) |
| 561 | .child(row( |
| 562 | "Name", |
| 563 | div() |
| 564 | .id("captions-name") |
| 565 | .flex_1() |
| 566 | .h(px(ButtonSize::Large.height())) |
| 567 | .px(px(8.)) |
| 568 | .flex() |
| 569 | .items_center() |
| 570 | .rounded(px(crate::layout::redesign::R_CONTROL)) |
| 571 | .bg(rgb(t.e2)) |
| 572 | .border_1() |
| 573 | .border_color(rgb(t.accent)) |
| 574 | .cursor(CursorStyle::IBeam) |
| 575 | .type_style(type_scale::body()) |
| 576 | .text_color(rgb(t.ink1)) |
| 577 | .child(shown) |
| 578 | .into_any_element(), |
| 579 | )) |
| 580 | .child(row("Format", kit::segmented("captions-format", &formats, selected, true, None, { |
| 581 | let me = me.clone(); |
| 582 | move |i, _, app| me.update(app, |this, cx| this.captions_pick(i, cx)) |
| 583 | }) |
| 584 | .into_any_element())) |
| 585 | .child(div().h(px(16.)).type_style(type_scale::caption()).text_color(rgb(note.1)).child(note.0)) |
| 586 | .into_any_element(); |
| 587 | let foot = vec![ |
| 588 | kit::Button::new("captions-cancel") |
| 589 | .label("Cancel") |
| 590 | .build() |
| 591 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 592 | .into_any_element(), |
| 593 | kit::Button::new("captions-save") |
| 594 | .label("Save captions") |
| 595 | .style(ButtonStyle::Primary) |
| 596 | .enabled(name_ok && has_cues) |
| 597 | .build() |
| 598 | .tooltip(crate::ui::widgets::overlay_tip_hover("Save captions", "", (!has_cues).then_some("No captions on the timeline yet"))) |
| 599 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.commit_export_captions(cx))) |
| 600 | .into_any_element(), |
| 601 | ]; |
| 602 | ("Export captions", body, foot) |
| 603 | } |
| 604 | |
| 605 | fn save_version_face(&self, d: &crate::player::project_dialogs::SaveVersion, cx: &mut Context<Self>) -> (&'static str, AnyElement, Vec<AnyElement>) { |
| 606 | let t = tokens(); |
| 607 | let cleaned = engine::versions::clean_name(&d.field.text); |
| 608 | // One reserved line under the field: an error, the name it will get, or what it replaces. |
| 609 | let note = match (&d.error, &cleaned) { |
| 610 | (Some(e), _) => Some((e.clone(), t.err)), |
| 611 | (None, Some(name)) if *name != d.field.text => Some((format!("Saved as {name}: only letters, digits, - and _"), t.ink3)), |
| 612 | (None, Some(name)) => std::fs::metadata(engine::versions::file(&d.dir, name)) |
| 613 | .and_then(|m| m.modified()) |
| 614 | .ok() |
| 615 | .map(|at| (format!("Replaces the version saved {}", engine::versions::age_text(at)), t.warn)), |
| 616 | _ => None, |
| 617 | }; |
| 618 | let all = d.field.all && !d.field.text.is_empty(); |
| 619 | let shown: AnyElement = match all { |
| 620 | true => div().bg(rgba(t.accent_wash)).child(d.field.text.clone()).into_any_element(), |
| 621 | false => SharedString::from(format!("{}▏", d.field.text)).into_any_element(), |
| 622 | }; |
| 623 | let body = div() |
| 624 | .flex() |
| 625 | .flex_col() |
| 626 | .gap(px(8.)) |
| 627 | .child(Self::caption("Keeps a full copy of the project as it is now. Restore it later from File, Versions.")) |
| 628 | .child( |
| 629 | div() |
| 630 | .id("version-name") |
| 631 | .h(px(ButtonSize::Large.height())) |
| 632 | .px(px(8.)) |
| 633 | .flex() |
| 634 | .items_center() |
| 635 | .rounded(px(crate::layout::redesign::R_CONTROL)) |
| 636 | .bg(rgb(t.e2)) |
| 637 | .border_1() |
| 638 | .border_color(rgb(t.accent)) |
| 639 | .cursor(CursorStyle::IBeam) |
| 640 | .type_style(type_scale::body()) |
| 641 | .text_color(rgb(t.ink1)) |
| 642 | .child(shown), |
| 643 | ) |
| 644 | .child( |
| 645 | div() |
| 646 | .h(px(16.)) |
| 647 | .type_style(type_scale::caption()) |
| 648 | .text_color(rgb(note.as_ref().map_or(t.ink3, |n| n.1))) |
| 649 | .child(note.map(|n| n.0).unwrap_or_default()), |
| 650 | ) |
| 651 | .into_any_element(); |
| 652 | let foot = vec![ |
| 653 | kit::Button::new("version-cancel") |
| 654 | .label("Cancel") |
| 655 | .build() |
| 656 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 657 | .into_any_element(), |
| 658 | kit::Button::new("version-save") |
| 659 | .label("Save version") |
| 660 | .style(ButtonStyle::Primary) |
| 661 | .enabled(cleaned.is_some()) |
| 662 | .build() |
| 663 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.commit_save_version(cx))) |
| 664 | .into_any_element(), |
| 665 | ]; |
| 666 | ("Save version", body, foot) |
| 667 | } |
| 668 | |
| 669 | fn path_entry_face(&self, d: &crate::player::project_dialogs::PathEntry, cx: &mut Context<Self>) -> (SharedString, AnyElement, Vec<AnyElement>) { |
| 670 | use crate::player::project_dialogs::PathFor; |
| 671 | let t = tokens(); |
| 672 | let (title, action): (SharedString, &str) = match (d.what, &d.from) { |
| 673 | (PathFor::Import, _) => ("Import media".into(), "Import"), |
| 674 | (PathFor::OpenProject, _) => ("Open project".into(), "Open"), |
| 675 | (PathFor::Subtitles, _) => ("Import subtitles".into(), "Import"), |
| 676 | (PathFor::Lut { .. }, _) => ("Choose a look file".into(), "Choose"), |
| 677 | (PathFor::Relink, from) => { |
| 678 | let name = from.as_deref().map_or("file".to_string(), crate::files::file_name); |
| 679 | (format!("Relink {name}").into(), "Relink") |
| 680 | } |
| 681 | }; |
| 682 | let typed = !d.field.text.trim().is_empty(); |
| 683 | // A long path shows its end, where the caret is, behind a mark that says the start is cut. |
| 684 | let chars = d.field.text.chars().count(); |
| 685 | let seen = match chars > PATH_SHOWN { |
| 686 | true => format!("…{}", d.field.text.chars().skip(chars - (PATH_SHOWN - 1)).collect::<String>()), |
| 687 | false => d.field.text.clone(), |
| 688 | }; |
| 689 | let shown: AnyElement = match d.field.all && typed { |
| 690 | true => div().bg(rgba(t.accent_wash)).child(seen).into_any_element(), |
| 691 | false => SharedString::from(format!("{seen}▏")).into_any_element(), |
| 692 | }; |
| 693 | let body = div() |
| 694 | .flex() |
| 695 | .flex_col() |
| 696 | .gap(px(8.)) |
| 697 | .child(Self::caption("Type or paste the file's path.")) |
| 698 | .child( |
| 699 | div() |
| 700 | .id("path-entry") |
| 701 | .h(px(ButtonSize::Large.height())) |
| 702 | .px(px(8.)) |
| 703 | .flex() |
| 704 | .items_center() |
| 705 | .overflow_hidden() |
| 706 | .rounded(px(crate::layout::redesign::R_CONTROL)) |
| 707 | .bg(rgb(t.e2)) |
| 708 | .border_1() |
| 709 | .border_color(rgb(t.accent)) |
| 710 | .cursor(CursorStyle::IBeam) |
| 711 | .type_style(type_scale::body()) |
| 712 | .text_color(rgb(t.ink1)) |
| 713 | .child(shown), |
| 714 | ) |
| 715 | .child( |
| 716 | div() |
| 717 | .h(px(16.)) |
| 718 | .type_style(type_scale::caption()) |
| 719 | .text_color(rgb(if d.error.is_some() { t.err } else { t.ink3 })) |
| 720 | .child(d.error.clone().unwrap_or_default()), |
| 721 | ) |
| 722 | .into_any_element(); |
| 723 | let foot = vec![ |
| 724 | kit::Button::new("path-cancel") |
| 725 | .label("Cancel") |
| 726 | .build() |
| 727 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 728 | .into_any_element(), |
| 729 | kit::Button::new("path-go") |
| 730 | .label(action) |
| 731 | .style(ButtonStyle::Primary) |
| 732 | .enabled(typed) |
| 733 | .build() |
| 734 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.commit_path_entry(cx))) |
| 735 | .into_any_element(), |
| 736 | ]; |
| 737 | (title, body, foot) |
| 738 | } |
| 739 | |
| 740 | fn versions_face(&self, d: &crate::player::project_dialogs::VersionList, cx: &mut Context<Self>) -> (&'static str, AnyElement, Vec<AnyElement>) { |
| 741 | let t = tokens(); |
| 742 | let body: AnyElement = if d.rows.is_empty() { |
| 743 | Self::caption("Use File \u{25b8} Save version to keep one.").into_any_element() |
| 744 | } else { |
| 745 | let rows = d.rows.iter().enumerate().map(|(n, v)| { |
| 746 | let on = n == d.picked; |
| 747 | div() |
| 748 | .id(("version-row", n)) |
| 749 | .flex_none() |
| 750 | .h(px(ROW_H)) |
| 751 | .px(px(10.)) |
| 752 | .flex() |
| 753 | .items_center() |
| 754 | .justify_between() |
| 755 | .gap(px(12.)) |
| 756 | .rounded(px(crate::layout::redesign::R_CONTROL)) |
| 757 | .cursor_pointer() |
| 758 | .when(on, |r| r.bg(rgba(t.accent_wash))) |
| 759 | .when(!on, |r| r.hover(|s| s.bg(rgb(t.e3)))) |
| 760 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| this.pick_version(n, cx))) |
| 761 | .child(div().min_w(px(0.)).truncate().type_style(type_scale::body_strong()).text_color(rgb(t.ink1)).child(v.name.clone())) |
| 762 | .child( |
| 763 | div() |
| 764 | .flex_none() |
| 765 | .type_style(type_scale::caption()) |
| 766 | .text_color(rgb(t.ink3)) |
| 767 | .child(format!("{} · {} clip{}", engine::versions::age_text(v.saved), v.clips, plural(v.clips))), |
| 768 | ) |
| 769 | }); |
| 770 | div() |
| 771 | .flex() |
| 772 | .flex_col() |
| 773 | .gap(px(8.)) |
| 774 | .child( |
| 775 | div() |
| 776 | .id("version-rows") |
| 777 | .flex() |
| 778 | .flex_col() |
| 779 | .max_h(px(ROW_H * ROWS)) |
| 780 | .overflow_y_scroll() |
| 781 | .children(rows), |
| 782 | ) |
| 783 | .child(Self::caption(format!( |
| 784 | "Restoring is one undo step: {} brings back what you have now.", |
| 785 | self.keymap.display(ActionId::Undo) |
| 786 | ))) |
| 787 | .into_any_element() |
| 788 | }; |
| 789 | let mut foot = vec![ |
| 790 | kit::Button::new("versions-close") |
| 791 | .label("Close") |
| 792 | .build() |
| 793 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 794 | .into_any_element(), |
| 795 | ]; |
| 796 | if !d.rows.is_empty() { |
| 797 | foot.push( |
| 798 | kit::Button::new("versions-restore") |
| 799 | .label(if d.busy { "Restoring…" } else { "Restore" }) |
| 800 | .style(ButtonStyle::Primary) |
| 801 | .enabled(!d.busy) |
| 802 | .min_w(96.) |
| 803 | .build() |
| 804 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.restore_picked_version(cx))) |
| 805 | .into_any_element(), |
| 806 | ); |
| 807 | } |
| 808 | ("Versions", body, foot) |
| 809 | } |
| 810 | |
| 811 | fn collect_face(&self, c: &Collect, cx: &mut Context<Self>) -> (&'static str, AnyElement, Vec<AnyElement>) { |
| 812 | let t = tokens(); |
| 813 | let close = |id: &'static str, label: &'static str, primary: bool, cx: &mut Context<Self>| { |
| 814 | kit::Button::new(id) |
| 815 | .label(label) |
| 816 | .style(if primary { ButtonStyle::Primary } else { ButtonStyle::Secondary }) |
| 817 | .build() |
| 818 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_project_dialog(cx))) |
| 819 | .into_any_element() |
| 820 | }; |
| 821 | let line = |text: String| div().type_style(type_scale::body()).text_color(rgb(t.ink2)).child(text).into_any_element(); |
| 822 | match c { |
| 823 | Collect::Ask(plan) => { |
| 824 | let files = plan.items.len(); |
| 825 | let mut lines = vec![if files == 0 { |
| 826 | line("Nothing to copy: every file the project uses is already in this folder, or is generated.".into()) |
| 827 | } else { |
| 828 | line(format!( |
| 829 | "Copies {files} file{} ({}) into one folder and plays the project from the copies.", |
| 830 | plural(files), |
| 831 | engine::collect::size_text(plan.bytes()) |
| 832 | )) |
| 833 | }]; |
| 834 | if plan.generated > 0 { |
| 835 | lines.push(Self::caption(format!("{} generated, nothing to copy", plan.generated)).into_any_element()); |
| 836 | } |
| 837 | if !plan.offline.is_empty() { |
| 838 | let n = plan.offline.len(); |
| 839 | lines.push( |
| 840 | Self::caption(format!("{n} file{} {} missing and will be skipped", plural(n), if n == 1 { "is" } else { "are" })) |
| 841 | .text_color(rgb(t.warn)) |
| 842 | .into_any_element(), |
| 843 | ); |
| 844 | } |
| 845 | if plan.already > 0 { |
| 846 | lines.push(Self::caption(format!("{} already in this folder", plan.already)).into_any_element()); |
| 847 | } |
| 848 | let body = div() |
| 849 | .flex() |
| 850 | .flex_col() |
| 851 | .gap(px(8.)) |
| 852 | .children(lines) |
| 853 | .child( |
| 854 | // The whole path: wrapped at its slashes would need a break rule gpui |
| 855 | // lacks, so it shows with the middle dropped and the full text on hover. |
| 856 | div() |
| 857 | .id("collect-folder-path") |
| 858 | .min_h(px(ButtonSize::Large.height())) |
| 859 | .px(px(8.)) |
| 860 | .flex() |
| 861 | .items_center() |
| 862 | .rounded(px(crate::layout::redesign::R_CONTROL)) |
| 863 | .bg(rgb(t.e2)) |
| 864 | .border_1() |
| 865 | .border_color(rgba(t.line)) |
| 866 | .type_style(type_scale::body()) |
| 867 | .text_color(rgb(t.ink1)) |
| 868 | .tooltip(crate::ui::widgets::overlay_tip_hover("Destination folder", "", Some(&plan.folder.display().to_string()))) |
| 869 | .child(div().min_w(px(0.)).truncate().child(crate::recent::short_path(&plan.folder, 52))), |
| 870 | ) |
| 871 | .into_any_element(); |
| 872 | let foot = vec![ |
| 873 | kit::Button::new("collect-folder") |
| 874 | .label("Choose folder…") |
| 875 | .style(ButtonStyle::Secondary) |
| 876 | .build() |
| 877 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.choose_collect_folder(cx))) |
| 878 | .into_any_element(), |
| 879 | div().flex_1().into_any_element(), |
| 880 | close("collect-cancel", "Cancel", false, cx), |
| 881 | kit::Button::new("collect-go") |
| 882 | .label("Collect") |
| 883 | .style(ButtonStyle::Primary) |
| 884 | .enabled(files > 0) |
| 885 | .build() |
| 886 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.start_collect(cx))) |
| 887 | .into_any_element(), |
| 888 | ]; |
| 889 | ("Collect media", body, foot) |
| 890 | } |
| 891 | Collect::Run(run) => { |
| 892 | let done = run.done.load(std::sync::atomic::Ordering::Relaxed); |
| 893 | let cancelling = run.cancel.load(std::sync::atomic::Ordering::Relaxed); |
| 894 | let body = div() |
| 895 | .flex() |
| 896 | .flex_col() |
| 897 | .gap(px(8.)) |
| 898 | .child( |
| 899 | div().h(px(6.)).w_full().rounded(px(3.)).bg(rgb(t.e2)).child( |
| 900 | div().h_full().rounded(px(3.)).bg(rgb(t.accent)).w(relative(run.fraction())), |
| 901 | ), |
| 902 | ) |
| 903 | .child(Self::caption(format!( |
| 904 | "{} of {}{}", |
| 905 | engine::collect::size_text(done), |
| 906 | engine::collect::size_text(run.total), |
| 907 | if cancelling { " · cancelling…" } else { "" } |
| 908 | ))) |
| 909 | .into_any_element(); |
| 910 | let foot = vec![ |
| 911 | kit::Button::new("collect-stop") |
| 912 | .label("Cancel") |
| 913 | .enabled(!cancelling) |
| 914 | .build() |
| 915 | .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.cancel_collect(cx))) |
| 916 | .into_any_element(), |
| 917 | ]; |
| 918 | ("Collecting media", body, foot) |
| 919 | } |
| 920 | Collect::Done(lines) => { |
| 921 | let body = div().flex().flex_col().gap(px(6.)).children(lines.iter().cloned().map(line)).into_any_element(); |
| 922 | ("Media collected", body, vec![close("collect-done", "Done", true, cx)]) |
| 923 | } |
| 924 | Collect::Failed(why) => { |
| 925 | let body = div().type_style(type_scale::body()).text_color(rgb(t.err)).child(format!("{why}. Nothing was changed.")).into_any_element(); |
| 926 | ("Collect failed", body, vec![close("collect-failed", "Close", true, cx)]) |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | } |