From 880e8a04c4dd97b8aaad167e890481602c496a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 16 Sep 2026 07:19:49 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(audio):=20the=20look=20panel?= =?UTF-8?q?=20picks=20the=20strand=20colour=20and=20reads=20a=20typed=20on?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CLIP tab's look section gains a Colour | Strand target over the disk (Strand only once the waveform has two or more strands) and a field that shows and takes the colour as #RRGGBB or rgb()/rgba(); an unreadable string is refused in words and changes nothing. The wheel acts on the picked slot. Every sample after the press is a live write, so one drag is one undo step rather than sixty. And every click door that writes the project arms autosave -- the look family, the settings rows, the library's source removal -- which none of them did: a colour picked and then closed was lost with no prompt, and the ledger never said "unsaved". --- crates/app/src/main.rs | 14 +- crates/app/src/player/actions.rs | 10 ++ crates/app/src/player/cards.rs | 49 +++++- crates/app/src/player/export.rs | 8 + crates/app/src/player/library.rs | 140 +++++++++++++++-- crates/app/src/player/timeline_edit.rs | 3 + crates/app/src/player/view.rs | 11 ++ crates/app/src/tests/cards.rs | 205 +++++++++++++++++++++++++ crates/app/src/tests/media.rs | 78 +++++++++- crates/app/src/tests/mod.rs | 6 +- crates/app/src/transport.rs | 78 +++++++++- crates/app/src/ui/dock_stance.rs | 132 ++++++++++++++-- crates/app/src/ui/widgets.rs | 82 ++++++++++ 13 files changed, 773 insertions(+), 43 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 37cf1b9..443809c 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -761,13 +761,21 @@ struct Player { viz_hs_dragging: bool, /// The wheel's box, recorded at prepaint for a drag's window position. viz_wheel: Rc>>, + /// Which of the clip's two inks the look section's wheel and colour field + /// act on ([`VizSlot`]): the clip's own colour, or the ring's dual half. + /// The pick stays picked across clips, the way the dock tab's does. + viz_slot: VizSlot, + /// The colour field's text, while the Clip tab's colour row is being typed + /// into ([`Player::edit_viz_hex`]). `None` is the row showing the colour + /// itself; `Some` is the buffer, its refusal, and the caret on screen. + viz_hex_edit: Option, /// The ink the hand is on, held back because the worker still owes a frame /// ([`Self::pending_color`]'s own reason, and a wheel sample is heavier /// than a grade's: it is not a table entry but the painter's own input, so /// the write is what rebuilds the picture). What the wheel draws while it /// stands, and never lost -- the frame that lands writes it, and so does - /// the release. - pending_viz: Option<(u8, u8)>, + /// the release. The slot the sample was taken on rides with it. + pending_viz: Option<(VizSlot, u8, u8)>, /// Each slider's box, recorded at prepaint: a mouse listener is handed the /// window position only, so this is what a press and a drag are read against /// ([`frac_along`]). One per band, because the press picks the row it landed @@ -1078,6 +1086,8 @@ fn main() { color_dragging: false, viz_hs_dragging: false, viz_wheel: Rc::default(), + viz_slot: VizSlot::Main, + viz_hex_edit: None, pending_viz: None, color_bars: std::array::from_fn(|_| Rc::default()), pending_color: None, diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 3d645eb..8f2ad31 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -35,6 +35,16 @@ impl Player { // an autosave a beat early over a refusal (nothing to regroup, say) // costs nothing a real edit would not have earned anyway, and one list // here is the whole answer instead of fifteen scattered calls. + // + // This list is the *action* doors only, and that is the class to mind + // when adding an edit: a control that reaches the session from a + // *click* -- the Clip tab's look chips and wheel, the settings rows, + // the library row's own menu -- is behind no action, so nothing here + // arms it. Such a door has to call `Player::mark_dirty` itself, on its + // own "the write took" gate, or the edit is invisible to autosave, to + // the ledger's `unsaved` ghost and to `Player::close_needs_answer`, + // which all read that one flag: the work is silently lost on close, + // with no prompt to answer. if matches!( action, ActionId::Paste diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 5745f8c..5bbdf9a 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -38,6 +38,10 @@ impl Player { pub(crate) fn apply_resolution(&mut self, width: u32, height: u32, cx: &mut Context) { if let Some(session) = &mut self.session { if session.set_resolution(width, height) { + // A project field written from a click, with no keymap action + // behind it to arm it ([`Player::act`]'s list is the action + // doors only). + self.mark_dirty(); self.notify_user(format!("PROJECT: {width}x{height}").into()); self.reset_after_reseek(); } @@ -60,6 +64,9 @@ impl Player { if let Some(session) = &mut self.session { if session.set_frame_rate(fps) { self.fps = session.meta().frame_rate; + // [`Self::apply_resolution`]'s own reason. Armed after the + // session's own reads, since the borrow outlives nothing. + self.mark_dirty(); self.notify_user(format!("PROJECT: {} fps", fps_label(fps)).into()); self.reset_after_reseek(); } @@ -91,7 +98,15 @@ impl Player { rate.map_or("the source's own rate".to_string(), |r| format!("{r} Hz")) }; if let Some(session) = &mut self.session { + let was = session.sample_rate(); session.set_sample_rate(rate); + // The engine's setter takes no answer back, so the arm is gated + // on the setting having moved: picking the rate already in force + // is not an edit. + let changed = session.sample_rate() != was; + if changed { + self.mark_dirty(); + } self.notify_user( format!( "PROJECT SOUND: {} — takes effect on the next seek, edit or reopen", @@ -122,6 +137,8 @@ impl Player { if let Some(session) = &mut self.session && session.set_tone(preset) { + // [`Self::apply_resolution`]'s own reason. + self.mark_dirty(); self.notify_user(format!("HDR: {} — affects HDR media", tone_label(preset)).into()); self.reset_after_reseek(); } @@ -673,8 +690,10 @@ impl Player { if let Some(speed) = self.pending_speed.take() { self.write_speed(speed, true, cx); } - if let Some((hue, sat)) = self.pending_viz.take() { - self.set_viz_hs(hue, sat, cx); + if let Some((_, hue, sat)) = self.pending_viz.take() { + // Live, as the two above are: the press is the one step this + // gesture rolls back to (`Player::write_viz_hs`). + self.write_viz_hs(hue, sat, true, cx); } } @@ -1838,6 +1857,32 @@ impl Player { } return true; } + // The Clip tab's colour field (`Player::edit_viz_hex`): the + // transition row's own keyboard door, and its free-text half -- + // checked here, beside it, for its reason (the Clip tab is always on + // screen, not modal). Every printable stroke lands in the buffer, so + // a letter that is also a room chord types into the field while it is + // open, exactly as the dock's source filter does. + if self.viz_hex_edit.is_some() { + match key { + ESCAPE => self.viz_hex_edit = None, + "enter" => self.commit_viz_hex(cx), + "backspace" => { + if let Some(edit) = self.viz_hex_edit.as_mut() { + edit.backspace(); + } + } + _ => match typed(key) { + Some(c) => { + if let Some(edit) = self.viz_hex_edit.as_mut() { + edit.typed(c); + } + } + None => return false, + }, + } + return true; + } // The Clip tab's transition duration field (DEBT #111): the same // keyboard door as the export card's bitrate field, checked first // since it can be open while no card is (the Clip tab is always on diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 122bf66..556165f 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -504,7 +504,15 @@ impl Player { /// ([`Self::cache_export_seat`]). pub(crate) fn apply_encoder(&mut self, seat: EncoderSeat, cx: &mut Context) { if let Some(session) = &mut self.session { + let was = session.encoder_seat(); session.set_encoder_seat(seat); + // The seat is written by a settings-row click, so nothing in + // [`Player::act`]'s list arms it -- and the engine's setter takes + // no answer back, so the arm rides the seat having moved. + let changed = session.encoder_seat() != was; + if changed { + self.mark_dirty(); + } self.notify_user(format!("ENCODER: {}", encoder_label(seat)).into()); } cx.notify(); diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index c6216e9..1be6c30 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -198,6 +198,11 @@ impl Player { return; } if session.set_visualizer(lane, idx, clip.visualizer ^ bit) { + // A look is a project field, so the write arms autosave and the + // close prompt the same way a grade or a trim does -- these chips + // are clicked, not dispatched through `act`, so nothing upstream + // has armed it for them. + self.mark_dirty(); self.reset_after_reseek(); } cx.notify(); @@ -218,12 +223,15 @@ impl Player { } let next = engine::decode::with_viz_style(clip.visualizer, style); if next != clip.visualizer && session.set_visualizer(lane, idx, next) { + // [`Self::toggle_viz_flag`]'s own reason: a clicked look arms + // autosave here, because nothing upstream has. + self.mark_dirty(); self.reset_after_reseek(); } cx.notify(); } - pub(crate) fn viz_paint(&self) -> u32 { + pub(crate) fn viz_paint(&self) -> u64 { self.selected .anchor() .and_then(|(lane, idx)| { @@ -236,13 +244,71 @@ impl Player { .unwrap_or(0) } - pub(crate) fn set_viz_hs(&mut self, hue: u8, sat: u8, cx: &mut Context) { + /// Which of the two inks the look section's wheel and colour field act on + /// ([`VizSlot`]). An open colour field is given up with the change: it is + /// seeded with the picked slot's colour, so it would otherwise edit a + /// colour the row is no longer showing. + pub(crate) fn set_viz_slot(&mut self, slot: VizSlot, cx: &mut Context) { + self.viz_slot = slot; + self.viz_hex_edit = None; + cx.notify(); + } + + /// Opens the colour type-in on `seed`, the picked slot's colour as the row + /// already shows it, so a backspace edits that rather than a field opening + /// empty over a colour still in force ([`NumberEdit::new`]'s own rule). The + /// transition row's field is given up: one inline editor at a time. + pub(crate) fn edit_viz_hex(&mut self, seed: &str) { + self.transition_edit = None; + self.viz_hex_edit = Some(ColorEdit::new(seed)); + } + + /// The colour field's enter. A colour it can read is written on the picked + /// slot -- one undo step, a typed colour being one edit -- and the field + /// closes. Anything else is refused *in words* with the field left open and + /// the colour where it was, so the next try is a backspace away. + pub(crate) fn commit_viz_hex(&mut self, cx: &mut Context) { + let Some((hue, sat)) = self.viz_hex_edit.as_mut().and_then(|edit| edit.commit()) else { + // Refused in words: the field stays open holding what it could + // not read. + cx.notify(); + return; + }; + self.viz_hex_edit = None; + // Nothing changed is not an edit. The field opens seeded with the + // row's own `viz_color_hex`, and that hex reads back as a *different* + // (hue, sat) for a large share of inks (the engine's round-trip + // canary counts 47 053 of 65 536 exact), so a commit that wrote + // whatever it parsed would take an undo step -- and arm autosave -- + // for the colour the row was already showing, on an enter that + // changed nothing. + let paint = self.viz_paint(); + let slot = self.viz_slot.picked(paint); + if slot.hue_sat(paint) == (hue, sat) { + cx.notify(); + return; + } + self.write_viz_hs(hue, sat, false, cx); + } + + /// Puts hue and saturation on the picked slot ([`VizSlot::picked`]): the + /// wheel's sample and the colour field's commit both land here, so the two + /// doors cannot disagree about which ink they write. + /// + /// `live` is [`Player::write_color`]'s own flag, for the colour card's + /// reason: the false one takes the undo step the whole gesture rolls back + /// to, the true one is every sample *inside* a drag + /// (`PlaybackSession::set_viz_paint_live`). A wheel sample is not a table + /// entry but the painter's own input, and it is the write that rebuilds the + /// picture at the playhead -- so one committed entry per pointer sample + /// would stamp a sixty-entry gesture into a hundred-step history and leave + /// the user a hundred-step history of one drag. + pub(crate) fn write_viz_hs(&mut self, hue: u8, sat: u8, live: bool, cx: &mut Context) { // A write supersedes whatever a drag was holding // ([`Player::write_color`]'s rule). self.pending_viz = None; - self.set_viz_paint_with(cx, |p| { - engine::decode::with_viz_paint_sat(engine::decode::with_viz_paint_hue(p, hue), sat) - }); + let slot = self.viz_slot; + self.set_viz_paint_with(live, move |p| slot.picked(p).set_hue_sat(p, hue, sat), cx); } /// One pointer sample on the wheel, as the hue and saturation under it. @@ -270,9 +336,13 @@ impl Player { let ang = dx.atan2(dy).to_degrees(); let hue_deg = (ang + 360.) % 360.; let hue = (hue_deg / 360. * 256.).round() as u16 as u8; + // The slot is read once, at the sample that carries it: whichever ink + // the hand picked up is the one the whole gesture writes, and the slot + // is what the held sample draws with while the worker catches up. + let slot = self.viz_slot.picked(self.viz_paint()); let busy = self.seek_since.is_some(); - match stash_or_write(&mut self.pending_viz, (hue, sat), first, busy) { - Some((hue, sat)) => self.set_viz_hs(hue, sat, cx), + match stash_or_write(&mut self.pending_viz, (slot, hue, sat), first, busy) { + Some((_, hue, sat)) => self.write_viz_hs(hue, sat, !first, cx), // The wheel draws off the held sample, so the mark goes on // following the hand while the picture catches up. None => cx.notify(), @@ -280,14 +350,23 @@ impl Player { } pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context) { - self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_strands(p, n)); + self.set_viz_paint_with(false, |p| engine::decode::with_viz_paint_strands(p, n), cx); } pub(crate) fn set_viz_glow(&mut self, n: u8, cx: &mut Context) { - self.set_viz_paint_with(cx, |p| engine::decode::with_viz_paint_glow(p, n)); + self.set_viz_paint_with(false, |p| engine::decode::with_viz_paint_glow(p, n), cx); } - fn set_viz_paint_with(&mut self, cx: &mut Context, f: impl FnOnce(u32) -> u32) { + /// `live` picks the door, as [`Player::write_viz_hs`] does: the strands and + /// glow steppers are presses and take their own undo step, and the two are + /// on the packed bytes rather than on either ink, so they are unaffected by + /// which slot the wheel is on. + fn set_viz_paint_with( + &mut self, + live: bool, + f: impl FnOnce(u64) -> u64, + cx: &mut Context, + ) { let Some((lane, idx)) = self.selected.anchor() else { return; }; @@ -301,8 +380,24 @@ impl Player { return; } let next = f(clip.viz_paint); - if next != clip.viz_paint && session.set_viz_paint(lane, idx, next) { - self.reset_after_reseek(); + if next != clip.viz_paint { + let took = match live { + true => session.set_viz_paint_live(lane, idx, next), + false => session.set_viz_paint(lane, idx, next), + }; + if took { + // Every look write arms autosave and the close gate + // (`write_color`'s own rule, and these doors have no keymap + // action behind them to arm it the way `act` does for the + // verbs): the wheel's press, a strands/glow stepper and a + // typed colour all land here. The drag's live samples land + // here too, which is why the arm is on the write and not on + // the gesture -- `mark_dirty` is idempotent, so the press, the + // samples and the release are one armed edit rather than + // sixty. + self.mark_dirty(); + self.reset_after_reseek(); + } } cx.notify(); } @@ -339,6 +434,11 @@ impl Player { // past the one that went has just moved down: without this the // next paste puts some other file on the timeline. self.clipboard = clipboard_after_remove(std::mem::take(&mut self.clipboard), idx); + // The library is project state, and this door is the row's + // own menu click -- nothing in [`Player::act`]'s list arms + // it. Behind the `Ok`, so a refusal (the engine's own words + // while clips still play the file) is not an edit. + self.mark_dirty(); self.reset_after_reseek(); // The last row leaves a session naming no file: nothing to // play, nothing to save and nothing to show, which is the empty @@ -1020,6 +1120,12 @@ impl Player { pub(crate) fn apply_proxies(&mut self) { let (on, auto) = (self.proxies_on, self.auto_proxies_on); if let Some(session) = &mut self.session { + // Deliberately not armed: the only caller is + // [`Self::install_media`], the import/load path, where arming is + // the one thing the `autosave_armed` rule forbids -- a project + // nobody has written must not start asking to be saved. The + // user's own door is the switch ([`Self::toggle_proxies`] / + // [`Self::toggle_auto_proxies`]), and that is where the arm is. session.set_proxies(on); session.set_auto_proxies(auto); } @@ -1062,7 +1168,11 @@ impl Player { let on = !self.proxies_on; self.proxies_on = on; if let Some(session) = &mut self.session { + let changed = session.proxies() != on; session.set_proxies(on); + if changed { + self.mark_dirty(); + } } // What is really under the switch, said in the same breath: a project // whose films have no stand-in yet would otherwise read as a switch @@ -1124,7 +1234,13 @@ impl Player { let on = !self.auto_proxies_on; self.auto_proxies_on = on; if let Some(session) = &mut self.session { + // [`Self::toggle_proxies`]'s own gate: the switch is a click and + // the session is where the project hears it. + let changed = session.auto_proxies() != on; session.set_auto_proxies(on); + if changed { + self.mark_dirty(); + } } let text = match on { true => "AUTO PROXIES ON — every import gets a stand-in", diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index f7cd0ba..a7577d4 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1820,6 +1820,9 @@ impl Player { /// offers a number a step could not also land on. pub(crate) fn edit_transition(&mut self, frames: u32, cap: u32) { let digits = cap.to_string().chars().count() + 1; + // The Clip tab's colour field is given up: one inline editor at a + // time, since both are driven by the one key branch that finds them. + self.viz_hex_edit = None; self.transition_edit = Some(NumberEdit::new(frames, 0, cap, digits, "frames")); } diff --git a/crates/app/src/player/view.rs b/crates/app/src/player/view.rs index ea0f3ed..afdbf38 100644 --- a/crates/app/src/player/view.rs +++ b/crates/app/src/player/view.rs @@ -183,10 +183,21 @@ impl Player { fit: FitPolicy, cx: &mut Context, ) { + // The policy has to have moved before this is an edit: `set_fit` + // answers "the index existed", not "the value changed" (the engine + // snapshot-and-rewrites the same policy and still says true), and the + // list keeps the row already in force clickable -- so the engine's + // own bool would light the ledger's `unsaved` ghost over a project + // nobody touched. if let Some(session) = &mut self.session + && session.fit_of(lane, idx) != fit && session.set_fit(lane, idx, fit) { let (w, h) = session.resolution(); + // A clip's own fit policy, written from a click: arms autosave + // and the close gate itself ([`Player::act`]'s list is the action + // doors only). + self.mark_dirty(); self.notify_user(format!("FIT POLICY: {} on {w}x{h}", fit_label(fit)).into()); self.reset_after_reseek(); } diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index a440981..b426fd6 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -1356,6 +1356,211 @@ fn a_typed_transition_duration_clamps_like_its_own_stepper() { assert_eq!(edit.commit_clamped(), 0); } +/// The colour field (`ColorEdit`), the transition field's free-text sibling: +/// every spelling of one colour lands on the same pair, the pair is what the +/// row shows back as a hex, and text that is not a colour is refused in words +/// while the field goes on holding it -- never dropped in silence, never +/// guessed at, and never cleared by the refusal itself. +#[test] +fn a_typed_colour_is_read_in_every_spelling_and_anything_else_is_refused() { + use engine::decode::{viz_color_from_text, viz_color_hex}; + + // One colour in every spelling the field takes: red as `#RRGGBB`, as bare + // digits, as `rgb(..)`, and as `rgba(..)` with the alpha dropped. Two + // spellings of one colour landing on different pairs would be a field + // whose colour depends on how it was written. + let red = viz_color_from_text("#FF0000").expect("red is a colour"); + for text in ["#FF0000", "FF0000", "rgb(255,0,0)", "rgba(255,0,0,255)"] { + let mut edit = ColorEdit::new(""); + for c in text.chars() { + edit.typed(c); + } + assert_eq!(edit.commit(), Some(red), "{text}"); + assert_eq!(edit.refusal, None, "{text} is a colour, not a refusal"); + } + + // The round trip through what the row displays: the hex the row shows + // reads back as the same pair, so opening the field on it and pressing + // enter changes nothing. A seed taken from anywhere else -- or a hex + // spelled by something other than the field's own reader -- shows up here. + let hex = viz_color_hex(red.0, red.1); + let mut edit = ColorEdit::new(&hex); + assert_eq!(edit.text, hex, "the field opens on the row's own line"); + assert!(edit.detail().contains("enter commits")); + assert_eq!(edit.commit(), Some(red)); + assert_eq!(edit.refusal, None); + + // Text that is not a colour: refused in words that say what a colour + // looks like, and the text survives the refusal -- a refusal that ate what + // was typed would make the next try retype all of it. + let mut edit = ColorEdit::new(""); + edit.typed('z'); + edit.typed('z'); + assert_eq!(edit.commit(), None); + let why = edit.refusal.clone().expect("a refusal, not a silence"); + assert!(why.contains("#RRGGBB"), "the refusal says what a colour is: {why}"); + assert_eq!(edit.text, "zz", "the refusal keeps the text it refused"); + assert!(edit.detail().contains("zz▏"), "the caret stays in the buffer"); + // ...and the next stroke clears it: that reason described the text that is + // no longer there. + edit.typed('0'); + assert_eq!(edit.refusal, None); + assert_eq!(edit.text, "zz0"); + + // Backspace erases the last character and the refusal with it, and the + // buffer is capped out loud rather than growing without bound off a held + // key. + let mut edit = ColorEdit::new(&hex); + edit.backspace(); + assert_eq!(edit.text.chars().count(), hex.chars().count() - 1); + for _ in 0..64 { + edit.typed('f'); + } + assert_eq!(edit.text.chars().count(), 32); + assert!(edit.refusal.is_some(), "the stroke past the cap says so"); + + // Why the commit compares before it writes: the field opens seeded with + // `viz_color_hex(now)`, and that hex reads back as a *different* pair for + // a good share of inks (the engine's round-trip canary counts 47 053 of + // 65 536 exact), so "write whatever the parse gave" would take an undo + // step for the colour the row was already showing. The fact is held here; + // the gate that reads it is pinned below. + let mut inexact = 0; + for hue in 0..=255u8 { + for sat in [0u8, 64, 160, 255] { + let seed = viz_color_hex(hue, sat); + match viz_color_from_text(&seed) { + // Exact: entering the seed is already a no-op for the write + // gate, whatever the gate says. + Some(pair) if pair == (hue, sat) => {} + // Inexact: this is the case the gate exists for -- without it + // every one of these takes a committing write on an untouched + // colour. + Some(_) => inexact += 1, + None => panic!("the row's own hex must be readable back: {seed}"), + } + } + } + assert!( + inexact > 0, + "no ink round-trips inexactly -- the commit's no-op gate would be dead weight" + ); + + // The gate itself, in the door that has it (`Player::commit_viz_hex`): the + // parse, then the comparison with the picked slot's own colour, and the + // write only past it. + let body = fn_body("commit_viz_hex"); + let gate = body + .split_once("hue_sat(paint)") + .expect("the commit no longer compares with the colour on the slot") + .1; + assert!( + gate.contains("write_viz_hs("), + "the commit writes before it has compared, so the row's own seed is an edit" + ); +} + +/// The look family's writes arm autosave, and therefore the ledger's `unsaved` +/// ghost and `Player::close_needs_answer`, which read the same flag: a colour +/// picked in the Clip tab that armed nothing could be closed away with no +/// prompt and no autosave. +/// +/// A scan and not a drive: every one of these doors needs a `Player` and a +/// gpui `Context`, and this crate has no window harness (`tests/view.rs`'s own +/// note). What a scan can hold is the three doors themselves -- the two the +/// whole paint family shares (`set_viz_paint_with` is where the wheel, the +/// steppers and a typed colour all land) and the two writes that do not go +/// through it (the style chips and the `Fast` chip, which write +/// `clip.visualizer`). Pre-fix none of the three armed anything while every +/// other engine-writing door did (`write_color`, `write_transform`, +/// `set_eq`, the trim/place/fade doors). +#[test] +fn a_visualizer_look_write_arms_autosave() { + for name in ["set_viz_style", "toggle_viz_flag"] { + let body = fn_body(name); + assert!( + body.contains("session.set_visualizer"), + "{name} no longer writes the clip's look at all" + ); + assert!( + body.contains("mark_dirty()"), + "{name} writes a look and arms nothing" + ); + } + let body = fn_body("set_viz_paint_with"); + // The arm rides the write that took, not the call: a no-op press (the + // colour under the hand already) is not an edit, and the ghost must stay + // off it. + let took = body + .split_once("if took {") + .expect("the paint door writes through a taken-write gate") + .1; + assert!( + took.contains("mark_dirty()"), + "the arm is outside the write gate, so a no-op press would dirty the project" + ); + assert!( + took.contains("reset_after_reseek()"), + "the arm replaced the reseek bookkeeping instead of joining it" + ); +} + +/// The rest of the class the visualizer look family belonged to: every other +/// door that writes the project from a *click* and so has no action behind it +/// to arm autosave ([`Player::act`]'s list is the action doors only). Each arm +/// rides its own "the write took" gate -- a pick that changed nothing must not +/// dirty the project, or a window nobody has touched would ask to be saved. +#[test] +fn every_click_door_that_writes_the_project_arms_autosave() { + // The doors the engine answers with a bool *that means "the value + // moved"*: the arm goes inside it. + for name in ["apply_resolution", "apply_frame_rate", "apply_tone"] { + let body = fn_body(name); + assert!( + body.contains("mark_dirty()"), + "{name} writes the project and arms nothing" + ); + } + // ...and the one whose bool does not mean that at all: `set_fit` says the + // index existed, and the picker keeps the row already in force clickable, + // so the arm rides the policy having moved -- on the engine's own bool it + // would light the `unsaved` ghost over a project nobody touched. + let body = fn_body("apply_fit"); + assert!( + body.contains("fit_of(lane, idx) != fit"), + "apply_fit arms on the engine's own bool again, which a no-op pick also answers true" + ); + assert!(body.contains("mark_dirty()"), "apply_fit arms nothing"); + // The import path keeps no arm on purpose (the `autosave_armed` rule): its + // only caller is `install_media`, so an arm there could only ever fire for + // a project nobody has touched. The user's door is the two toggles. + let body = fn_body("apply_proxies"); + assert!( + body.find("mark_dirty").is_none(), + "apply_proxies arms again -- its only caller is the import path" + ); + // The doors whose setter takes no answer back, and the library row's + // removal: the arm rides a local `changed` (or the removal having landed), + // never the call. + for (name, gate) in [ + ("apply_sample_rate", "if changed {"), + ("apply_encoder", "if changed {"), + ("toggle_proxies", "if changed {"), + ("toggle_auto_proxies", "if changed {"), + ("remove_source", "Some(Ok(idx))"), + ] { + let body = fn_body(name); + let after = body + .split_once(gate) + .unwrap_or_else(|| panic!("{name} lost the gate its arm rides")) + .1; + assert!( + after.contains("mark_dirty()"), + "{name} arms outside its gate, so a no-op pick would dirty the project" + ); + } +} + /// [`crate::ui::dock_stance::transition_of`]: the dock's duration row /// appears only for an anchor that actually carries a dissolve or a /// crossfade, and the room it offers is capped at what the successor clip diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index 71c09bc..087b78e 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -214,12 +214,12 @@ fn the_wheel_draws_the_sample_a_drag_is_holding() { assert_eq!(viz_held_paint(0, None), 0); assert_eq!(viz_held_paint(0x0208_d2fd, None), 0x0208_d2fd); // Held: that hue and saturation over what the clip already carries. - let held = viz_held_paint(0, Some((253, 210))); + let held = viz_held_paint(0, Some((VizSlot::Main, 253, 210))); assert_eq!(engine::decode::viz_hue_ui(held), 253); assert_eq!(engine::decode::viz_sat_ui(held), 210); // ...in that order, never the other way round: a mark drawn at the wrong // angle is the whole gesture showing the wrong colour. - let flipped = viz_held_paint(0, Some((210, 253))); + let flipped = viz_held_paint(0, Some((VizSlot::Main, 210, 253))); assert_ne!(held, flipped); assert_eq!(engine::decode::viz_hue_ui(flipped), 210); assert_eq!(engine::decode::viz_sat_ui(flipped), 253); @@ -229,11 +229,83 @@ fn the_wheel_draws_the_sample_a_drag_is_holding() { assert_eq!(engine::decode::viz_glow_of(held), 2); let pen = engine::decode::with_viz_paint_glow(0x0208_d2fd, 9); assert_eq!( - engine::decode::viz_glow_of(viz_held_paint(pen, Some((253, 210)))), + engine::decode::viz_glow_of(viz_held_paint(pen, Some((VizSlot::Main, 253, 210)))), 9 ); } +/// The strand's half of the same gesture, and the two things a second ink on +/// the one wheel may not get wrong. A strand the clip has not chosen starts at +/// the automatic complement the painter draws there -- the clip's hue half a +/// turn round, at the clip's own saturation -- so the mark is on a colour the +/// picture already has and the first write only says "this one, then". And the +/// clip's own ink is not touched by any of it: the whole point of a second ink +/// is that one slot's writes leave the other alone. +#[test] +fn the_strand_slot_starts_at_the_complement_and_the_write_chooses_it() { + use engine::decode::{ + viz_hue_ui, viz_sat_ui, viz_strand_hue_ui, viz_strand_sat_ui, viz_strand_set, + with_viz_paint_hue, with_viz_paint_strands, VIZ_PAINT_AZURE, + }; + + let paint = with_viz_paint_strands(VIZ_PAINT_AZURE, 2); + assert!(!viz_strand_set(paint), "no strand colour chosen yet"); + assert_eq!( + VizSlot::Strand.hue_sat(paint), + (viz_hue_ui(paint).wrapping_add(128), viz_sat_ui(paint)), + "the unset strand stands where the painter draws its complement" + ); + // ...half a turn round, wrapping: hue 200's complement is 72, not 328. + let late = with_viz_paint_hue(paint, 200); + assert_eq!(VizSlot::Strand.hue_sat(late).0, 200u8.wrapping_add(128)); + assert_eq!(VizSlot::Strand.hue_sat(late).0, 72); + + // The write is what chooses it, and reads back as what was written. + let picked = VizSlot::Strand.set_hue_sat(paint, 0, 255); + assert!(viz_strand_set(picked)); + assert_eq!(viz_strand_hue_ui(picked), 0); + assert_eq!(viz_strand_sat_ui(picked), 255); + assert_eq!(VizSlot::Strand.hue_sat(picked), (0, 255)); + // The clip's own colour survives the strand's writes untouched. + assert_eq!(viz_hue_ui(picked), viz_hue_ui(paint)); + assert_eq!(viz_sat_ui(picked), viz_sat_ui(paint)); + // A held strand sample draws the strand, not the clip's colour: the slot + // rides with the sample. + let held = viz_held_paint(paint, Some((VizSlot::Strand, 0, 255))); + assert_eq!(VizSlot::Strand.hue_sat(held), (0, 255)); + assert_eq!(viz_strand_set(held), true); + // And the wheel's own slot writes only its own bytes. + let main = VizSlot::Main.set_hue_sat(picked, 33, 44); + assert_eq!((viz_hue_ui(main), viz_sat_ui(main)), (33, 44)); + assert_eq!((viz_strand_hue_ui(main), viz_strand_sat_ui(main)), (0, 255)); +} + +/// One strand has no dual half, so the strand slot falls back to the clip's own +/// colour: a write there lands on the ink the picture actually paints instead +/// of choosing a strand colour nothing wears. Two strands put it back -- the +/// same reading the Strand chip is enabled by. +#[test] +fn a_strand_slot_on_a_single_strand_clip_is_the_clip_s_own_colour() { + use engine::decode::{ + viz_hue_ui, viz_sat_ui, viz_strand_set, viz_strands_of, with_viz_paint_hue, + with_viz_paint_sat, with_viz_paint_strands, VIZ_PAINT_AZURE, + }; + + let one = with_viz_paint_strands( + with_viz_paint_sat(with_viz_paint_hue(VIZ_PAINT_AZURE, 64), 200), + 1, + ); + assert_eq!(viz_strands_of(one), 1); + assert_eq!(VizSlot::Strand.picked(one), VizSlot::Main); + let hit = VizSlot::Strand.picked(one).set_hue_sat(one, 0, 255); + assert!(!viz_strand_set(hit), "one strand chooses no strand colour"); + assert_eq!((viz_hue_ui(hit), viz_sat_ui(hit)), (0, 255)); + // The clip's own slot is never redirected -- it is what the fallback + // lands on. + assert_eq!(VizSlot::Main.picked(one), VizSlot::Main); + assert_eq!(VizSlot::Strand.picked(with_viz_paint_strands(one, 2)), VizSlot::Strand); +} + /// A seek says nothing until it has stood: an ordinary one is a flicker and /// a cold read of a big file is the case worth words. #[test] diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 59379e2..19e70aa 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -11,7 +11,8 @@ mod view; use super::{ ACCENT_PRIMARY, AUDIO_KBPS, BG_RAISED, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, - CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, + ColorEdit, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT, + EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, Enable, 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::{ row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label, rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, timecode, timeline_fixed_h, tip_may_paint, - transport, typed, unseen_paths, unseen_sources, viz_held_paint, whole_take, window_title, + transport, typed, unseen_paths, unseen_sources, viz_held_paint, VizSlot, whole_take, + window_title, }; use super::{ diff --git a/crates/app/src/transport.rs b/crates/app/src/transport.rs index d8da8ed..a877333 100644 --- a/crates/app/src/transport.rs +++ b/crates/app/src/transport.rs @@ -204,18 +204,86 @@ pub(crate) fn stash_or_write( } } +/// Which of a visualizer's two inks a look control acts on: the clip's own +/// colour, or the second half of a dual-strand ring. Zero -- the clip's own -- +/// is what every control meant before there was a second, so it is also what +/// the Clip tab opens on ([`Player::viz_slot`]). +/// +/// Both inks are read and written through the same three methods, so the +/// wheel, the hex field and the drag that holds a sample between them cannot +/// disagree about which one a gesture is on. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub(crate) enum VizSlot { + /// The clip's own hue and saturation -- the paint field's low bytes. + Main, + /// The ring's dual half. Only a clip that chose one wears it; otherwise + /// the painter draws the automatic complement (`visualizer_i420`). + Strand, +} + +impl VizSlot { + /// The ink with a picture behind it. A one-strand ring has no dual half, + /// so a wheel on the strand colour there would move a mark and nothing + /// else: every control reads the slot through here and lands on the clip's + /// own colour instead while that is the case -- which is also why the + /// Strand chip is dead then. + pub(crate) fn picked(self, paint: u64) -> VizSlot { + match self { + VizSlot::Strand if engine::decode::viz_strands_of(paint) < 2 => VizSlot::Main, + slot => slot, + } + } + + /// What this ink is showing: the clip's hue and saturation, or -- for a + /// strand the clip has not chosen -- the automatic complement the painter + /// draws there, so a hand picking the strand up starts where the picture + /// already is and the first write only says "this one, then". + pub(crate) fn hue_sat(self, paint: u64) -> (u8, u8) { + match self { + VizSlot::Main => ( + engine::decode::viz_hue_ui(paint), + engine::decode::viz_sat_ui(paint), + ), + VizSlot::Strand if engine::decode::viz_strand_set(paint) => ( + engine::decode::viz_strand_hue_ui(paint), + engine::decode::viz_strand_sat_ui(paint), + ), + VizSlot::Strand => ( + engine::decode::viz_hue_ui(paint).wrapping_add(128), + engine::decode::viz_sat_ui(paint), + ), + } + } + + /// Sets this ink's hue and saturation, raising the strand's chosen flag on + /// the way -- the engine's strand setters do that, which is what makes the + /// wheel's first sample on the slot the write that chooses it. + pub(crate) fn set_hue_sat(self, paint: u64, hue: u8, sat: u8) -> u64 { + match self { + VizSlot::Main => engine::decode::with_viz_paint_sat( + engine::decode::with_viz_paint_hue(paint, hue), + sat, + ), + VizSlot::Strand => engine::decode::with_viz_paint_strand_sat( + engine::decode::with_viz_paint_strand_hue(paint, hue), + sat, + ), + } + } +} + /// What the wheel draws: the clip's own ink, or the sample a drag is holding /// while the worker is still behind ([`stash_or_write`]). The wheel is a /// picker with no table of its own, so a held sample would otherwise be /// invisible -- the clip carries the sample *before* it until the holding /// frame lands -- and the mark would sit still under a moving hand. /// [`Player::color_params`] holds exactly this rule for the card's sliders. -pub(crate) fn viz_held_paint(paint: u32, held: Option<(u8, u8)>) -> u32 { +/// +/// The held sample carries its slot, so a drag on the strand colour draws the +/// strand colour even before the clip has one of its own. +pub(crate) fn viz_held_paint(paint: u64, held: Option<(VizSlot, u8, u8)>) -> u64 { match held { - Some((hue, sat)) => engine::decode::with_viz_paint_sat( - engine::decode::with_viz_paint_hue(paint, hue), - sat, - ), + Some((slot, hue, sat)) => slot.set_hue_sat(paint, hue, sat), None => paint, } } diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 14d7552..7719105 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -1214,6 +1214,7 @@ fn viz_style_verbs(player: &Player, cx: &mut Context) -> impl IntoElemen .text_color(rgb(if on { INK1() } else { INK3() })) .font(row.font) .text_size(row.size) + .tooltip(crate::ui::widgets::tip_hover(label_text, "", None)) .children(hitmap::control(id, label_text, true)) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.set_viz_style(style, cx); @@ -1238,6 +1239,7 @@ fn viz_style_verbs(player: &Player, cx: &mut Context) -> impl IntoElemen .text_color(rgb(if on { INK1() } else { INK3() })) .font(style.font.clone()) .text_size(style.size) + .tooltip(crate::ui::widgets::tip_hover(label_text, "", None)) .children(hitmap::control(id, label_text, true)) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.toggle_viz_flag(bit, cx); @@ -1290,6 +1292,9 @@ fn viz_style_verbs(player: &Player, cx: &mut Context) -> impl IntoElemen fn viz_step( id: &'static str, + // What the button is called on hover and in the hitmap: the glyph alone + // names nothing. + name: &'static str, glyph: &'static str, cx: &mut Context, f: impl Fn(&mut Player, &mut Context) + 'static + Copy, @@ -1304,18 +1309,115 @@ fn viz_step( .rounded(px(3.)) .bg(rgb(DARK_RAISED())) .cursor_pointer() - .children(hitmap::control(id, glyph, true)) + .tooltip(crate::ui::widgets::tip_hover(name, "", None)) + .children(hitmap::control(id, name, true)) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| f(this, cx))) .child(glyph) } -fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context) -> impl IntoElement { +/// Which of the clip's two inks the wheel and the colour field are on. The +/// picked chip wears the solid ink and the other the quiet one -- the style +/// chips' own shape (`viz_style_verbs`'s `pick`, one row up the same column). +/// +/// The Strand chip is dead while the clip has one strand: a strand colour is +/// painted on the ring's *dual* half and a one-strand ring has none, so the +/// chip would be wired to nothing -- and it says so on hover rather than doing +/// nothing in silence (`widgets::control`'s own rule for a button with no +/// action). +fn viz_slot_chips(player: &Player, paint: u64, cx: &mut Context) -> impl IntoElement { + let picked = player.viz_slot.picked(paint); + let strand_live = engine::decode::viz_strands_of(paint) >= 2; + let chip = |id: &'static str, label_text: &'static str, slot: VizSlot, live: bool| { + let row = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); + let on = picked == slot; + div() + .id(id) + .flex_none() + .h(px(CONTROL_H)) + .px(px(8.)) + .flex() + .items_center() + .font(row.font) + .text_size(row.size) + .text_color(rgb(if on { INK1() } else { INK3() })) + .tooltip(crate::ui::widgets::tip_hover( + label_text, + "", + match live { + true => None, + false => Some("needs two strands"), + }, + )) + .children(hitmap::control(id, label_text, live)) + .when(!live, |d| d.opacity(0.4).cursor_not_allowed()) + .when(live, |d| { + d.cursor_pointer() + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.set_viz_slot(slot, cx); + })) + }) + .child(label_text.to_string()) + .into_any_element() + }; + div() + .id("dock-viz-slots") + .flex() + .items_center() + .child(chip("dock-viz-colour", "Colour", VizSlot::Main, true)) + .child(chip("dock-viz-strand", "Strand", VizSlot::Strand, strand_live)) +} + +/// The picked slot's colour as text, and the way in: a click opens the type-in +/// seeded with exactly what the row is showing +/// ([`Player::edit_viz_hex`]). While the field is open the row is the buffer +/// and its refusal instead -- `transition_row`'s own rule for its own field. +fn viz_hex_row(player: &Player, paint: u64, cx: &mut Context) -> impl IntoElement { + let (hue, sat) = player.viz_slot.picked(paint).hue_sat(paint); + let hex = engine::decode::viz_color_hex(hue, sat); + // The seed the click opens on is the line the row is showing, so a click + // that lands while the field is open cannot seed it with something else. + let seed = hex.clone(); + let field = player.viz_hex_edit.as_ref(); + let row = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); + div() + .id("dock-viz-hex-field") + .h(px(CONTROL_H)) + .flex() + .items_center() + .font(row.font) + .text_size(row.size) + .text_color(rgb(INK2())) + .cursor_pointer() + .tooltip(crate::ui::widgets::tip_hover("Colour", "click to type", None)) + .children(hitmap::control( + "dock-viz-hex-field", + "Colour hex, type-in", + true, + )) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.edit_viz_hex(&seed); + cx.notify(); + })) + .child(match field { + Some(edit) => edit.detail(), + None => hex, + }) +} + +fn viz_color_wheel(player: &Player, paint: u64, cx: &mut Context) -> impl IntoElement { + // What the mark is on, read out here because the canvas closure paints and + // so cannot borrow the player: the picked slot's ink + // ([`VizSlot::hue_sat`]) -- the clip's own colour, or, for a strand the + // clip has not chosen, the automatic complement, so the hand starts where + // the picture already is. + let (mark_hue, mark_sat) = player.viz_slot.picked(paint).hue_sat(paint); div() .id("dock-viz-hs") .w(px(112.)) .h(px(112.)) .relative() .cursor_pointer() + .tooltip(crate::ui::widgets::tip_hover("Colour wheel", "drag to pick", None)) .children(hitmap::control("dock-viz-hs", "Colour wheel", true)) .child(bounds_probe(player.viz_wheel.clone())) .child( @@ -1351,8 +1453,8 @@ fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context) -> imp } } // Selection mark. - let hue = f32::from(engine::decode::viz_hue_ui(paint)) / 256. * std::f32::consts::TAU; - let sat = f32::from(engine::decode::viz_sat_ui(paint)) / 255.; + let hue = f32::from(mark_hue) / 256. * std::f32::consts::TAU; + let sat = f32::from(mark_sat) / 255.; let mx = cx + radius * sat * hue.sin(); let my = cy - radius * sat * hue.cos(); let mut mark = PathBuilder::stroke(px(2.)); @@ -1382,7 +1484,7 @@ fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context) -> imp ) } -fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context) -> impl IntoElement { +fn viz_paint_knobs(player: &Player, paint: u64, cx: &mut Context) -> impl IntoElement { let strands = engine::decode::viz_strands_of(paint); let glow = engine::decode::viz_glow_of(paint); 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) -> imp .flex() .flex_col() .gap(px(4.)) - .child( - div() - .font(style.font.clone()) - .text_size(style.size) - .text_color(rgb(INK2())) - .child("Colour"), - ) - .child(viz_color_wheel(player, paint, cx)), + .child(viz_slot_chips(player, paint, cx)) + .child(viz_color_wheel(player, paint, cx)) + .child(viz_hex_row(player, paint, cx)), ) .child( div() @@ -1419,7 +1516,7 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context) -> imp .text_color(rgb(INK2())) .child("Strands"), ) - .child(viz_step("dock-viz-strands-minus", "−", cx, |this, cx| { + .child(viz_step("dock-viz-strands-minus", "Fewer strands", "−", cx, |this, cx| { this.set_viz_strands(engine::decode::viz_strands_of(this.viz_paint()).saturating_sub(1).max(1), cx); })) .child( @@ -1429,7 +1526,7 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context) -> imp .text_color(rgb(INK1())) .child(format!("{strands}")), ) - .child(viz_step("dock-viz-strands-plus", "+", cx, |this, cx| { + .child(viz_step("dock-viz-strands-plus", "More strands", "+", cx, |this, cx| { this.set_viz_strands(engine::decode::viz_strands_of(this.viz_paint()).saturating_add(1).min(32), cx); })), ) @@ -1446,7 +1543,7 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context) -> imp .text_color(rgb(INK2())) .child("Glow"), ) - .child(viz_step("dock-viz-glow-minus", "−", cx, |this, cx| { + .child(viz_step("dock-viz-glow-minus", "Less glow", "−", cx, |this, cx| { this.set_viz_glow(engine::decode::viz_glow_of(this.viz_paint()).saturating_sub(1), cx); })) .child( @@ -1456,7 +1553,7 @@ fn viz_paint_knobs(player: &Player, paint: u32, cx: &mut Context) -> imp .text_color(rgb(INK1())) .child(format!("{glow}")), ) - .child(viz_step("dock-viz-glow-plus", "+", cx, |this, cx| { + .child(viz_step("dock-viz-glow-plus", "More glow", "+", cx, |this, cx| { this.set_viz_glow(engine::decode::viz_glow_of(this.viz_paint()).saturating_add(1).min(16), cx); })), ) @@ -1702,6 +1799,7 @@ fn keys_tab(player: &Player, cx: &mut Context) -> impl IntoElement { .font(style.font.clone()) .text_size(style.size) .text_color(rgb(INK1())) + .tooltip(crate::ui::widgets::tip_hover("Filter keys", "click to type", None)) .children(hitmap::control("dock.keys-filter", "Filter keys", true)) .child(match player.keys_filter.is_empty() { true => "⌕".to_string(), diff --git a/crates/app/src/ui/widgets.rs b/crates/app/src/ui/widgets.rs index b8c63a7..7fcb85b 100644 --- a/crates/app/src/ui/widgets.rs +++ b/crates/app/src/ui/widgets.rs @@ -470,6 +470,88 @@ impl NumberEdit { } } +/// How much text the colour field will hold: `rgba(255, 255, 255, 255)` with +/// room to spare. Every legal colour is far inside it; the cap is there so a +/// held key cannot grow the buffer without bound. +const COLOR_EDIT_CHARS: usize = 32; + +/// A colour being typed into a row that has no text field of its own: the +/// free-text sibling of [`NumberEdit`], for the same reason it exists -- these +/// rows take no gpui focus, so the text is held as state and driven by the +/// root's key handler. One caller, the Clip tab's colour field +/// ([`Player::edit_viz_hex`]): typing, backspace, enter that commits and +/// escape that gives up, and a refusal in words when what is there is not a +/// colour. +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct ColorEdit { + pub(crate) text: String, + pub(crate) refusal: Option, +} + +impl ColorEdit { + /// Starts on the colour the row already shows, so backspace edits it + /// rather than the field opening empty over a colour still in force + /// ([`NumberEdit::new`]'s own rule). + pub(crate) fn new(seed: &str) -> Self { + ColorEdit { + text: seed.to_string(), + refusal: None, + } + } + + /// One printable stroke. The one past the cap is refused *out loud*: a + /// keystroke dropped in silence is what leaves a field showing something + /// the user did not type ([`NumberEdit::digit`]'s own reason). + pub(crate) fn typed(&mut self, c: char) { + if self.text.chars().count() >= COLOR_EDIT_CHARS { + self.refusal = Some(format!("{COLOR_EDIT_CHARS} characters is already past the field")); + return; + } + self.text.push(c); + self.refusal = None; + } + + /// Erases the last character, and the refusal with it: the text on screen + /// has changed, so the reason the old one was refused no longer describes + /// it. + pub(crate) fn backspace(&mut self) { + self.text.pop(); + self.refusal = None; + } + + /// The colour, or `None` with the reason recorded where the row will read + /// it. Only the shapes the paint field can carry are read at all + /// (`engine::decode::viz_color_from_text`); anything else is refused + /// rather than guessed at, and the refusal says what a colour looks like + /// so the next try is a backspace away. + pub(crate) fn commit(&mut self) -> Option<(u8, u8)> { + match engine::decode::viz_color_from_text(&self.text) { + Some(hue_sat) => { + self.refusal = None; + Some(hue_sat) + } + None => { + self.refusal = Some("type a colour — #RRGGBB or rgb(r,g,b)".to_string()); + None + } + } + } + + /// What the row shows while it is being typed into: the text, the caret + /// that says it is landing *here*, and either the refusal or the two keys + /// that end the edit. + pub(crate) fn detail(&self) -> String { + format!( + "{}▏ {}", + self.text, + match &self.refusal { + Some(why) => why.as_str(), + None => "enter commits · esc cancels", + } + ) + } +} + /// What a window with no file open shows: DESIGN §8 wants a noun, not a /// sentence -- both ways in (window drop target, Import in the media list) /// are taught by their own geography, not by this label.