The look panel picks the strand colour and reads a typed one
Browse files at this commit880e8a04c4dd97b8aaad167e890481602c496a99Parent: 7de7b97- feat
- the look panel picks the strand colour and reads a typed one
13 changed files +773 -43
- crates/app/src/main.rs +12 -2
- crates/app/src/player/actions.rs +10 -0
- crates/app/src/player/cards.rs +47 -2
- crates/app/src/player/export.rs +8 -0
- crates/app/src/player/library.rs +128 -12
- crates/app/src/player/timeline_edit.rs +3 -0
- crates/app/src/player/view.rs +11 -0
- crates/app/src/tests/cards.rs +205 -0
- crates/app/src/tests/media.rs +75 -3
- crates/app/src/tests/mod.rs +4 -2
- crates/app/src/transport.rs +73 -5
- crates/app/src/ui/dock_stance.rs +115 -17
- crates/app/src/ui/widgets.rs +82 -0
crates/app/src/main.rsmodified+12 -2
| @@ -761,13 +761,21 @@ struct Player { | |||
| 761 | viz_hs_dragging: bool, | 761 | viz_hs_dragging: bool, |
| 762 | /// The wheel's box, recorded at prepaint for a drag's window position. | 762 | /// The wheel's box, recorded at prepaint for a drag's window position. |
| 763 | viz_wheel: Rc<Cell<Bounds<Pixels>>>, | 763 | viz_wheel: Rc<Cell<Bounds<Pixels>>>, |
| 764 | + /// Which of the clip's two inks the look section's wheel and colour field | ||
| 765 | + /// act on ([`VizSlot`]): the clip's own colour, or the ring's dual half. | ||
| 766 | + /// The pick stays picked across clips, the way the dock tab's does. | ||
| 767 | + viz_slot: VizSlot, | ||
| 768 | + /// The colour field's text, while the Clip tab's colour row is being typed | ||
| 769 | + /// into ([`Player::edit_viz_hex`]). `None` is the row showing the colour | ||
| 770 | + /// itself; `Some` is the buffer, its refusal, and the caret on screen. | ||
| 771 | + viz_hex_edit: Option<ColorEdit>, | ||
| 764 | /// The ink the hand is on, held back because the worker still owes a frame | 772 | /// The ink the hand is on, held back because the worker still owes a frame |
| 765 | /// ([`Self::pending_color`]'s own reason, and a wheel sample is heavier | 773 | /// ([`Self::pending_color`]'s own reason, and a wheel sample is heavier |
| 766 | /// than a grade's: it is not a table entry but the painter's own input, so | 774 | /// than a grade's: it is not a table entry but the painter's own input, so |
| 767 | /// the write is what rebuilds the picture). What the wheel draws while it | 775 | /// the write is what rebuilds the picture). What the wheel draws while it |
| 768 | /// stands, and never lost -- the frame that lands writes it, and so does | 776 | /// stands, and never lost -- the frame that lands writes it, and so does |
| 769 | - /// the release. | 777 | + /// the release. The slot the sample was taken on rides with it. |
| 770 | - pending_viz: Option<(u8, u8)>, | 778 | + pending_viz: Option<(VizSlot, u8, u8)>, |
| 771 | /// Each slider's box, recorded at prepaint: a mouse listener is handed the | 779 | /// Each slider's box, recorded at prepaint: a mouse listener is handed the |
| 772 | /// window position only, so this is what a press and a drag are read against | 780 | /// window position only, so this is what a press and a drag are read against |
| 773 | /// ([`frac_along`]). One per band, because the press picks the row it landed | 781 | /// ([`frac_along`]). One per band, because the press picks the row it landed |
| @@ -1078,6 +1086,8 @@ fn main() { | |||
| 1078 | color_dragging: false, | 1086 | color_dragging: false, |
| 1079 | viz_hs_dragging: false, | 1087 | viz_hs_dragging: false, |
| 1080 | viz_wheel: Rc::default(), | 1088 | viz_wheel: Rc::default(), |
| 1089 | + viz_slot: VizSlot::Main, | ||
| 1090 | + viz_hex_edit: None, | ||
| 1081 | pending_viz: None, | 1091 | pending_viz: None, |
| 1082 | color_bars: std::array::from_fn(|_| Rc::default()), | 1092 | color_bars: std::array::from_fn(|_| Rc::default()), |
| 1083 | pending_color: None, | 1093 | pending_color: None, |
crates/app/src/player/actions.rsmodified+10 -0
| @@ -35,6 +35,16 @@ impl Player { | |||
| 35 | // an autosave a beat early over a refusal (nothing to regroup, say) | 35 | // an autosave a beat early over a refusal (nothing to regroup, say) |
| 36 | // costs nothing a real edit would not have earned anyway, and one list | 36 | // costs nothing a real edit would not have earned anyway, and one list |
| 37 | // here is the whole answer instead of fifteen scattered calls. | 37 | // here is the whole answer instead of fifteen scattered calls. |
| 38 | + // | ||
| 39 | + // This list is the *action* doors only, and that is the class to mind | ||
| 40 | + // when adding an edit: a control that reaches the session from a | ||
| 41 | + // *click* -- the Clip tab's look chips and wheel, the settings rows, | ||
| 42 | + // the library row's own menu -- is behind no action, so nothing here | ||
| 43 | + // arms it. Such a door has to call `Player::mark_dirty` itself, on its | ||
| 44 | + // own "the write took" gate, or the edit is invisible to autosave, to | ||
| 45 | + // the ledger's `unsaved` ghost and to `Player::close_needs_answer`, | ||
| 46 | + // which all read that one flag: the work is silently lost on close, | ||
| 47 | + // with no prompt to answer. | ||
| 38 | if matches!( | 48 | if matches!( |
| 39 | action, | 49 | action, |
| 40 | ActionId::Paste | 50 | ActionId::Paste |
crates/app/src/player/cards.rsmodified+47 -2
| @@ -38,6 +38,10 @@ impl Player { | |||
| 38 | pub(crate) fn apply_resolution(&mut self, width: u32, height: u32, cx: &mut Context<Self>) { | 38 | pub(crate) fn apply_resolution(&mut self, width: u32, height: u32, cx: &mut Context<Self>) { |
| 39 | if let Some(session) = &mut self.session { | 39 | if let Some(session) = &mut self.session { |
| 40 | if session.set_resolution(width, height) { | 40 | if session.set_resolution(width, height) { |
| 41 | + // A project field written from a click, with no keymap action | ||
| 42 | + // behind it to arm it ([`Player::act`]'s list is the action | ||
| 43 | + // doors only). | ||
| 44 | + self.mark_dirty(); | ||
| 41 | self.notify_user(format!("PROJECT: {width}x{height}").into()); | 45 | self.notify_user(format!("PROJECT: {width}x{height}").into()); |
| 42 | self.reset_after_reseek(); | 46 | self.reset_after_reseek(); |
| 43 | } | 47 | } |
| @@ -60,6 +64,9 @@ impl Player { | |||
| 60 | if let Some(session) = &mut self.session { | 64 | if let Some(session) = &mut self.session { |
| 61 | if session.set_frame_rate(fps) { | 65 | if session.set_frame_rate(fps) { |
| 62 | self.fps = session.meta().frame_rate; | 66 | self.fps = session.meta().frame_rate; |
| 67 | + // [`Self::apply_resolution`]'s own reason. Armed after the | ||
| 68 | + // session's own reads, since the borrow outlives nothing. | ||
| 69 | + self.mark_dirty(); | ||
| 63 | self.notify_user(format!("PROJECT: {} fps", fps_label(fps)).into()); | 70 | self.notify_user(format!("PROJECT: {} fps", fps_label(fps)).into()); |
| 64 | self.reset_after_reseek(); | 71 | self.reset_after_reseek(); |
| 65 | } | 72 | } |
| @@ -91,7 +98,15 @@ impl Player { | |||
| 91 | rate.map_or("the source's own rate".to_string(), |r| format!("{r} Hz")) | 98 | rate.map_or("the source's own rate".to_string(), |r| format!("{r} Hz")) |
| 92 | }; | 99 | }; |
| 93 | if let Some(session) = &mut self.session { | 100 | if let Some(session) = &mut self.session { |
| 101 | + let was = session.sample_rate(); | ||
| 94 | session.set_sample_rate(rate); | 102 | session.set_sample_rate(rate); |
| 103 | + // The engine's setter takes no answer back, so the arm is gated | ||
| 104 | + // on the setting having moved: picking the rate already in force | ||
| 105 | + // is not an edit. | ||
| 106 | + let changed = session.sample_rate() != was; | ||
| 107 | + if changed { | ||
| 108 | + self.mark_dirty(); | ||
| 109 | + } | ||
| 95 | self.notify_user( | 110 | self.notify_user( |
| 96 | format!( | 111 | format!( |
| 97 | "PROJECT SOUND: {} — takes effect on the next seek, edit or reopen", | 112 | "PROJECT SOUND: {} — takes effect on the next seek, edit or reopen", |
| @@ -122,6 +137,8 @@ impl Player { | |||
| 122 | if let Some(session) = &mut self.session | 137 | if let Some(session) = &mut self.session |
| 123 | && session.set_tone(preset) | 138 | && session.set_tone(preset) |
| 124 | { | 139 | { |
| 140 | + // [`Self::apply_resolution`]'s own reason. | ||
| 141 | + self.mark_dirty(); | ||
| 125 | self.notify_user(format!("HDR: {} — affects HDR media", tone_label(preset)).into()); | 142 | self.notify_user(format!("HDR: {} — affects HDR media", tone_label(preset)).into()); |
| 126 | self.reset_after_reseek(); | 143 | self.reset_after_reseek(); |
| 127 | } | 144 | } |
| @@ -673,8 +690,10 @@ impl Player { | |||
| 673 | if let Some(speed) = self.pending_speed.take() { | 690 | if let Some(speed) = self.pending_speed.take() { |
| 674 | self.write_speed(speed, true, cx); | 691 | self.write_speed(speed, true, cx); |
| 675 | } | 692 | } |
| 676 | - if let Some((hue, sat)) = self.pending_viz.take() { | 693 | + if let Some((_, hue, sat)) = self.pending_viz.take() { |
| 677 | - self.set_viz_hs(hue, sat, cx); | 694 | + // Live, as the two above are: the press is the one step this |
| 695 | + // gesture rolls back to (`Player::write_viz_hs`). | ||
| 696 | + self.write_viz_hs(hue, sat, true, cx); | ||
| 678 | } | 697 | } |
| 679 | } | 698 | } |
| 680 | 699 | ||
| @@ -1838,6 +1857,32 @@ impl Player { | |||
| 1838 | } | 1857 | } |
| 1839 | return true; | 1858 | return true; |
| 1840 | } | 1859 | } |
| 1860 | + // The Clip tab's colour field (`Player::edit_viz_hex`): the | ||
| 1861 | + // transition row's own keyboard door, and its free-text half -- | ||
| 1862 | + // checked here, beside it, for its reason (the Clip tab is always on | ||
| 1863 | + // screen, not modal). Every printable stroke lands in the buffer, so | ||
| 1864 | + // a letter that is also a room chord types into the field while it is | ||
| 1865 | + // open, exactly as the dock's source filter does. | ||
| 1866 | + if self.viz_hex_edit.is_some() { | ||
| 1867 | + match key { | ||
| 1868 | + ESCAPE => self.viz_hex_edit = None, | ||
| 1869 | + "enter" => self.commit_viz_hex(cx), | ||
| 1870 | + "backspace" => { | ||
| 1871 | + if let Some(edit) = self.viz_hex_edit.as_mut() { | ||
| 1872 | + edit.backspace(); | ||
| 1873 | + } | ||
| 1874 | + } | ||
| 1875 | + _ => match typed(key) { | ||
| 1876 | + Some(c) => { | ||
| 1877 | + if let Some(edit) = self.viz_hex_edit.as_mut() { | ||
| 1878 | + edit.typed(c); | ||
| 1879 | + } | ||
| 1880 | + } | ||
| 1881 | + None => return false, | ||
| 1882 | + }, | ||
| 1883 | + } | ||
| 1884 | + return true; | ||
| 1885 | + } | ||
| 1841 | // The Clip tab's transition duration field (DEBT #111): the same | 1886 | // The Clip tab's transition duration field (DEBT #111): the same |
| 1842 | // keyboard door as the export card's bitrate field, checked first | 1887 | // keyboard door as the export card's bitrate field, checked first |
| 1843 | // since it can be open while no card is (the Clip tab is always on | 1888 | // since it can be open while no card is (the Clip tab is always on |
crates/app/src/player/export.rsmodified+8 -0
| @@ -504,7 +504,15 @@ impl Player { | |||
| 504 | /// ([`Self::cache_export_seat`]). | 504 | /// ([`Self::cache_export_seat`]). |
| 505 | pub(crate) fn apply_encoder(&mut self, seat: EncoderSeat, cx: &mut Context<Self>) { | 505 | pub(crate) fn apply_encoder(&mut self, seat: EncoderSeat, cx: &mut Context<Self>) { |
| 506 | if let Some(session) = &mut self.session { | 506 | if let Some(session) = &mut self.session { |
| 507 | + let was = session.encoder_seat(); | ||
| 507 | session.set_encoder_seat(seat); | 508 | session.set_encoder_seat(seat); |
| 509 | + // The seat is written by a settings-row click, so nothing in | ||
| 510 | + // [`Player::act`]'s list arms it -- and the engine's setter takes | ||
| 511 | + // no answer back, so the arm rides the seat having moved. | ||
| 512 | + let changed = session.encoder_seat() != was; | ||
| 513 | + if changed { | ||
| 514 | + self.mark_dirty(); | ||
| 515 | + } | ||
| 508 | self.notify_user(format!("ENCODER: {}", encoder_label(seat)).into()); | 516 | self.notify_user(format!("ENCODER: {}", encoder_label(seat)).into()); |
| 509 | } | 517 | } |
| 510 | cx.notify(); | 518 | cx.notify(); |
crates/app/src/player/library.rsmodified+128 -12
| @@ -198,6 +198,11 @@ impl Player { | |||
| 198 | return; | 198 | return; |
| 199 | } | 199 | } |
| 200 | if session.set_visualizer(lane, idx, clip.visualizer ^ bit) { | 200 | if session.set_visualizer(lane, idx, clip.visualizer ^ bit) { |
| 201 | + // A look is a project field, so the write arms autosave and the | ||
| 202 | + // close prompt the same way a grade or a trim does -- these chips | ||
| 203 | + // are clicked, not dispatched through `act`, so nothing upstream | ||
| 204 | + // has armed it for them. | ||
| 205 | + self.mark_dirty(); | ||
| 201 | self.reset_after_reseek(); | 206 | self.reset_after_reseek(); |
| 202 | } | 207 | } |
| 203 | cx.notify(); | 208 | cx.notify(); |
| @@ -218,12 +223,15 @@ impl Player { | |||
| 218 | } | 223 | } |
| 219 | let next = engine::decode::with_viz_style(clip.visualizer, style); | 224 | let next = engine::decode::with_viz_style(clip.visualizer, style); |
| 220 | if next != clip.visualizer && session.set_visualizer(lane, idx, next) { | 225 | if next != clip.visualizer && session.set_visualizer(lane, idx, next) { |
| 226 | + // [`Self::toggle_viz_flag`]'s own reason: a clicked look arms | ||
| 227 | + // autosave here, because nothing upstream has. | ||
| 228 | + self.mark_dirty(); | ||
| 221 | self.reset_after_reseek(); | 229 | self.reset_after_reseek(); |
| 222 | } | 230 | } |
| 223 | cx.notify(); | 231 | cx.notify(); |
| 224 | } | 232 | } |
| 225 | 233 | ||
| 226 | - pub(crate) fn viz_paint(&self) -> u32 { | 234 | + pub(crate) fn viz_paint(&self) -> u64 { |
| 227 | self.selected | 235 | self.selected |
| 228 | .anchor() | 236 | .anchor() |
| 229 | .and_then(|(lane, idx)| { | 237 | .and_then(|(lane, idx)| { |
| @@ -236,13 +244,71 @@ impl Player { | |||
| 236 | .unwrap_or(0) | 244 | .unwrap_or(0) |
| 237 | } | 245 | } |
| 238 | 246 | ||
| 239 | - pub(crate) fn set_viz_hs(&mut self, hue: u8, sat: u8, cx: &mut Context<Self>) { | 247 | + /// Which of the two inks the look section's wheel and colour field act on |
| 248 | + /// ([`VizSlot`]). An open colour field is given up with the change: it is | ||
| 249 | + /// seeded with the picked slot's colour, so it would otherwise edit a | ||
| 250 | + /// colour the row is no longer showing. | ||
| 251 | + pub(crate) fn set_viz_slot(&mut self, slot: VizSlot, cx: &mut Context<Self>) { | ||
| 252 | + self.viz_slot = slot; | ||
| 253 | + self.viz_hex_edit = None; | ||
| 254 | + cx.notify(); | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + /// Opens the colour type-in on `seed`, the picked slot's colour as the row | ||
| 258 | + /// already shows it, so a backspace edits that rather than a field opening | ||
| 259 | + /// empty over a colour still in force ([`NumberEdit::new`]'s own rule). The | ||
| 260 | + /// transition row's field is given up: one inline editor at a time. | ||
| 261 | + pub(crate) fn edit_viz_hex(&mut self, seed: &str) { | ||
| 262 | + self.transition_edit = None; | ||
| 263 | + self.viz_hex_edit = Some(ColorEdit::new(seed)); | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + /// The colour field's enter. A colour it can read is written on the picked | ||
| 267 | + /// slot -- one undo step, a typed colour being one edit -- and the field | ||
| 268 | + /// closes. Anything else is refused *in words* with the field left open and | ||
| 269 | + /// the colour where it was, so the next try is a backspace away. | ||
| 270 | + pub(crate) fn commit_viz_hex(&mut self, cx: &mut Context<Self>) { | ||
| 271 | + let Some((hue, sat)) = self.viz_hex_edit.as_mut().and_then(|edit| edit.commit()) else { | ||
| 272 | + // Refused in words: the field stays open holding what it could | ||
| 273 | + // not read. | ||
| 274 | + cx.notify(); | ||
| 275 | + return; | ||
| 276 | + }; | ||
| 277 | + self.viz_hex_edit = None; | ||
| 278 | + // Nothing changed is not an edit. The field opens seeded with the | ||
| 279 | + // row's own `viz_color_hex`, and that hex reads back as a *different* | ||
| 280 | + // (hue, sat) for a large share of inks (the engine's round-trip | ||
| 281 | + // canary counts 47 053 of 65 536 exact), so a commit that wrote | ||
| 282 | + // whatever it parsed would take an undo step -- and arm autosave -- | ||
| 283 | + // for the colour the row was already showing, on an enter that | ||
| 284 | + // changed nothing. | ||
| 285 | + let paint = self.viz_paint(); | ||
| 286 | + let slot = self.viz_slot.picked(paint); | ||
| 287 | + if slot.hue_sat(paint) == (hue, sat) { | ||
| 288 | + cx.notify(); | ||
| 289 | + return; | ||
| 290 | + } | ||
| 291 | + self.write_viz_hs(hue, sat, false, cx); | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + /// Puts hue and saturation on the picked slot ([`VizSlot::picked`]): the | ||
| 295 | + /// wheel's sample and the colour field's commit both land here, so the two | ||
| 296 | + /// doors cannot disagree about which ink they write. | ||
| 297 | + /// | ||
| 298 | + /// `live` is [`Player::write_color`]'s own flag, for the colour card's | ||
| 299 | + /// reason: the false one takes the undo step the whole gesture rolls back | ||
| 300 | + /// to, the true one is every sample *inside* a drag | ||
| 301 | + /// (`PlaybackSession::set_viz_paint_live`). A wheel sample is not a table | ||
| 302 | + /// entry but the painter's own input, and it is the write that rebuilds the | ||
| 303 | + /// picture at the playhead -- so one committed entry per pointer sample | ||
| 304 | + /// would stamp a sixty-entry gesture into a hundred-step history and leave | ||
| 305 | + /// the user a hundred-step history of one drag. | ||
| 306 | + pub(crate) fn write_viz_hs(&mut self, hue: u8, sat: u8, live: bool, cx: &mut Context<Self>) { | ||
| 240 | // A write supersedes whatever a drag was holding | 307 | // A write supersedes whatever a drag was holding |
| 241 | // ([`Player::write_color`]'s rule). | 308 | // ([`Player::write_color`]'s rule). |
| 242 | self.pending_viz = None; | 309 | self.pending_viz = None; |
| 243 | - self.set_viz_paint_with(cx, |p| { | 310 | + let slot = self.viz_slot; |
| 244 | - engine::decode::with_viz_paint_sat(engine::decode::with_viz_paint_hue(p, hue), sat) | 311 | + self.set_viz_paint_with(live, move |p| slot.picked(p).set_hue_sat(p, hue, sat), cx); |
| 245 | - }); | ||
| 246 | } | 312 | } |
| 247 | 313 | ||
| 248 | /// One pointer sample on the wheel, as the hue and saturation under it. | 314 | /// One pointer sample on the wheel, as the hue and saturation under it. |
| @@ -270,9 +336,13 @@ impl Player { | |||
| 270 | let ang = dx.atan2(dy).to_degrees(); | 336 | let ang = dx.atan2(dy).to_degrees(); |
| 271 | let hue_deg = (ang + 360.) % 360.; | 337 | let hue_deg = (ang + 360.) % 360.; |
| 272 | let hue = (hue_deg / 360. * 256.).round() as u16 as u8; | 338 | let hue = (hue_deg / 360. * 256.).round() as u16 as u8; |
| 339 | + // The slot is read once, at the sample that carries it: whichever ink | ||
| 340 | + // the hand picked up is the one the whole gesture writes, and the slot | ||
| 341 | + // is what the held sample draws with while the worker catches up. | ||
| 342 | + let slot = self.viz_slot.picked(self.viz_paint()); | ||
| 273 | let busy = self.seek_since.is_some(); | 343 | let busy = self.seek_since.is_some(); |
| 274 | - match stash_or_write(&mut self.pending_viz, (hue, sat), first, busy) { | 344 | + match stash_or_write(&mut self.pending_viz, (slot, hue, sat), first, busy) { |
| 275 | - Some((hue, sat)) => self.set_viz_hs(hue, sat, cx), | 345 | + Some((_, hue, sat)) => self.write_viz_hs(hue, sat, !first, cx), |
| 276 | // The wheel draws off the held sample, so the mark goes on | 346 | // The wheel draws off the held sample, so the mark goes on |
| 277 | // following the hand while the picture catches up. | 347 | // following the hand while the picture catches up. |
| 278 | None => cx.notify(), | 348 | None => cx.notify(), |
| @@ -280,14 +350,23 @@ impl Player { | |||
| 280 | } | 350 | } |
| 281 | 351 | ||
| 282 | pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context<Self>) { | 352 | pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context<Self>) { |
| 283 | - self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_strands(p, n)); | 353 | + self.set_viz_paint_with(false, |p| engine::decode::with_viz_paint_strands(p, n), cx); |
| 284 | } | 354 | } |
| 285 | 355 | ||
| 286 | pub(crate) fn set_viz_glow(&mut self, n: u8, cx: &mut Context<Self>) { | 356 | pub(crate) fn set_viz_glow(&mut self, n: u8, cx: &mut Context<Self>) { |
| 287 | - self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_glow(p, n)); | 357 | + self.set_viz_paint_with(false, |p| engine::decode::with_viz_paint_glow(p, n), cx); |
| 288 | } | 358 | } |
| 289 | 359 | ||
| 290 | - fn set_viz_paint_with(&mut self, cx: &mut Context<Self>, f: impl FnOnce(u32) -> u32) { | 360 | + /// `live` picks the door, as [`Player::write_viz_hs`] does: the strands and |
| 361 | + /// glow steppers are presses and take their own undo step, and the two are | ||
| 362 | + /// on the packed bytes rather than on either ink, so they are unaffected by | ||
| 363 | + /// which slot the wheel is on. | ||
| 364 | + fn set_viz_paint_with( | ||
| 365 | + &mut self, | ||
| 366 | + live: bool, | ||
| 367 | + f: impl FnOnce(u64) -> u64, | ||
| 368 | + cx: &mut Context<Self>, | ||
| 369 | + ) { | ||
| 291 | let Some((lane, idx)) = self.selected.anchor() else { | 370 | let Some((lane, idx)) = self.selected.anchor() else { |
| 292 | return; | 371 | return; |
| 293 | }; | 372 | }; |
| @@ -301,8 +380,24 @@ impl Player { | |||
| 301 | return; | 380 | return; |
| 302 | } | 381 | } |
| 303 | let next = f(clip.viz_paint); | 382 | let next = f(clip.viz_paint); |
| 304 | - if next != clip.viz_paint && session.set_viz_paint(lane, idx, next) { | 383 | + if next != clip.viz_paint { |
| 305 | - self.reset_after_reseek(); | 384 | + let took = match live { |
| 385 | + true => session.set_viz_paint_live(lane, idx, next), | ||
| 386 | + false => session.set_viz_paint(lane, idx, next), | ||
| 387 | + }; | ||
| 388 | + if took { | ||
| 389 | + // Every look write arms autosave and the close gate | ||
| 390 | + // (`write_color`'s own rule, and these doors have no keymap | ||
| 391 | + // action behind them to arm it the way `act` does for the | ||
| 392 | + // verbs): the wheel's press, a strands/glow stepper and a | ||
| 393 | + // typed colour all land here. The drag's live samples land | ||
| 394 | + // here too, which is why the arm is on the write and not on | ||
| 395 | + // the gesture -- `mark_dirty` is idempotent, so the press, the | ||
| 396 | + // samples and the release are one armed edit rather than | ||
| 397 | + // sixty. | ||
| 398 | + self.mark_dirty(); | ||
| 399 | + self.reset_after_reseek(); | ||
| 400 | + } | ||
| 306 | } | 401 | } |
| 307 | cx.notify(); | 402 | cx.notify(); |
| 308 | } | 403 | } |
| @@ -339,6 +434,11 @@ impl Player { | |||
| 339 | // past the one that went has just moved down: without this the | 434 | // past the one that went has just moved down: without this the |
| 340 | // next paste puts some other file on the timeline. | 435 | // next paste puts some other file on the timeline. |
| 341 | self.clipboard = clipboard_after_remove(std::mem::take(&mut self.clipboard), idx); | 436 | self.clipboard = clipboard_after_remove(std::mem::take(&mut self.clipboard), idx); |
| 437 | + // The library is project state, and this door is the row's | ||
| 438 | + // own menu click -- nothing in [`Player::act`]'s list arms | ||
| 439 | + // it. Behind the `Ok`, so a refusal (the engine's own words | ||
| 440 | + // while clips still play the file) is not an edit. | ||
| 441 | + self.mark_dirty(); | ||
| 342 | self.reset_after_reseek(); | 442 | self.reset_after_reseek(); |
| 343 | // The last row leaves a session naming no file: nothing to | 443 | // The last row leaves a session naming no file: nothing to |
| 344 | // play, nothing to save and nothing to show, which is the empty | 444 | // play, nothing to save and nothing to show, which is the empty |
| @@ -1020,6 +1120,12 @@ impl Player { | |||
| 1020 | pub(crate) fn apply_proxies(&mut self) { | 1120 | pub(crate) fn apply_proxies(&mut self) { |
| 1021 | let (on, auto) = (self.proxies_on, self.auto_proxies_on); | 1121 | let (on, auto) = (self.proxies_on, self.auto_proxies_on); |
| 1022 | if let Some(session) = &mut self.session { | 1122 | if let Some(session) = &mut self.session { |
| 1123 | + // Deliberately not armed: the only caller is | ||
| 1124 | + // [`Self::install_media`], the import/load path, where arming is | ||
| 1125 | + // the one thing the `autosave_armed` rule forbids -- a project | ||
| 1126 | + // nobody has written must not start asking to be saved. The | ||
| 1127 | + // user's own door is the switch ([`Self::toggle_proxies`] / | ||
| 1128 | + // [`Self::toggle_auto_proxies`]), and that is where the arm is. | ||
| 1023 | session.set_proxies(on); | 1129 | session.set_proxies(on); |
| 1024 | session.set_auto_proxies(auto); | 1130 | session.set_auto_proxies(auto); |
| 1025 | } | 1131 | } |
| @@ -1062,7 +1168,11 @@ impl Player { | |||
| 1062 | let on = !self.proxies_on; | 1168 | let on = !self.proxies_on; |
| 1063 | self.proxies_on = on; | 1169 | self.proxies_on = on; |
| 1064 | if let Some(session) = &mut self.session { | 1170 | if let Some(session) = &mut self.session { |
| 1171 | + let changed = session.proxies() != on; | ||
| 1065 | session.set_proxies(on); | 1172 | session.set_proxies(on); |
| 1173 | + if changed { | ||
| 1174 | + self.mark_dirty(); | ||
| 1175 | + } | ||
| 1066 | } | 1176 | } |
| 1067 | // What is really under the switch, said in the same breath: a project | 1177 | // What is really under the switch, said in the same breath: a project |
| 1068 | // whose films have no stand-in yet would otherwise read as a switch | 1178 | // whose films have no stand-in yet would otherwise read as a switch |
| @@ -1124,7 +1234,13 @@ impl Player { | |||
| 1124 | let on = !self.auto_proxies_on; | 1234 | let on = !self.auto_proxies_on; |
| 1125 | self.auto_proxies_on = on; | 1235 | self.auto_proxies_on = on; |
| 1126 | if let Some(session) = &mut self.session { | 1236 | if let Some(session) = &mut self.session { |
| 1237 | + // [`Self::toggle_proxies`]'s own gate: the switch is a click and | ||
| 1238 | + // the session is where the project hears it. | ||
| 1239 | + let changed = session.auto_proxies() != on; | ||
| 1127 | session.set_auto_proxies(on); | 1240 | session.set_auto_proxies(on); |
| 1241 | + if changed { | ||
| 1242 | + self.mark_dirty(); | ||
| 1243 | + } | ||
| 1128 | } | 1244 | } |
| 1129 | let text = match on { | 1245 | let text = match on { |
| 1130 | true => "AUTO PROXIES ON — every import gets a stand-in", | 1246 | true => "AUTO PROXIES ON — every import gets a stand-in", |
crates/app/src/player/timeline_edit.rsmodified+3 -0
| @@ -1820,6 +1820,9 @@ impl Player { | |||
| 1820 | /// offers a number a step could not also land on. | 1820 | /// offers a number a step could not also land on. |
| 1821 | pub(crate) fn edit_transition(&mut self, frames: u32, cap: u32) { | 1821 | pub(crate) fn edit_transition(&mut self, frames: u32, cap: u32) { |
| 1822 | let digits = cap.to_string().chars().count() + 1; | 1822 | let digits = cap.to_string().chars().count() + 1; |
| 1823 | + // The Clip tab's colour field is given up: one inline editor at a | ||
| 1824 | + // time, since both are driven by the one key branch that finds them. | ||
| 1825 | + self.viz_hex_edit = None; | ||
| 1823 | self.transition_edit = Some(NumberEdit::new(frames, 0, cap, digits, "frames")); | 1826 | self.transition_edit = Some(NumberEdit::new(frames, 0, cap, digits, "frames")); |
| 1824 | } | 1827 | } |
| 1825 | 1828 | ||
crates/app/src/player/view.rsmodified+11 -0
| @@ -183,10 +183,21 @@ impl Player { | |||
| 183 | fit: FitPolicy, | 183 | fit: FitPolicy, |
| 184 | cx: &mut Context<Self>, | 184 | cx: &mut Context<Self>, |
| 185 | ) { | 185 | ) { |
| 186 | + // The policy has to have moved before this is an edit: `set_fit` | ||
| 187 | + // answers "the index existed", not "the value changed" (the engine | ||
| 188 | + // snapshot-and-rewrites the same policy and still says true), and the | ||
| 189 | + // list keeps the row already in force clickable -- so the engine's | ||
| 190 | + // own bool would light the ledger's `unsaved` ghost over a project | ||
| 191 | + // nobody touched. | ||
| 186 | if let Some(session) = &mut self.session | 192 | if let Some(session) = &mut self.session |
| 193 | + && session.fit_of(lane, idx) != fit | ||
| 187 | && session.set_fit(lane, idx, fit) | 194 | && session.set_fit(lane, idx, fit) |
| 188 | { | 195 | { |
| 189 | let (w, h) = session.resolution(); | 196 | let (w, h) = session.resolution(); |
| 197 | + // A clip's own fit policy, written from a click: arms autosave | ||
| 198 | + // and the close gate itself ([`Player::act`]'s list is the action | ||
| 199 | + // doors only). | ||
| 200 | + self.mark_dirty(); | ||
| 190 | self.notify_user(format!("FIT POLICY: {} on {w}x{h}", fit_label(fit)).into()); | 201 | self.notify_user(format!("FIT POLICY: {} on {w}x{h}", fit_label(fit)).into()); |
| 191 | self.reset_after_reseek(); | 202 | self.reset_after_reseek(); |
| 192 | } | 203 | } |
crates/app/src/tests/cards.rsmodified+205 -0
| @@ -1356,6 +1356,211 @@ fn a_typed_transition_duration_clamps_like_its_own_stepper() { | |||
| 1356 | assert_eq!(edit.commit_clamped(), 0); | 1356 | assert_eq!(edit.commit_clamped(), 0); |
| 1357 | } | 1357 | } |
| 1358 | 1358 | ||
| 1359 | +/// The colour field (`ColorEdit`), the transition field's free-text sibling: | ||
| 1360 | +/// every spelling of one colour lands on the same pair, the pair is what the | ||
| 1361 | +/// row shows back as a hex, and text that is not a colour is refused in words | ||
| 1362 | +/// while the field goes on holding it -- never dropped in silence, never | ||
| 1363 | +/// guessed at, and never cleared by the refusal itself. | ||
| 1364 | +#[test] | ||
| 1365 | +fn a_typed_colour_is_read_in_every_spelling_and_anything_else_is_refused() { | ||
| 1366 | + use engine::decode::{viz_color_from_text, viz_color_hex}; | ||
| 1367 | + | ||
| 1368 | + // One colour in every spelling the field takes: red as `#RRGGBB`, as bare | ||
| 1369 | + // digits, as `rgb(..)`, and as `rgba(..)` with the alpha dropped. Two | ||
| 1370 | + // spellings of one colour landing on different pairs would be a field | ||
| 1371 | + // whose colour depends on how it was written. | ||
| 1372 | + let red = viz_color_from_text("#FF0000").expect("red is a colour"); | ||
| 1373 | + for text in ["#FF0000", "FF0000", "rgb(255,0,0)", "rgba(255,0,0,255)"] { | ||
| 1374 | + let mut edit = ColorEdit::new(""); | ||
| 1375 | + for c in text.chars() { | ||
| 1376 | + edit.typed(c); | ||
| 1377 | + } | ||
| 1378 | + assert_eq!(edit.commit(), Some(red), "{text}"); | ||
| 1379 | + assert_eq!(edit.refusal, None, "{text} is a colour, not a refusal"); | ||
| 1380 | + } | ||
| 1381 | + | ||
| 1382 | + // The round trip through what the row displays: the hex the row shows | ||
| 1383 | + // reads back as the same pair, so opening the field on it and pressing | ||
| 1384 | + // enter changes nothing. A seed taken from anywhere else -- or a hex | ||
| 1385 | + // spelled by something other than the field's own reader -- shows up here. | ||
| 1386 | + let hex = viz_color_hex(red.0, red.1); | ||
| 1387 | + let mut edit = ColorEdit::new(&hex); | ||
| 1388 | + assert_eq!(edit.text, hex, "the field opens on the row's own line"); | ||
| 1389 | + assert!(edit.detail().contains("enter commits")); | ||
| 1390 | + assert_eq!(edit.commit(), Some(red)); | ||
| 1391 | + assert_eq!(edit.refusal, None); | ||
| 1392 | + | ||
| 1393 | + // Text that is not a colour: refused in words that say what a colour | ||
| 1394 | + // looks like, and the text survives the refusal -- a refusal that ate what | ||
| 1395 | + // was typed would make the next try retype all of it. | ||
| 1396 | + let mut edit = ColorEdit::new(""); | ||
| 1397 | + edit.typed('z'); | ||
| 1398 | + edit.typed('z'); | ||
| 1399 | + assert_eq!(edit.commit(), None); | ||
| 1400 | + let why = edit.refusal.clone().expect("a refusal, not a silence"); | ||
| 1401 | + assert!(why.contains("#RRGGBB"), "the refusal says what a colour is: {why}"); | ||
| 1402 | + assert_eq!(edit.text, "zz", "the refusal keeps the text it refused"); | ||
| 1403 | + assert!(edit.detail().contains("zz▏"), "the caret stays in the buffer"); | ||
| 1404 | + // ...and the next stroke clears it: that reason described the text that is | ||
| 1405 | + // no longer there. | ||
| 1406 | + edit.typed('0'); | ||
| 1407 | + assert_eq!(edit.refusal, None); | ||
| 1408 | + assert_eq!(edit.text, "zz0"); | ||
| 1409 | + | ||
| 1410 | + // Backspace erases the last character and the refusal with it, and the | ||
| 1411 | + // buffer is capped out loud rather than growing without bound off a held | ||
| 1412 | + // key. | ||
| 1413 | + let mut edit = ColorEdit::new(&hex); | ||
| 1414 | + edit.backspace(); | ||
| 1415 | + assert_eq!(edit.text.chars().count(), hex.chars().count() - 1); | ||
| 1416 | + for _ in 0..64 { | ||
| 1417 | + edit.typed('f'); | ||
| 1418 | + } | ||
| 1419 | + assert_eq!(edit.text.chars().count(), 32); | ||
| 1420 | + assert!(edit.refusal.is_some(), "the stroke past the cap says so"); | ||
| 1421 | + | ||
| 1422 | + // Why the commit compares before it writes: the field opens seeded with | ||
| 1423 | + // `viz_color_hex(now)`, and that hex reads back as a *different* pair for | ||
| 1424 | + // a good share of inks (the engine's round-trip canary counts 47 053 of | ||
| 1425 | + // 65 536 exact), so "write whatever the parse gave" would take an undo | ||
| 1426 | + // step for the colour the row was already showing. The fact is held here; | ||
| 1427 | + // the gate that reads it is pinned below. | ||
| 1428 | + let mut inexact = 0; | ||
| 1429 | + for hue in 0..=255u8 { | ||
| 1430 | + for sat in [0u8, 64, 160, 255] { | ||
| 1431 | + let seed = viz_color_hex(hue, sat); | ||
| 1432 | + match viz_color_from_text(&seed) { | ||
| 1433 | + // Exact: entering the seed is already a no-op for the write | ||
| 1434 | + // gate, whatever the gate says. | ||
| 1435 | + Some(pair) if pair == (hue, sat) => {} | ||
| 1436 | + // Inexact: this is the case the gate exists for -- without it | ||
| 1437 | + // every one of these takes a committing write on an untouched | ||
| 1438 | + // colour. | ||
| 1439 | + Some(_) => inexact += 1, | ||
| 1440 | + None => panic!("the row's own hex must be readable back: {seed}"), | ||
| 1441 | + } | ||
| 1442 | + } | ||
| 1443 | + } | ||
| 1444 | + assert!( | ||
| 1445 | + inexact > 0, | ||
| 1446 | + "no ink round-trips inexactly -- the commit's no-op gate would be dead weight" | ||
| 1447 | + ); | ||
| 1448 | + | ||
| 1449 | + // The gate itself, in the door that has it (`Player::commit_viz_hex`): the | ||
| 1450 | + // parse, then the comparison with the picked slot's own colour, and the | ||
| 1451 | + // write only past it. | ||
| 1452 | + let body = fn_body("commit_viz_hex"); | ||
| 1453 | + let gate = body | ||
| 1454 | + .split_once("hue_sat(paint)") | ||
| 1455 | + .expect("the commit no longer compares with the colour on the slot") | ||
| 1456 | + .1; | ||
| 1457 | + assert!( | ||
| 1458 | + gate.contains("write_viz_hs("), | ||
| 1459 | + "the commit writes before it has compared, so the row's own seed is an edit" | ||
| 1460 | + ); | ||
| 1461 | +} | ||
| 1462 | + | ||
| 1463 | +/// The look family's writes arm autosave, and therefore the ledger's `unsaved` | ||
| 1464 | +/// ghost and `Player::close_needs_answer`, which read the same flag: a colour | ||
| 1465 | +/// picked in the Clip tab that armed nothing could be closed away with no | ||
| 1466 | +/// prompt and no autosave. | ||
| 1467 | +/// | ||
| 1468 | +/// A scan and not a drive: every one of these doors needs a `Player` and a | ||
| 1469 | +/// gpui `Context`, and this crate has no window harness (`tests/view.rs`'s own | ||
| 1470 | +/// note). What a scan can hold is the three doors themselves -- the two the | ||
| 1471 | +/// whole paint family shares (`set_viz_paint_with` is where the wheel, the | ||
| 1472 | +/// steppers and a typed colour all land) and the two writes that do not go | ||
| 1473 | +/// through it (the style chips and the `Fast` chip, which write | ||
| 1474 | +/// `clip.visualizer`). Pre-fix none of the three armed anything while every | ||
| 1475 | +/// other engine-writing door did (`write_color`, `write_transform`, | ||
| 1476 | +/// `set_eq`, the trim/place/fade doors). | ||
| 1477 | +#[test] | ||
| 1478 | +fn a_visualizer_look_write_arms_autosave() { | ||
| 1479 | + for name in ["set_viz_style", "toggle_viz_flag"] { | ||
| 1480 | + let body = fn_body(name); | ||
| 1481 | + assert!( | ||
| 1482 | + body.contains("session.set_visualizer"), | ||
| 1483 | + "{name} no longer writes the clip's look at all" | ||
| 1484 | + ); | ||
| 1485 | + assert!( | ||
| 1486 | + body.contains("mark_dirty()"), | ||
| 1487 | + "{name} writes a look and arms nothing" | ||
| 1488 | + ); | ||
| 1489 | + } | ||
| 1490 | + let body = fn_body("set_viz_paint_with"); | ||
| 1491 | + // The arm rides the write that took, not the call: a no-op press (the | ||
| 1492 | + // colour under the hand already) is not an edit, and the ghost must stay | ||
| 1493 | + // off it. | ||
| 1494 | + let took = body | ||
| 1495 | + .split_once("if took {") | ||
| 1496 | + .expect("the paint door writes through a taken-write gate") | ||
| 1497 | + .1; | ||
| 1498 | + assert!( | ||
| 1499 | + took.contains("mark_dirty()"), | ||
| 1500 | + "the arm is outside the write gate, so a no-op press would dirty the project" | ||
| 1501 | + ); | ||
| 1502 | + assert!( | ||
| 1503 | + took.contains("reset_after_reseek()"), | ||
| 1504 | + "the arm replaced the reseek bookkeeping instead of joining it" | ||
| 1505 | + ); | ||
| 1506 | +} | ||
| 1507 | + | ||
| 1508 | +/// The rest of the class the visualizer look family belonged to: every other | ||
| 1509 | +/// door that writes the project from a *click* and so has no action behind it | ||
| 1510 | +/// to arm autosave ([`Player::act`]'s list is the action doors only). Each arm | ||
| 1511 | +/// rides its own "the write took" gate -- a pick that changed nothing must not | ||
| 1512 | +/// dirty the project, or a window nobody has touched would ask to be saved. | ||
| 1513 | +#[test] | ||
| 1514 | +fn every_click_door_that_writes_the_project_arms_autosave() { | ||
| 1515 | + // The doors the engine answers with a bool *that means "the value | ||
| 1516 | + // moved"*: the arm goes inside it. | ||
| 1517 | + for name in ["apply_resolution", "apply_frame_rate", "apply_tone"] { | ||
| 1518 | + let body = fn_body(name); | ||
| 1519 | + assert!( | ||
| 1520 | + body.contains("mark_dirty()"), | ||
| 1521 | + "{name} writes the project and arms nothing" | ||
| 1522 | + ); | ||
| 1523 | + } | ||
| 1524 | + // ...and the one whose bool does not mean that at all: `set_fit` says the | ||
| 1525 | + // index existed, and the picker keeps the row already in force clickable, | ||
| 1526 | + // so the arm rides the policy having moved -- on the engine's own bool it | ||
| 1527 | + // would light the `unsaved` ghost over a project nobody touched. | ||
| 1528 | + let body = fn_body("apply_fit"); | ||
| 1529 | + assert!( | ||
| 1530 | + body.contains("fit_of(lane, idx) != fit"), | ||
| 1531 | + "apply_fit arms on the engine's own bool again, which a no-op pick also answers true" | ||
| 1532 | + ); | ||
| 1533 | + assert!(body.contains("mark_dirty()"), "apply_fit arms nothing"); | ||
| 1534 | + // The import path keeps no arm on purpose (the `autosave_armed` rule): its | ||
| 1535 | + // only caller is `install_media`, so an arm there could only ever fire for | ||
| 1536 | + // a project nobody has touched. The user's door is the two toggles. | ||
| 1537 | + let body = fn_body("apply_proxies"); | ||
| 1538 | + assert!( | ||
| 1539 | + body.find("mark_dirty").is_none(), | ||
| 1540 | + "apply_proxies arms again -- its only caller is the import path" | ||
| 1541 | + ); | ||
| 1542 | + // The doors whose setter takes no answer back, and the library row's | ||
| 1543 | + // removal: the arm rides a local `changed` (or the removal having landed), | ||
| 1544 | + // never the call. | ||
| 1545 | + for (name, gate) in [ | ||
| 1546 | + ("apply_sample_rate", "if changed {"), | ||
| 1547 | + ("apply_encoder", "if changed {"), | ||
| 1548 | + ("toggle_proxies", "if changed {"), | ||
| 1549 | + ("toggle_auto_proxies", "if changed {"), | ||
| 1550 | + ("remove_source", "Some(Ok(idx))"), | ||
| 1551 | + ] { | ||
| 1552 | + let body = fn_body(name); | ||
| 1553 | + let after = body | ||
| 1554 | + .split_once(gate) | ||
| 1555 | + .unwrap_or_else(|| panic!("{name} lost the gate its arm rides")) | ||
| 1556 | + .1; | ||
| 1557 | + assert!( | ||
| 1558 | + after.contains("mark_dirty()"), | ||
| 1559 | + "{name} arms outside its gate, so a no-op pick would dirty the project" | ||
| 1560 | + ); | ||
| 1561 | + } | ||
| 1562 | +} | ||
| 1563 | + | ||
| 1359 | /// [`crate::ui::dock_stance::transition_of`]: the dock's duration row | 1564 | /// [`crate::ui::dock_stance::transition_of`]: the dock's duration row |
| 1360 | /// appears only for an anchor that actually carries a dissolve or a | 1565 | /// appears only for an anchor that actually carries a dissolve or a |
| 1361 | /// crossfade, and the room it offers is capped at what the successor clip | 1566 | /// crossfade, and the room it offers is capped at what the successor clip |
crates/app/src/tests/media.rsmodified+75 -3
| @@ -214,12 +214,12 @@ fn the_wheel_draws_the_sample_a_drag_is_holding() { | |||
| 214 | assert_eq!(viz_held_paint(0, None), 0); | 214 | assert_eq!(viz_held_paint(0, None), 0); |
| 215 | assert_eq!(viz_held_paint(0x0208_d2fd, None), 0x0208_d2fd); | 215 | assert_eq!(viz_held_paint(0x0208_d2fd, None), 0x0208_d2fd); |
| 216 | // Held: that hue and saturation over what the clip already carries. | 216 | // Held: that hue and saturation over what the clip already carries. |
| 217 | - let held = viz_held_paint(0, Some((253, 210))); | 217 | + let held = viz_held_paint(0, Some((VizSlot::Main, 253, 210))); |
| 218 | assert_eq!(engine::decode::viz_hue_ui(held), 253); | 218 | assert_eq!(engine::decode::viz_hue_ui(held), 253); |
| 219 | assert_eq!(engine::decode::viz_sat_ui(held), 210); | 219 | assert_eq!(engine::decode::viz_sat_ui(held), 210); |
| 220 | // ...in that order, never the other way round: a mark drawn at the wrong | 220 | // ...in that order, never the other way round: a mark drawn at the wrong |
| 221 | // angle is the whole gesture showing the wrong colour. | 221 | // angle is the whole gesture showing the wrong colour. |
| 222 | - let flipped = viz_held_paint(0, Some((210, 253))); | 222 | + let flipped = viz_held_paint(0, Some((VizSlot::Main, 210, 253))); |
| 223 | assert_ne!(held, flipped); | 223 | assert_ne!(held, flipped); |
| 224 | assert_eq!(engine::decode::viz_hue_ui(flipped), 210); | 224 | assert_eq!(engine::decode::viz_hue_ui(flipped), 210); |
| 225 | assert_eq!(engine::decode::viz_sat_ui(flipped), 253); | 225 | assert_eq!(engine::decode::viz_sat_ui(flipped), 253); |
| @@ -229,11 +229,83 @@ fn the_wheel_draws_the_sample_a_drag_is_holding() { | |||
| 229 | assert_eq!(engine::decode::viz_glow_of(held), 2); | 229 | assert_eq!(engine::decode::viz_glow_of(held), 2); |
| 230 | let pen = engine::decode::with_viz_paint_glow(0x0208_d2fd, 9); | 230 | let pen = engine::decode::with_viz_paint_glow(0x0208_d2fd, 9); |
| 231 | assert_eq!( | 231 | assert_eq!( |
| 232 | - engine::decode::viz_glow_of(viz_held_paint(pen, Some((253, 210)))), | 232 | + engine::decode::viz_glow_of(viz_held_paint(pen, Some((VizSlot::Main, 253, 210)))), |
| 233 | 9 | 233 | 9 |
| 234 | ); | 234 | ); |
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | +/// The strand's half of the same gesture, and the two things a second ink on | ||
| 238 | +/// the one wheel may not get wrong. A strand the clip has not chosen starts at | ||
| 239 | +/// the automatic complement the painter draws there -- the clip's hue half a | ||
| 240 | +/// turn round, at the clip's own saturation -- so the mark is on a colour the | ||
| 241 | +/// picture already has and the first write only says "this one, then". And the | ||
| 242 | +/// clip's own ink is not touched by any of it: the whole point of a second ink | ||
| 243 | +/// is that one slot's writes leave the other alone. | ||
| 244 | +#[test] | ||
| 245 | +fn the_strand_slot_starts_at_the_complement_and_the_write_chooses_it() { | ||
| 246 | + use engine::decode::{ | ||
| 247 | + viz_hue_ui, viz_sat_ui, viz_strand_hue_ui, viz_strand_sat_ui, viz_strand_set, | ||
| 248 | + with_viz_paint_hue, with_viz_paint_strands, VIZ_PAINT_AZURE, | ||
| 249 | + }; | ||
| 250 | + | ||
| 251 | + let paint = with_viz_paint_strands(VIZ_PAINT_AZURE, 2); | ||
| 252 | + assert!(!viz_strand_set(paint), "no strand colour chosen yet"); | ||
| 253 | + assert_eq!( | ||
| 254 | + VizSlot::Strand.hue_sat(paint), | ||
| 255 | + (viz_hue_ui(paint).wrapping_add(128), viz_sat_ui(paint)), | ||
| 256 | + "the unset strand stands where the painter draws its complement" | ||
| 257 | + ); | ||
| 258 | + // ...half a turn round, wrapping: hue 200's complement is 72, not 328. | ||
| 259 | + let late = with_viz_paint_hue(paint, 200); | ||
| 260 | + assert_eq!(VizSlot::Strand.hue_sat(late).0, 200u8.wrapping_add(128)); | ||
| 261 | + assert_eq!(VizSlot::Strand.hue_sat(late).0, 72); | ||
| 262 | + | ||
| 263 | + // The write is what chooses it, and reads back as what was written. | ||
| 264 | + let picked = VizSlot::Strand.set_hue_sat(paint, 0, 255); | ||
| 265 | + assert!(viz_strand_set(picked)); | ||
| 266 | + assert_eq!(viz_strand_hue_ui(picked), 0); | ||
| 267 | + assert_eq!(viz_strand_sat_ui(picked), 255); | ||
| 268 | + assert_eq!(VizSlot::Strand.hue_sat(picked), (0, 255)); | ||
| 269 | + // The clip's own colour survives the strand's writes untouched. | ||
| 270 | + assert_eq!(viz_hue_ui(picked), viz_hue_ui(paint)); | ||
| 271 | + assert_eq!(viz_sat_ui(picked), viz_sat_ui(paint)); | ||
| 272 | + // A held strand sample draws the strand, not the clip's colour: the slot | ||
| 273 | + // rides with the sample. | ||
| 274 | + let held = viz_held_paint(paint, Some((VizSlot::Strand, 0, 255))); | ||
| 275 | + assert_eq!(VizSlot::Strand.hue_sat(held), (0, 255)); | ||
| 276 | + assert_eq!(viz_strand_set(held), true); | ||
| 277 | + // And the wheel's own slot writes only its own bytes. | ||
| 278 | + let main = VizSlot::Main.set_hue_sat(picked, 33, 44); | ||
| 279 | + assert_eq!((viz_hue_ui(main), viz_sat_ui(main)), (33, 44)); | ||
| 280 | + assert_eq!((viz_strand_hue_ui(main), viz_strand_sat_ui(main)), (0, 255)); | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | +/// One strand has no dual half, so the strand slot falls back to the clip's own | ||
| 284 | +/// colour: a write there lands on the ink the picture actually paints instead | ||
| 285 | +/// of choosing a strand colour nothing wears. Two strands put it back -- the | ||
| 286 | +/// same reading the Strand chip is enabled by. | ||
| 287 | +#[test] | ||
| 288 | +fn a_strand_slot_on_a_single_strand_clip_is_the_clip_s_own_colour() { | ||
| 289 | + use engine::decode::{ | ||
| 290 | + viz_hue_ui, viz_sat_ui, viz_strand_set, viz_strands_of, with_viz_paint_hue, | ||
| 291 | + with_viz_paint_sat, with_viz_paint_strands, VIZ_PAINT_AZURE, | ||
| 292 | + }; | ||
| 293 | + | ||
| 294 | + let one = with_viz_paint_strands( | ||
| 295 | + with_viz_paint_sat(with_viz_paint_hue(VIZ_PAINT_AZURE, 64), 200), | ||
| 296 | + 1, | ||
| 297 | + ); | ||
| 298 | + assert_eq!(viz_strands_of(one), 1); | ||
| 299 | + assert_eq!(VizSlot::Strand.picked(one), VizSlot::Main); | ||
| 300 | + let hit = VizSlot::Strand.picked(one).set_hue_sat(one, 0, 255); | ||
| 301 | + assert!(!viz_strand_set(hit), "one strand chooses no strand colour"); | ||
| 302 | + assert_eq!((viz_hue_ui(hit), viz_sat_ui(hit)), (0, 255)); | ||
| 303 | + // The clip's own slot is never redirected -- it is what the fallback | ||
| 304 | + // lands on. | ||
| 305 | + assert_eq!(VizSlot::Main.picked(one), VizSlot::Main); | ||
| 306 | + assert_eq!(VizSlot::Strand.picked(with_viz_paint_strands(one, 2)), VizSlot::Strand); | ||
| 307 | +} | ||
| 308 | + | ||
| 237 | /// A seek says nothing until it has stood: an ordinary one is a flicker and | 309 | /// A seek says nothing until it has stood: an ordinary one is a flicker and |
| 238 | /// a cold read of a big file is the case worth words. | 310 | /// a cold read of a big file is the case worth words. |
| 239 | #[test] | 311 | #[test] |
crates/app/src/tests/mod.rsmodified+4 -2
| @@ -11,7 +11,8 @@ mod view; | |||
| 11 | 11 | ||
| 12 | use super::{ | 12 | use super::{ |
| 13 | ACCENT_PRIMARY, AUDIO_KBPS, BG_RAISED, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, | 13 | ACCENT_PRIMARY, AUDIO_KBPS, BG_RAISED, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, |
| 14 | - CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, | 14 | + ColorEdit, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT, |
| 15 | + EQ_FREQ_HIGH, | ||
| 15 | EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, | 16 | EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, |
| 16 | EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, Enable, | 17 | EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, Enable, |
| 17 | BPS_COARSE, BPS_FINE, BPS_MAX, BPS_MIN, EXPORT_MOMENT_H, EncoderSeat, FORMATS, Format, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, | 18 | BPS_COARSE, BPS_FINE, BPS_MAX, BPS_MIN, EXPORT_MOMENT_H, EncoderSeat, FORMATS, Format, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, |
| @@ -31,7 +32,8 @@ use super::{ | |||
| 31 | row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label, | 32 | row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label, |
| 32 | rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, | 33 | rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, |
| 33 | subtitle_plan, timecode, timeline_fixed_h, tip_may_paint, | 34 | subtitle_plan, timecode, timeline_fixed_h, tip_may_paint, |
| 34 | - transport, typed, unseen_paths, unseen_sources, viz_held_paint, whole_take, window_title, | 35 | + transport, typed, unseen_paths, unseen_sources, viz_held_paint, VizSlot, whole_take, |
| 36 | + window_title, | ||
| 35 | }; | 37 | }; |
| 36 | 38 | ||
| 37 | use super::{ | 39 | use super::{ |
crates/app/src/transport.rsmodified+73 -5
| @@ -204,18 +204,86 @@ pub(crate) fn stash_or_write<T: Copy>( | |||
| 204 | } | 204 | } |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | +/// Which of a visualizer's two inks a look control acts on: the clip's own | ||
| 208 | +/// colour, or the second half of a dual-strand ring. Zero -- the clip's own -- | ||
| 209 | +/// is what every control meant before there was a second, so it is also what | ||
| 210 | +/// the Clip tab opens on ([`Player::viz_slot`]). | ||
| 211 | +/// | ||
| 212 | +/// Both inks are read and written through the same three methods, so the | ||
| 213 | +/// wheel, the hex field and the drag that holds a sample between them cannot | ||
| 214 | +/// disagree about which one a gesture is on. | ||
| 215 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
| 216 | +pub(crate) enum VizSlot { | ||
| 217 | + /// The clip's own hue and saturation -- the paint field's low bytes. | ||
| 218 | + Main, | ||
| 219 | + /// The ring's dual half. Only a clip that chose one wears it; otherwise | ||
| 220 | + /// the painter draws the automatic complement (`visualizer_i420`). | ||
| 221 | + Strand, | ||
| 222 | +} | ||
| 223 | + | ||
| 224 | +impl VizSlot { | ||
| 225 | + /// The ink with a picture behind it. A one-strand ring has no dual half, | ||
| 226 | + /// so a wheel on the strand colour there would move a mark and nothing | ||
| 227 | + /// else: every control reads the slot through here and lands on the clip's | ||
| 228 | + /// own colour instead while that is the case -- which is also why the | ||
| 229 | + /// Strand chip is dead then. | ||
| 230 | + pub(crate) fn picked(self, paint: u64) -> VizSlot { | ||
| 231 | + match self { | ||
| 232 | + VizSlot::Strand if engine::decode::viz_strands_of(paint) < 2 => VizSlot::Main, | ||
| 233 | + slot => slot, | ||
| 234 | + } | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + /// What this ink is showing: the clip's hue and saturation, or -- for a | ||
| 238 | + /// strand the clip has not chosen -- the automatic complement the painter | ||
| 239 | + /// draws there, so a hand picking the strand up starts where the picture | ||
| 240 | + /// already is and the first write only says "this one, then". | ||
| 241 | + pub(crate) fn hue_sat(self, paint: u64) -> (u8, u8) { | ||
| 242 | + match self { | ||
| 243 | + VizSlot::Main => ( | ||
| 244 | + engine::decode::viz_hue_ui(paint), | ||
| 245 | + engine::decode::viz_sat_ui(paint), | ||
| 246 | + ), | ||
| 247 | + VizSlot::Strand if engine::decode::viz_strand_set(paint) => ( | ||
| 248 | + engine::decode::viz_strand_hue_ui(paint), | ||
| 249 | + engine::decode::viz_strand_sat_ui(paint), | ||
| 250 | + ), | ||
| 251 | + VizSlot::Strand => ( | ||
| 252 | + engine::decode::viz_hue_ui(paint).wrapping_add(128), | ||
| 253 | + engine::decode::viz_sat_ui(paint), | ||
| 254 | + ), | ||
| 255 | + } | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + /// Sets this ink's hue and saturation, raising the strand's chosen flag on | ||
| 259 | + /// the way -- the engine's strand setters do that, which is what makes the | ||
| 260 | + /// wheel's first sample on the slot the write that chooses it. | ||
| 261 | + pub(crate) fn set_hue_sat(self, paint: u64, hue: u8, sat: u8) -> u64 { | ||
| 262 | + match self { | ||
| 263 | + VizSlot::Main => engine::decode::with_viz_paint_sat( | ||
| 264 | + engine::decode::with_viz_paint_hue(paint, hue), | ||
| 265 | + sat, | ||
| 266 | + ), | ||
| 267 | + VizSlot::Strand => engine::decode::with_viz_paint_strand_sat( | ||
| 268 | + engine::decode::with_viz_paint_strand_hue(paint, hue), | ||
| 269 | + sat, | ||
| 270 | + ), | ||
| 271 | + } | ||
| 272 | + } | ||
| 273 | +} | ||
| 274 | + | ||
| 207 | /// What the wheel draws: the clip's own ink, or the sample a drag is holding | 275 | /// What the wheel draws: the clip's own ink, or the sample a drag is holding |
| 208 | /// while the worker is still behind ([`stash_or_write`]). The wheel is a | 276 | /// while the worker is still behind ([`stash_or_write`]). The wheel is a |
| 209 | /// picker with no table of its own, so a held sample would otherwise be | 277 | /// picker with no table of its own, so a held sample would otherwise be |
| 210 | /// invisible -- the clip carries the sample *before* it until the holding | 278 | /// invisible -- the clip carries the sample *before* it until the holding |
| 211 | /// frame lands -- and the mark would sit still under a moving hand. | 279 | /// frame lands -- and the mark would sit still under a moving hand. |
| 212 | /// [`Player::color_params`] holds exactly this rule for the card's sliders. | 280 | /// [`Player::color_params`] holds exactly this rule for the card's sliders. |
| 213 | -pub(crate) fn viz_held_paint(paint: u32, held: Option<(u8, u8)>) -> u32 { | 281 | +/// |
| 282 | +/// The held sample carries its slot, so a drag on the strand colour draws the | ||
| 283 | +/// strand colour even before the clip has one of its own. | ||
| 284 | +pub(crate) fn viz_held_paint(paint: u64, held: Option<(VizSlot, u8, u8)>) -> u64 { | ||
| 214 | match held { | 285 | match held { |
| 215 | - Some((hue, sat)) => engine::decode::with_viz_paint_sat( | 286 | + Some((slot, hue, sat)) => slot.set_hue_sat(paint, hue, sat), |
| 216 | - engine::decode::with_viz_paint_hue(paint, hue), | ||
| 217 | - sat, | ||
| 218 | - ), | ||
| 219 | None => paint, | 287 | None => paint, |
| 220 | } | 288 | } |
| 221 | } | 289 | } |
crates/app/src/ui/dock_stance.rsmodified+115 -17
| @@ -1214,6 +1214,7 @@ fn viz_style_verbs(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen | |||
| 1214 | .text_color(rgb(if on { INK1() } else { INK3() })) | 1214 | .text_color(rgb(if on { INK1() } else { INK3() })) |
| 1215 | .font(row.font) | 1215 | .font(row.font) |
| 1216 | .text_size(row.size) | 1216 | .text_size(row.size) |
| 1217 | + .tooltip(crate::ui::widgets::tip_hover(label_text, "", None)) | ||
| 1217 | .children(hitmap::control(id, label_text, true)) | 1218 | .children(hitmap::control(id, label_text, true)) |
| 1218 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 1219 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { |
| 1219 | this.set_viz_style(style, cx); | 1220 | this.set_viz_style(style, cx); |
| @@ -1238,6 +1239,7 @@ fn viz_style_verbs(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen | |||
| 1238 | .text_color(rgb(if on { INK1() } else { INK3() })) | 1239 | .text_color(rgb(if on { INK1() } else { INK3() })) |
| 1239 | .font(style.font.clone()) | 1240 | .font(style.font.clone()) |
| 1240 | .text_size(style.size) | 1241 | .text_size(style.size) |
| 1242 | + .tooltip(crate::ui::widgets::tip_hover(label_text, "", None)) | ||
| 1241 | .children(hitmap::control(id, label_text, true)) | 1243 | .children(hitmap::control(id, label_text, true)) |
| 1242 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 1244 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { |
| 1243 | this.toggle_viz_flag(bit, cx); | 1245 | this.toggle_viz_flag(bit, cx); |
| @@ -1290,6 +1292,9 @@ fn viz_style_verbs(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen | |||
| 1290 | 1292 | ||
| 1291 | fn viz_step( | 1293 | fn viz_step( |
| 1292 | id: &'static str, | 1294 | id: &'static str, |
| 1295 | + // What the button is called on hover and in the hitmap: the glyph alone | ||
| 1296 | + // names nothing. | ||
| 1297 | + name: &'static str, | ||
| 1293 | glyph: &'static str, | 1298 | glyph: &'static str, |
| 1294 | cx: &mut Context<Player>, | 1299 | cx: &mut Context<Player>, |
| 1295 | f: impl Fn(&mut Player, &mut Context<Player>) + 'static + Copy, | 1300 | f: impl Fn(&mut Player, &mut Context<Player>) + 'static + Copy, |
| @@ -1304,18 +1309,115 @@ fn viz_step( | |||
| 1304 | .rounded(px(3.)) | 1309 | .rounded(px(3.)) |
| 1305 | .bg(rgb(DARK_RAISED())) | 1310 | .bg(rgb(DARK_RAISED())) |
| 1306 | .cursor_pointer() | 1311 | .cursor_pointer() |
| 1307 | - .children(hitmap::control(id, glyph, true)) | 1312 | + .tooltip(crate::ui::widgets::tip_hover(name, "", None)) |
| 1313 | + .children(hitmap::control(id, name, true)) | ||
| 1308 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| f(this, cx))) | 1314 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| f(this, cx))) |
| 1309 | .child(glyph) | 1315 | .child(glyph) |
| 1310 | } | 1316 | } |
| 1311 | 1317 | ||
| 1312 | -fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context<Player>) -> impl IntoElement { | 1318 | +/// Which of the clip's two inks the wheel and the colour field are on. The |
| 1319 | +/// picked chip wears the solid ink and the other the quiet one -- the style | ||
| 1320 | +/// chips' own shape (`viz_style_verbs`'s `pick`, one row up the same column). | ||
| 1321 | +/// | ||
| 1322 | +/// The Strand chip is dead while the clip has one strand: a strand colour is | ||
| 1323 | +/// painted on the ring's *dual* half and a one-strand ring has none, so the | ||
| 1324 | +/// chip would be wired to nothing -- and it says so on hover rather than doing | ||
| 1325 | +/// nothing in silence (`widgets::control`'s own rule for a button with no | ||
| 1326 | +/// action). | ||
| 1327 | +fn viz_slot_chips(player: &Player, paint: u64, cx: &mut Context<Player>) -> impl IntoElement { | ||
| 1328 | + let picked = player.viz_slot.picked(paint); | ||
| 1329 | + let strand_live = engine::decode::viz_strands_of(paint) >= 2; | ||
| 1330 | + let chip = |id: &'static str, label_text: &'static str, slot: VizSlot, live: bool| { | ||
| 1331 | + let row = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); | ||
| 1332 | + let on = picked == slot; | ||
| 1333 | + div() | ||
| 1334 | + .id(id) | ||
| 1335 | + .flex_none() | ||
| 1336 | + .h(px(CONTROL_H)) | ||
| 1337 | + .px(px(8.)) | ||
| 1338 | + .flex() | ||
| 1339 | + .items_center() | ||
| 1340 | + .font(row.font) | ||
| 1341 | + .text_size(row.size) | ||
| 1342 | + .text_color(rgb(if on { INK1() } else { INK3() })) | ||
| 1343 | + .tooltip(crate::ui::widgets::tip_hover( | ||
| 1344 | + label_text, | ||
| 1345 | + "", | ||
| 1346 | + match live { | ||
| 1347 | + true => None, | ||
| 1348 | + false => Some("needs two strands"), | ||
| 1349 | + }, | ||
| 1350 | + )) | ||
| 1351 | + .children(hitmap::control(id, label_text, live)) | ||
| 1352 | + .when(!live, |d| d.opacity(0.4).cursor_not_allowed()) | ||
| 1353 | + .when(live, |d| { | ||
| 1354 | + d.cursor_pointer() | ||
| 1355 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 1356 | + this.set_viz_slot(slot, cx); | ||
| 1357 | + })) | ||
| 1358 | + }) | ||
| 1359 | + .child(label_text.to_string()) | ||
| 1360 | + .into_any_element() | ||
| 1361 | + }; | ||
| 1362 | + div() | ||
| 1363 | + .id("dock-viz-slots") | ||
| 1364 | + .flex() | ||
| 1365 | + .items_center() | ||
| 1366 | + .child(chip("dock-viz-colour", "Colour", VizSlot::Main, true)) | ||
| 1367 | + .child(chip("dock-viz-strand", "Strand", VizSlot::Strand, strand_live)) | ||
| 1368 | +} | ||
| 1369 | + | ||
| 1370 | +/// The picked slot's colour as text, and the way in: a click opens the type-in | ||
| 1371 | +/// seeded with exactly what the row is showing | ||
| 1372 | +/// ([`Player::edit_viz_hex`]). While the field is open the row is the buffer | ||
| 1373 | +/// and its refusal instead -- `transition_row`'s own rule for its own field. | ||
| 1374 | +fn viz_hex_row(player: &Player, paint: u64, cx: &mut Context<Player>) -> impl IntoElement { | ||
| 1375 | + let (hue, sat) = player.viz_slot.picked(paint).hue_sat(paint); | ||
| 1376 | + let hex = engine::decode::viz_color_hex(hue, sat); | ||
| 1377 | + // The seed the click opens on is the line the row is showing, so a click | ||
| 1378 | + // that lands while the field is open cannot seed it with something else. | ||
| 1379 | + let seed = hex.clone(); | ||
| 1380 | + let field = player.viz_hex_edit.as_ref(); | ||
| 1381 | + let row = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); | ||
| 1382 | + div() | ||
| 1383 | + .id("dock-viz-hex-field") | ||
| 1384 | + .h(px(CONTROL_H)) | ||
| 1385 | + .flex() | ||
| 1386 | + .items_center() | ||
| 1387 | + .font(row.font) | ||
| 1388 | + .text_size(row.size) | ||
| 1389 | + .text_color(rgb(INK2())) | ||
| 1390 | + .cursor_pointer() | ||
| 1391 | + .tooltip(crate::ui::widgets::tip_hover("Colour", "click to type", None)) | ||
| 1392 | + .children(hitmap::control( | ||
| 1393 | + "dock-viz-hex-field", | ||
| 1394 | + "Colour hex, type-in", | ||
| 1395 | + true, | ||
| 1396 | + )) | ||
| 1397 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 1398 | + this.edit_viz_hex(&seed); | ||
| 1399 | + cx.notify(); | ||
| 1400 | + })) | ||
| 1401 | + .child(match field { | ||
| 1402 | + Some(edit) => edit.detail(), | ||
| 1403 | + None => hex, | ||
| 1404 | + }) | ||
| 1405 | +} | ||
| 1406 | + | ||
| 1407 | +fn viz_color_wheel(player: &Player, paint: u64, cx: &mut Context<Player>) -> impl IntoElement { | ||
| 1408 | + // What the mark is on, read out here because the canvas closure paints and | ||
| 1409 | + // so cannot borrow the player: the picked slot's ink | ||
| 1410 | + // ([`VizSlot::hue_sat`]) -- the clip's own colour, or, for a strand the | ||
| 1411 | + // clip has not chosen, the automatic complement, so the hand starts where | ||
| 1412 | + // the picture already is. | ||
| 1413 | + let (mark_hue, mark_sat) = player.viz_slot.picked(paint).hue_sat(paint); | ||
| 1313 | div() | 1414 | div() |
| 1314 | .id("dock-viz-hs") | 1415 | .id("dock-viz-hs") |
| 1315 | .w(px(112.)) | 1416 | .w(px(112.)) |
| 1316 | .h(px(112.)) | 1417 | .h(px(112.)) |
| 1317 | .relative() | 1418 | .relative() |
| 1318 | .cursor_pointer() | 1419 | .cursor_pointer() |
| 1420 | + .tooltip(crate::ui::widgets::tip_hover("Colour wheel", "drag to pick", None)) | ||
| 1319 | .children(hitmap::control("dock-viz-hs", "Colour wheel", true)) | 1421 | .children(hitmap::control("dock-viz-hs", "Colour wheel", true)) |
| 1320 | .child(bounds_probe(player.viz_wheel.clone())) | 1422 | .child(bounds_probe(player.viz_wheel.clone())) |
| 1321 | .child( | 1423 | .child( |
| @@ -1351,8 +1453,8 @@ fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context<Player>) -> imp | |||
| 1351 | } | 1453 | } |
| 1352 | } | 1454 | } |
| 1353 | // Selection mark. | 1455 | // Selection mark. |
| 1354 | - let hue = f32::from(engine::decode::viz_hue_ui(paint)) / 256. * std::f32::consts::TAU; | 1456 | + let hue = f32::from(mark_hue) / 256. * std::f32::consts::TAU; |
| 1355 | - let sat = f32::from(engine::decode::viz_sat_ui(paint)) / 255.; | 1457 | + let sat = f32::from(mark_sat) / 255.; |
| 1356 | let mx = cx + radius * sat * hue.sin(); | 1458 | let mx = cx + radius * sat * hue.sin(); |
| 1357 | let my = cy - radius * sat * hue.cos(); | 1459 | let my = cy - radius * sat * hue.cos(); |
| 1358 | let mut mark = PathBuilder::stroke(px(2.)); | 1460 | let mut mark = PathBuilder::stroke(px(2.)); |
| @@ -1382,7 +1484,7 @@ fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context<Player>) -> imp | |||
| 1382 | ) | 1484 | ) |
| 1383 | } | 1485 | } |
| 1384 | 1486 | ||
| 1385 | -fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context<Player>) -> impl IntoElement { | 1487 | +fn viz_paint_knobs(player: &Player, paint: u64, cx: &mut Context<Player>) -> impl IntoElement { |
| 1386 | let strands = engine::decode::viz_strands_of(paint); | 1488 | let strands = engine::decode::viz_strands_of(paint); |
| 1387 | let glow = engine::decode::viz_glow_of(paint); | 1489 | let glow = engine::decode::viz_glow_of(paint); |
| 1388 | let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); | 1490 | let style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); |
| @@ -1397,14 +1499,9 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context<Player>) -> imp | |||
| 1397 | .flex() | 1499 | .flex() |
| 1398 | .flex_col() | 1500 | .flex_col() |
| 1399 | .gap(px(4.)) | 1501 | .gap(px(4.)) |
| 1400 | - .child( | 1502 | + .child(viz_slot_chips(player, paint, cx)) |
| 1401 | - div() | 1503 | + .child(viz_color_wheel(player, paint, cx)) |
| 1402 | - .font(style.font.clone()) | 1504 | + .child(viz_hex_row(player, paint, cx)), |
| 1403 | - .text_size(style.size) | ||
| 1404 | - .text_color(rgb(INK2())) | ||
| 1405 | - .child("Colour"), | ||
| 1406 | - ) | ||
| 1407 | - .child(viz_color_wheel(player, paint, cx)), | ||
| 1408 | ) | 1505 | ) |
| 1409 | .child( | 1506 | .child( |
| 1410 | div() | 1507 | div() |
| @@ -1419,7 +1516,7 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context<Player>) -> imp | |||
| 1419 | .text_color(rgb(INK2())) | 1516 | .text_color(rgb(INK2())) |
| 1420 | .child("Strands"), | 1517 | .child("Strands"), |
| 1421 | ) | 1518 | ) |
| 1422 | - .child(viz_step("dock-viz-strands-minus", "−", cx, |this, cx| { | 1519 | + .child(viz_step("dock-viz-strands-minus", "Fewer strands", "−", cx, |this, cx| { |
| 1423 | this.set_viz_strands(engine::decode::viz_strands_of(this.viz_paint()).saturating_sub(1).max(1), cx); | 1520 | this.set_viz_strands(engine::decode::viz_strands_of(this.viz_paint()).saturating_sub(1).max(1), cx); |
| 1424 | })) | 1521 | })) |
| 1425 | .child( | 1522 | .child( |
| @@ -1429,7 +1526,7 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context<Player>) -> imp | |||
| 1429 | .text_color(rgb(INK1())) | 1526 | .text_color(rgb(INK1())) |
| 1430 | .child(format!("{strands}")), | 1527 | .child(format!("{strands}")), |
| 1431 | ) | 1528 | ) |
| 1432 | - .child(viz_step("dock-viz-strands-plus", "+", cx, |this, cx| { | 1529 | + .child(viz_step("dock-viz-strands-plus", "More strands", "+", cx, |this, cx| { |
| 1433 | this.set_viz_strands(engine::decode::viz_strands_of(this.viz_paint()).saturating_add(1).min(32), cx); | 1530 | this.set_viz_strands(engine::decode::viz_strands_of(this.viz_paint()).saturating_add(1).min(32), cx); |
| 1434 | })), | 1531 | })), |
| 1435 | ) | 1532 | ) |
| @@ -1446,7 +1543,7 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context<Player>) -> imp | |||
| 1446 | .text_color(rgb(INK2())) | 1543 | .text_color(rgb(INK2())) |
| 1447 | .child("Glow"), | 1544 | .child("Glow"), |
| 1448 | ) | 1545 | ) |
| 1449 | - .child(viz_step("dock-viz-glow-minus", "−", cx, |this, cx| { | 1546 | + .child(viz_step("dock-viz-glow-minus", "Less glow", "−", cx, |this, cx| { |
| 1450 | this.set_viz_glow(engine::decode::viz_glow_of(this.viz_paint()).saturating_sub(1), cx); | 1547 | this.set_viz_glow(engine::decode::viz_glow_of(this.viz_paint()).saturating_sub(1), cx); |
| 1451 | })) | 1548 | })) |
| 1452 | .child( | 1549 | .child( |
| @@ -1456,7 +1553,7 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context<Player>) -> imp | |||
| 1456 | .text_color(rgb(INK1())) | 1553 | .text_color(rgb(INK1())) |
| 1457 | .child(format!("{glow}")), | 1554 | .child(format!("{glow}")), |
| 1458 | ) | 1555 | ) |
| 1459 | - .child(viz_step("dock-viz-glow-plus", "+", cx, |this, cx| { | 1556 | + .child(viz_step("dock-viz-glow-plus", "More glow", "+", cx, |this, cx| { |
| 1460 | this.set_viz_glow(engine::decode::viz_glow_of(this.viz_paint()).saturating_add(1).min(16), cx); | 1557 | this.set_viz_glow(engine::decode::viz_glow_of(this.viz_paint()).saturating_add(1).min(16), cx); |
| 1461 | })), | 1558 | })), |
| 1462 | ) | 1559 | ) |
| @@ -1702,6 +1799,7 @@ fn keys_tab(player: &Player, cx: &mut Context<Player>) -> impl IntoElement { | |||
| 1702 | .font(style.font.clone()) | 1799 | .font(style.font.clone()) |
| 1703 | .text_size(style.size) | 1800 | .text_size(style.size) |
| 1704 | .text_color(rgb(INK1())) | 1801 | .text_color(rgb(INK1())) |
| 1802 | + .tooltip(crate::ui::widgets::tip_hover("Filter keys", "click to type", None)) | ||
| 1705 | .children(hitmap::control("dock.keys-filter", "Filter keys", true)) | 1803 | .children(hitmap::control("dock.keys-filter", "Filter keys", true)) |
| 1706 | .child(match player.keys_filter.is_empty() { | 1804 | .child(match player.keys_filter.is_empty() { |
| 1707 | true => "⌕".to_string(), | 1805 | true => "⌕".to_string(), |
crates/app/src/ui/widgets.rsmodified+82 -0
| @@ -470,6 +470,88 @@ impl NumberEdit { | |||
| 470 | } | 470 | } |
| 471 | } | 471 | } |
| 472 | 472 | ||
| 473 | +/// How much text the colour field will hold: `rgba(255, 255, 255, 255)` with | ||
| 474 | +/// room to spare. Every legal colour is far inside it; the cap is there so a | ||
| 475 | +/// held key cannot grow the buffer without bound. | ||
| 476 | +const COLOR_EDIT_CHARS: usize = 32; | ||
| 477 | + | ||
| 478 | +/// A colour being typed into a row that has no text field of its own: the | ||
| 479 | +/// free-text sibling of [`NumberEdit`], for the same reason it exists -- these | ||
| 480 | +/// rows take no gpui focus, so the text is held as state and driven by the | ||
| 481 | +/// root's key handler. One caller, the Clip tab's colour field | ||
| 482 | +/// ([`Player::edit_viz_hex`]): typing, backspace, enter that commits and | ||
| 483 | +/// escape that gives up, and a refusal in words when what is there is not a | ||
| 484 | +/// colour. | ||
| 485 | +#[derive(Clone, Debug, PartialEq, Eq)] | ||
| 486 | +pub(crate) struct ColorEdit { | ||
| 487 | + pub(crate) text: String, | ||
| 488 | + pub(crate) refusal: Option<String>, | ||
| 489 | +} | ||
| 490 | + | ||
| 491 | +impl ColorEdit { | ||
| 492 | + /// Starts on the colour the row already shows, so backspace edits it | ||
| 493 | + /// rather than the field opening empty over a colour still in force | ||
| 494 | + /// ([`NumberEdit::new`]'s own rule). | ||
| 495 | + pub(crate) fn new(seed: &str) -> Self { | ||
| 496 | + ColorEdit { | ||
| 497 | + text: seed.to_string(), | ||
| 498 | + refusal: None, | ||
| 499 | + } | ||
| 500 | + } | ||
| 501 | + | ||
| 502 | + /// One printable stroke. The one past the cap is refused *out loud*: a | ||
| 503 | + /// keystroke dropped in silence is what leaves a field showing something | ||
| 504 | + /// the user did not type ([`NumberEdit::digit`]'s own reason). | ||
| 505 | + pub(crate) fn typed(&mut self, c: char) { | ||
| 506 | + if self.text.chars().count() >= COLOR_EDIT_CHARS { | ||
| 507 | + self.refusal = Some(format!("{COLOR_EDIT_CHARS} characters is already past the field")); | ||
| 508 | + return; | ||
| 509 | + } | ||
| 510 | + self.text.push(c); | ||
| 511 | + self.refusal = None; | ||
| 512 | + } | ||
| 513 | + | ||
| 514 | + /// Erases the last character, and the refusal with it: the text on screen | ||
| 515 | + /// has changed, so the reason the old one was refused no longer describes | ||
| 516 | + /// it. | ||
| 517 | + pub(crate) fn backspace(&mut self) { | ||
| 518 | + self.text.pop(); | ||
| 519 | + self.refusal = None; | ||
| 520 | + } | ||
| 521 | + | ||
| 522 | + /// The colour, or `None` with the reason recorded where the row will read | ||
| 523 | + /// it. Only the shapes the paint field can carry are read at all | ||
| 524 | + /// (`engine::decode::viz_color_from_text`); anything else is refused | ||
| 525 | + /// rather than guessed at, and the refusal says what a colour looks like | ||
| 526 | + /// so the next try is a backspace away. | ||
| 527 | + pub(crate) fn commit(&mut self) -> Option<(u8, u8)> { | ||
| 528 | + match engine::decode::viz_color_from_text(&self.text) { | ||
| 529 | + Some(hue_sat) => { | ||
| 530 | + self.refusal = None; | ||
| 531 | + Some(hue_sat) | ||
| 532 | + } | ||
| 533 | + None => { | ||
| 534 | + self.refusal = Some("type a colour — #RRGGBB or rgb(r,g,b)".to_string()); | ||
| 535 | + None | ||
| 536 | + } | ||
| 537 | + } | ||
| 538 | + } | ||
| 539 | + | ||
| 540 | + /// What the row shows while it is being typed into: the text, the caret | ||
| 541 | + /// that says it is landing *here*, and either the refusal or the two keys | ||
| 542 | + /// that end the edit. | ||
| 543 | + pub(crate) fn detail(&self) -> String { | ||
| 544 | + format!( | ||
| 545 | + "{}▏ {}", | ||
| 546 | + self.text, | ||
| 547 | + match &self.refusal { | ||
| 548 | + Some(why) => why.as_str(), | ||
| 549 | + None => "enter commits · esc cancels", | ||
| 550 | + } | ||
| 551 | + ) | ||
| 552 | + } | ||
| 553 | +} | ||
| 554 | + | ||
| 473 | /// What a window with no file open shows: DESIGN §8 wants a noun, not a | 555 | /// What a window with no file open shows: DESIGN §8 wants a noun, not a |
| 474 | /// sentence -- both ways in (window drop target, Import in the media list) | 556 | /// sentence -- both ways in (window drop target, Import in the media list) |
| 475 | /// are taught by their own geography, not by this label. | 557 | /// are taught by their own geography, not by this label. |