diff --git a/crates/app/src/interact.rs b/crates/app/src/interact.rs index ebfeb6a..9cd92e3 100644 --- a/crates/app/src/interact.rs +++ b/crates/app/src/interact.rs @@ -214,7 +214,7 @@ pub(crate) fn drag_scrim(cx: &mut Context) -> Div { /// stop following the hand on the first move. `stop_propagation` so the press /// never reaches the region under it -- a seam over the timeline must not scrub. pub(crate) fn divider(split: Split, cx: &mut Context) -> Div { - let across = matches!(split, Split::Timeline); + let across = matches!(split, Split::Timeline | Split::Bench); div() .flex_none() .when(across, |d| d.h(px(SPLIT_W)).w_full().cursor_row_resize()) diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index 41d7641..5276f46 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -382,14 +382,18 @@ pub(crate) const PPS_DEFAULT: f64 = 40.; // -- the seams between the regions, and where a hand has dragged them --------- -/// Which divider a hand has hold of. The three seams the main layout has -- -/// library|picture, picture|inspector and the timeline's top edge -- and so the -/// only three sizes in this window a person sets rather than is given. +/// Which divider a hand has hold of. The legacy tree's three seams -- +/// library|picture, picture|inspector and the timeline's top edge -- plus the +/// darkroom's own two, dock|centre and time-band|bench: `stance.rs`'s own +/// `BENCH_H`/`DOCK_W` doc comments named this exact fold as the fix for +/// "fields are not stretchable" before this diff existed. #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub(crate) enum Split { Library, Inspector, Timeline, + Dock, + Bench, } /// How wide a divider is drawn *and* hit. Wider than the 1 px stroke it stands @@ -409,6 +413,11 @@ pub(crate) const SIDE_MAX_FRAC: f32 = 1. / 3.; /// timeline is asking on purpose, and the picture still keeps most of a third. pub(crate) const TIMELINE_MAX_SHARE: f32 = 0.7; +/// The least the darkroom's bench may be dragged to: a section head and one +/// [`LANE_H`] row -- [`bench_stance::render`]'s own floor, read here rather +/// than duplicated so the seam and the region it drags never disagree. +pub(crate) const BENCH_MIN_H: f32 = 20. + LANE_H; + /// What a hand has done to the three seams: the size it dragged each panel to, /// or `None` where nobody has touched one and the window's own share still /// answers. Held in the model and not recomputed, so a size outlives the @@ -419,6 +428,8 @@ pub(crate) struct Splits { library: Option, inspector: Option, timeline: Option, + dock: Option, + bench: Option, } impl Splits { @@ -427,6 +438,8 @@ impl Splits { Split::Library => self.library, Split::Inspector => self.inspector, Split::Timeline => self.timeline, + Split::Dock => self.dock, + Split::Bench => self.bench, } } @@ -435,10 +448,54 @@ impl Splits { Split::Library => &mut self.library, Split::Inspector => &mut self.inspector, Split::Timeline => &mut self.timeline, + Split::Dock => &mut self.dock, + Split::Bench => &mut self.bench, } = Some(size); } } +/// Where the darkroom's own two dragged sizes live -- dock and bench, the +/// only pair with a hand on them so far. Same small, silent round trip as +/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves both +/// `None`, which [`split_size`] already reads as "give it the window's own +/// share". +pub(crate) fn stance_splits_config_path() -> std::path::PathBuf { + crate::keymap::Keymap::config_path().with_file_name("stance-splits") +} + +pub(crate) fn load_stance_splits() -> Splits { + let mut splits = Splits::default(); + if let Ok(text) = std::fs::read_to_string(stance_splits_config_path()) { + for line in text.lines() { + let Some((key, value)) = line.split_once('=') else { continue }; + let Ok(px) = value.trim().parse::() else { continue }; + match key { + "dock" => splits.dock = Some(px), + "bench" => splits.bench = Some(px), + _ => {} + } + } + } + splits +} + +/// Writes the two sizes a hand has actually dragged -- the legacy three stay +/// unpersisted, as they already were before this diff (out of its scope). +pub(crate) fn save_stance_splits(splits: &Splits) { + let mut text = String::new(); + if let Some(d) = splits.dock { + text += &format!("dock={d}\n"); + } + if let Some(b) = splits.bench { + text += &format!("bench={b}\n"); + } + let path = stance_splits_config_path(); + if let Some(dir) = path.parent() { + let _ = std::fs::create_dir_all(dir); + } + let _ = std::fs::write(path, text); +} + /// How small a panel may be dragged and how large: the floor is the size it /// still shows something at, the ceiling is what its neighbour needs to stay a /// region rather than a sliver. Neither end is passable -- a panel dragged to @@ -454,6 +511,15 @@ pub(crate) fn split_bounds( match split { Split::Library => (LIBRARY_MIN_W, w * SIDE_MAX_FRAC), Split::Inspector => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC), + // The dock is the darkroom's one side column -- same shape as the + // legacy inspector's, so it takes the legacy inspector's own floor + // and ceiling rather than a second pair that would only ever agree. + Split::Dock => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC), + // The bench is the darkroom's own timeline: [`Split::Timeline`]'s + // ceiling share, and a floor tall enough for a section head and one + // lane row -- `bench_stance::render` draws exactly that pair, and + // nothing shorter leaves the lane a whole row. + Split::Bench => (BENCH_MIN_H, h * TIMELINE_MAX_SHARE), // One whole lane under the chrome, the scrollbar strip's row included // while there is one to draw ([`timeline_fixed_h`]): a timeline // shorter than that is a ruler with nothing beneath it. A second @@ -497,6 +563,8 @@ pub(crate) fn split_size( Split::Library => library_w(w), Split::Inspector => inspector_w(w), Split::Timeline => timeline_h(lanes, scroll).min(h * TIMELINE_SHARE), + Split::Dock => crate::ui::stance::DOCK_W, + Split::Bench => crate::ui::stance::BENCH_H, }; // The floor wins a window too small to honour both ends: a panel at its // floor is still a panel, and `clamp` panics outright on a ceiling under @@ -517,6 +585,11 @@ pub(crate) fn split_drag_size(split: Split, at: Point, window: Size h - y - TOOLBAR_H - SPLIT_W / 2., + // The dock sits on the same right edge the inspector does. + Split::Dock => w - x - SPLIT_W / 2., + // The bench sits above the fixed ledger strip, the bench's own + // reason the timeline's formula reads the toolbar. + Split::Bench => h - y - crate::ui::stance::LEDGER_H - SPLIT_W / 2., } } diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 2feb555..5a24766 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -912,7 +912,7 @@ fn main() { hw_caps: None, clipboard: None, scrubbing: false, - splits: Splits::default(), + splits: load_stance_splits(), split_drag: None, trim: None, fade_drag: None, diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 3d2f2c2..28fd5dc 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1651,6 +1651,13 @@ impl Player { } if let Some(split) = self.split_drag.take() { self.drag_split(split, event.position, window, cx); + // The darkroom's own two seams outlive the window: written once, + // on the release that ends the gesture, the same small-file + // round trip `ui::dock_stance`'s tab pick uses -- not on every + // sample in between, which `drag_move` above never owed a write. + if matches!(split, Split::Dock | Split::Bench) { + save_stance_splits(&self.splits); + } return; } if std::mem::take(&mut self.eq_dragging) { diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 28640da..a23cc88 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1736,6 +1736,61 @@ fn a_dragged_divider_stops_before_either_panel_disappears() { ); } +/// The darkroom's own two seams (`Split::Dock`, `Split::Bench`): a hand may +/// not drag either past its floor or its ceiling, the same promise +/// [`a_dragged_divider_stops_before_either_panel_disappears`] makes for the +/// legacy three. +#[test] +fn the_darkroom_seams_stop_before_either_side_disappears() { + use crate::ui::theme::INSPECTOR_MIN_W; + use crate::{ + BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, split_drag_size, split_size, + }; + use gpui::{point, px, size}; + + let window = size(px(1280.), px(720.)); + // Untouched, each answers its own stance default. + assert_eq!( + split_size(Split::Dock, None, 2, window, false), + crate::ui::stance::DOCK_W + ); + assert_eq!( + split_size(Split::Bench, None, 2, window, false), + crate::ui::stance::BENCH_H + ); + // Dragged, it is what the hand asked for... + assert_eq!(split_size(Split::Dock, Some(400.), 2, window, false), 400.); + assert_eq!(split_size(Split::Bench, Some(300.), 2, window, false), 300.); + // ...and never past the floor... + assert_eq!( + split_size(Split::Dock, Some(0.), 2, window, false), + INSPECTOR_MIN_W + ); + assert_eq!( + split_size(Split::Bench, Some(0.), 2, window, false), + BENCH_MIN_H + ); + // ...nor the ceiling. + assert_eq!( + split_size(Split::Dock, Some(9000.), 2, window, false), + 1280. * SIDE_MAX_FRAC + ); + assert_eq!( + split_size(Split::Bench, Some(9000.), 2, window, false), + 720. * TIMELINE_MAX_SHARE + ); + // The pointer turned into a size, half a strip off for the same reason + // the legacy seams read it that way. + assert_eq!( + split_drag_size(Split::Dock, point(px(1000.), px(400.)), window), + 280. - SPLIT_W / 2. + ); + assert_eq!( + split_drag_size(Split::Bench, point(px(300.), px(500.)), window), + 220. - crate::ui::stance::LEDGER_H - SPLIT_W / 2. + ); +} + /// Every seam in the main layout has a handle on it, and every region draws /// itself at the size that handle sets: a region still measuring itself off the /// window's own share is a panel whose divider moves nothing. @@ -1748,6 +1803,13 @@ fn every_seam_in_the_layout_has_a_divider_on_it() { "{split} has no divider to drag" ); } + let stance = src_text("ui/stance.rs"); + for split in ["Split::Dock", "Split::Bench"] { + assert!( + stance.contains(&format!("divider({split}")), + "{split} has no divider to drag" + ); + } // The strip is drawn wide enough to hit and says which way it moves -- // an invisible hairline is a feature nobody finds. let interact = src_text("interact.rs"); diff --git a/crates/app/src/ui/library.rs b/crates/app/src/ui/library.rs index 8c51a2b..9858e13 100644 --- a/crates/app/src/ui/library.rs +++ b/crates/app/src/ui/library.rs @@ -688,7 +688,7 @@ impl Player { // floor clamp and the room the list sizes against are `menu_floor`'s, // so a menu taller than the footprint scrolls instead of climbing // back over the picture. - let (at, room) = menu_floor(menu.at, viewport, darkroom); + let (at, room) = menu_floor(menu.at, viewport, darkroom, self.split_px(Split::Bench, viewport)); let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); let full: SharedString = path.display().to_string().into(); diff --git a/crates/app/src/ui/overlays.rs b/crates/app/src/ui/overlays.rs index 63ce4f3..1205d89 100644 --- a/crates/app/src/ui/overlays.rs +++ b/crates/app/src/ui/overlays.rs @@ -670,7 +670,7 @@ impl Player { // footprint (`room`), not the whole window, so a menu taller than // the footprint scrolls inside its own plate instead of walking its // clamped top edge back up over the picture ([`menu_floor`]). - let (at, room) = menu_floor(menu.at, viewport, self.darkroom); + let (at, room) = menu_floor(menu.at, viewport, self.darkroom, self.split_px(Split::Bench, viewport)); let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); let full: SharedString = source @@ -832,7 +832,7 @@ impl Player { .collect(); // The window's own room, and the list scrolls only where the window has // none -- the clip menu's rule, one function for both. - let (at, room) = menu_floor(picker.at, viewport, darkroom); + let (at, room) = menu_floor(picker.at, viewport, darkroom, self.split_px(Split::Bench, viewport)); let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); Some( diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 4185f57..3ba638d 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -20,16 +20,19 @@ const SPINE_W: f32 = 56.; /// Fixed strip under the screen: timecode, transport, cut readout, contact /// strip, Export -- all placeholder at this step. const TIME_BAND_H: f32 = 88.; -/// corner-cut: a fixed share of the window rather than one measured against -/// the picture's own room, matching the placeholder every other stance -/// region still carries at this step. Ceiling: fold into the same split the -/// legacy timeline's `Split::Timeline` answers once the stance grows a -/// resizable seam of its own. -const BENCH_H: f32 = 200.; -/// Thin strip at the foot of the centre column. -const LEDGER_H: f32 = 28.; -/// Right side panel, fixed width, carrying the Src/Clip tab pair. -const DOCK_W: f32 = 280.; +/// The bench's untouched height -- [`Split::Bench`]'s own default, read by +/// `layout::split_size` the same way the legacy tree's `library_w`/ +/// `inspector_w` feed `Split::Library`/`Split::Inspector`. A hand on the +/// seam above it overrides this; nothing else does. +pub(crate) const BENCH_H: f32 = 200.; +/// Thin strip at the foot of the centre column. Read by `layout`'s +/// `Split::Bench` drag formula (the seam sits above the fixed ledger, so a +/// drag has to leave room for it) -- kept `pub(crate)` for that one door +/// rather than a second copy of the number. +pub(crate) const LEDGER_H: f32 = 28.; +/// The dock's untouched width -- [`Split::Dock`]'s own default, the same +/// role [`BENCH_H`] plays for the bench. +pub(crate) const DOCK_W: f32 = 280.; /// The lowest a menu's top edge may sit and still land inside the /// bench/ledger/dock footprint below the screen (DESIGN §5, §9, §11 check 6): @@ -37,9 +40,12 @@ const DOCK_W: f32 = 280.; /// the picture just because the pointer is there. `overlays.rs`/`library.rs` /// clamp their `menu.at.y` against this before handing it to `menu_at`, only /// in the darkroom stance -- the legacy tree has no fixed screen/time-band -/// split for this to mean anything against, and must not move. -pub(crate) fn below_picture_floor(viewport_h: f32) -> f32 { - (viewport_h - TIME_BAND_H - BENCH_H - LEDGER_H).max(0.) +/// split for this to mean anything against, and must not move. `bench_h` is +/// the live, possibly hand-dragged `Split::Bench` height (`Player::split_px`) +/// rather than the fixed [`BENCH_H`] default, so a widened bench clamps the +/// menu against the room actually left, not the room it started with. +pub(crate) fn below_picture_floor(viewport_h: f32, bench_h: f32) -> f32 { + (viewport_h - TIME_BAND_H - bench_h - LEDGER_H).max(0.) } /// The floor-clamped placement for every scrolling menu (clip context menu, @@ -59,11 +65,12 @@ pub(crate) fn menu_floor( at: Point, viewport: Size, darkroom: bool, + bench_h: f32, ) -> (Point, Size) { if !darkroom { return (at, viewport); } - let floor = below_picture_floor(f32::from(viewport.height)); + let floor = below_picture_floor(f32::from(viewport.height), bench_h); let at = point(at.x, px(f32::from(at.y).max(floor))); let room = size(viewport.width, px(f32::from(viewport.height) - floor)); (at, room) @@ -83,8 +90,8 @@ mod menu_floor_tests { #[test] fn a_menu_taller_than_the_footprint_stays_pinned_to_the_floor_not_walked_back_over_it() { let viewport = size(px(1280.), px(720.)); - let floor = below_picture_floor(f32::from(viewport.height)); - let (at, room) = menu_floor(point(px(300.), px(20.)), viewport, true); + let floor = below_picture_floor(f32::from(viewport.height), BENCH_H); + let (at, room) = menu_floor(point(px(300.), px(20.)), viewport, true, BENCH_H); assert_eq!(f32::from(at.y), floor); // 396px of rows (the charter's measured menu height) does not fit in // the 316px footprint room, so it must be capped to it, not the @@ -425,11 +432,14 @@ fn time_band(player: &mut Player, position: f64, cx: &mut Context) -> im /// Lanes, under the time band. `canvas` is the bench background too (DESIGN /// §2's token table), so it shares its surface with the screen above it. -fn bench(player: &mut Player, cx: &mut Context) -> impl IntoElement { +/// Height comes from [`Player::split_px`] now, not the fixed [`BENCH_H`]: +/// the seam [`crate::ui::stance::render`] mounts above this region is what +/// answers "ui fields are not stretchable" for the bench. +fn bench(player: &mut Player, bench_h: f32, cx: &mut Context) -> impl IntoElement { div() .id("stance-bench") .flex_none() - .h(px(BENCH_H)) + .h(px(bench_h)) // §4: lanes take 0 radius. .rounded(px(0.)) .bg(rgb(DARK_CANVAS())) @@ -440,7 +450,7 @@ fn bench(player: &mut Player, cx: &mut Context) -> impl IntoElement { .px(px(12.)) .py(px(4.)) .child(section_head("bench")) - .child(bench_stance::render(player, BENCH_H - 20., cx)) + .child(bench_stance::render(player, bench_h - 20., cx)) } /// Which of the three §8 severities a notice's own words carry. Reuses @@ -567,18 +577,21 @@ fn ledger(player: &Player, position: f64) -> impl IntoElement { /// The dock: the only side panel, right, fixed width, carrying the Src/Clip /// tab pair (DESIGN §5). The frame is drawn here; `dock_stance.rs` owns the /// tab row and both tabs' content (DESIGN §12 step 4). -fn dock(player: &Player, window_h: Pixels, cx: &mut Context) -> impl IntoElement { +/// Width comes from [`Player::split_px`] now, not the fixed [`DOCK_W`]: the +/// seam [`crate::ui::stance::render`] mounts to its left is what answers +/// "ui fields are not stretchable" for the dock. +fn dock(player: &Player, dock_w: f32, window_h: Pixels, cx: &mut Context) -> impl IntoElement { div() .id("stance-dock") .flex_none() - .w(px(DOCK_W)) + .w(px(dock_w)) .h_full() .bg(rgb(DARK_PANEL())) .border_l_1() .border_color(rgba(DARK_SEAM())) .flex() .flex_col() - .child(dock_stance::render(player, DOCK_W, window_h, cx)) + .child(dock_stance::render(player, dock_w, window_h, cx)) } /// The whole stance: spine, screen, time band, bench, ledger, dock, in the @@ -593,6 +606,12 @@ pub(crate) fn render( let window_size = window.viewport_size(); let window_h = window_size.height; let position = player.playhead(player.drawn_duration()); + // The two seams a hand may drag (`Split::Dock`, `Split::Bench`): read + // through the same door every legacy region measures itself by + // ([`Player::split_px`]), so a dragged size and a drawn one cannot + // disagree here either. + let dock_w = player.split_px(Split::Dock, window_size); + let bench_h = player.split_px(Split::Bench, window_size); div() .id("stance-room") .track_focus(&player.focus) @@ -739,6 +758,12 @@ pub(crate) fn render( cx.notify(); } })) + // The seam drag is tracked on the root, same reason the legacy + // ruler-scrub is (render.rs): the pointer outruns the 6px divider + // hitbox on the first move, so only the whole-window root keeps + // hearing it once a `Split::Dock`/`Split::Bench` drag has started. + .on_mouse_move(cx.listener(Player::drag_move)) + .on_mouse_up(MouseButton::Left, cx.listener(Player::drag_release)) .size_full() .flex() .bg(rgb(DARK_CANVAS())) @@ -753,7 +778,8 @@ pub(crate) fn render( .flex_col() .child(screen(player, position, window, cx)) .child(time_band(player, position, cx)) - .child(bench(player, cx)) + .child(divider(Split::Bench, cx)) + .child(bench(player, bench_h, cx)) .child(ledger(player, position)) .when_some(player.notices.front().cloned(), |el, n| { el.child(notice_plate(n)) @@ -780,5 +806,6 @@ pub(crate) fn render( .children(player.export_progress_card(cx)) .children(player.picker_card(window_size, cx)), ) - .child(dock(player, window_h, cx)) + .child(divider(Split::Dock, cx)) + .child(dock(player, dock_w, window_h, cx)) }