Seams clamp before they persist, and survive a release outside the window
Browse files at this commit4e57e1ca59066b4c1b2317e25e663a5a97cdbf0eParent: 5480ccb- fix
- seams clamp before they persist, and survive a release outside the window
4 changed files +125 -35
- crates/app/src/layout.rs +60 -24
- crates/app/src/player/timeline_edit.rs +24 -4
- crates/app/src/tests/layout.rs +37 -5
- crates/app/src/ui/stance.rs +4 -2
crates/app/src/layout.rsmodified+60 -24
| @@ -396,6 +396,25 @@ pub(crate) enum Split { | ||
| 396 | 396 | Bench, |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | +impl Split { | |
| 400 | + /// The two persisted seams -- library/inspector/timeline stay | |
| 401 | + /// unpersisted, out of this diff's scope, same as before it. Read by | |
| 402 | + /// [`load_stance_splits`] and [`save_stance_splits`] together so the | |
| 403 | + /// two can never learn a different set of keys from each other, the | |
| 404 | + /// gap a sixth region would otherwise fall through silently. | |
| 405 | + const PERSISTED: [Split; 2] = [Split::Dock, Split::Bench]; | |
| 406 | + | |
| 407 | + fn key(self) -> &'static str { | |
| 408 | + match self { | |
| 409 | + Split::Library => "library", | |
| 410 | + Split::Inspector => "inspector", | |
| 411 | + Split::Timeline => "timeline", | |
| 412 | + Split::Dock => "dock", | |
| 413 | + Split::Bench => "bench", | |
| 414 | + } | |
| 415 | + } | |
| 416 | +} | |
| 417 | + | |
| 399 | 418 | /// How wide a divider is drawn *and* hit. Wider than the 1 px stroke it stands |
| 400 | 419 | /// in for: a seam nobody can put a pointer on is a seam nobody can drag, which |
| 401 | 420 | /// is why every editor that ships this draws a strip rather than the hairline |
| @@ -413,10 +432,11 @@ pub(crate) const SIDE_MAX_FRAC: f32 = 1. / 3.; | ||
| 413 | 432 | /// timeline is asking on purpose, and the picture still keeps most of a third. |
| 414 | 433 | pub(crate) const TIMELINE_MAX_SHARE: f32 = 0.7; |
| 415 | 434 | |
| 416 | -/// The least the darkroom's bench may be dragged to: a section head and one | |
| 417 | -/// [`LANE_H`] row -- [`bench_stance::render`]'s own floor, read here rather | |
| 418 | -/// than duplicated so the seam and the region it drags never disagree. | |
| 419 | -pub(crate) const BENCH_MIN_H: f32 = 20. + LANE_H; | |
| 435 | +/// The least the darkroom's bench may be dragged to: driven and measured | |
| 436 | +/// against a real project -- below this the V1 lane's own chip clips and | |
| 437 | +/// the A1 lane drops off the bench entirely, which a floor exists to make | |
| 438 | +/// unreachable. | |
| 439 | +pub(crate) const BENCH_MIN_H: f32 = 80.; | |
| 420 | 440 | |
| 421 | 441 | /// What a hand has done to the three seams: the size it dragged each panel to, |
| 422 | 442 | /// or `None` where nobody has touched one and the window's own share still |
| @@ -464,32 +484,40 @@ pub(crate) fn stance_splits_config_path() -> std::path::PathBuf { | ||
| 464 | 484 | } |
| 465 | 485 | |
| 466 | 486 | pub(crate) fn load_stance_splits() -> Splits { |
| 487 | + load_stance_splits_from(&stance_splits_config_path()) | |
| 488 | +} | |
| 489 | + | |
| 490 | +/// One `split=pixels` line per touched seam, read from `path` -- factored out | |
| 491 | +/// of [`load_stance_splits`] so a test can round-trip a scratch file instead | |
| 492 | +/// of the real config. | |
| 493 | +pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits { | |
| 467 | 494 | let mut splits = Splits::default(); |
| 468 | - if let Ok(text) = std::fs::read_to_string(stance_splits_config_path()) { | |
| 495 | + if let Ok(text) = std::fs::read_to_string(path) { | |
| 469 | 496 | for line in text.lines() { |
| 470 | 497 | let Some((key, value)) = line.split_once('=') else { continue }; |
| 471 | 498 | let Ok(px) = value.trim().parse::<f32>() else { continue }; |
| 472 | - match key { | |
| 473 | - "dock" => splits.dock = Some(px), | |
| 474 | - "bench" => splits.bench = Some(px), | |
| 475 | - _ => {} | |
| 476 | - } | |
| 499 | + let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else { | |
| 500 | + continue; | |
| 501 | + }; | |
| 502 | + splits.set(split, px); | |
| 477 | 503 | } |
| 478 | 504 | } |
| 479 | 505 | splits |
| 480 | 506 | } |
| 481 | 507 | |
| 482 | -/// Writes the two sizes a hand has actually dragged -- the legacy three stay | |
| 508 | +/// Writes the sizes a hand has actually dragged -- the legacy three stay | |
| 483 | 509 | /// unpersisted, as they already were before this diff (out of its scope). |
| 510 | +/// Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field, | |
| 511 | +/// so a region added there needs no second, separately-maintained list here. | |
| 484 | 512 | pub(crate) fn save_stance_splits(splits: &Splits) { |
| 485 | - let mut text = String::new(); | |
| 486 | - if let Some(d) = splits.dock { | |
| 487 | - text += &format!("dock={d}\n"); | |
| 488 | - } | |
| 489 | - if let Some(b) = splits.bench { | |
| 490 | - text += &format!("bench={b}\n"); | |
| 491 | - } | |
| 492 | - let path = stance_splits_config_path(); | |
| 513 | + save_stance_splits_to(splits, &stance_splits_config_path()); | |
| 514 | +} | |
| 515 | + | |
| 516 | +pub(crate) fn save_stance_splits_to(splits: &Splits, path: &std::path::Path) { | |
| 517 | + let text: String = Split::PERSISTED | |
| 518 | + .into_iter() | |
| 519 | + .filter_map(|split| splits.get(split).map(|px| format!("{}={px}\n", split.key()))) | |
| 520 | + .collect(); | |
| 493 | 521 | if let Some(dir) = path.parent() { |
| 494 | 522 | let _ = std::fs::create_dir_all(dir); |
| 495 | 523 | } |
| @@ -515,11 +543,19 @@ pub(crate) fn split_bounds( | ||
| 515 | 543 | // legacy inspector's, so it takes the legacy inspector's own floor |
| 516 | 544 | // and ceiling rather than a second pair that would only ever agree. |
| 517 | 545 | Split::Dock => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC), |
| 518 | - // The bench is the darkroom's own timeline: [`Split::Timeline`]'s | |
| 519 | - // ceiling share, and a floor tall enough for a section head and one | |
| 520 | - // lane row -- `bench_stance::render` draws exactly that pair, and | |
| 521 | - // nothing shorter leaves the lane a whole row. | |
| 522 | - Split::Bench => (BENCH_MIN_H, h * TIMELINE_MAX_SHARE), | |
| 546 | + // The bench is the darkroom's own timeline, but its ceiling is not | |
| 547 | + // [`Split::Timeline`]'s window-share one: a bench that swallows | |
| 548 | + // `TIMELINE_MAX_SHARE` of a 720p window leaves the screen and its | |
| 549 | + // scale plate only 100px, which is not a picture any more. The | |
| 550 | + // ceiling instead leaves the screen and time band their own fixed | |
| 551 | + // 160px -- room for the scale plate, the picture and a sliver of | |
| 552 | + // letterbox -- and `BENCH_MIN_H` still wins the clamp on anything | |
| 553 | + // shorter than that. | |
| 554 | + Split::Bench => ( | |
| 555 | + BENCH_MIN_H, | |
| 556 | + (h - crate::ui::stance::TIME_BAND_H - crate::ui::stance::LEDGER_H - 160.) | |
| 557 | + .max(BENCH_MIN_H), | |
| 558 | + ), | |
| 523 | 559 | // One whole lane under the chrome, the scrollbar strip's row included |
| 524 | 560 | // while there is one to draw ([`timeline_fixed_h`]): a timeline |
| 525 | 561 | // shorter than that is a ruler with nothing beneath it. A second |
crates/app/src/player/timeline_edit.rsmodified+24 -4
| @@ -1518,9 +1518,16 @@ impl Player { | ||
| 1518 | 1518 | match event.pressed_button { |
| 1519 | 1519 | Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx), |
| 1520 | 1520 | // Released outside the window: the up below never came, so this |
| 1521 | - // is where the gesture ends. Nothing is owed -- every move has | |
| 1522 | - // already been written. | |
| 1523 | - _ => self.split_drag = None, | |
| 1521 | + // is where the gesture ends. The size is already written to | |
| 1522 | + // `self.splits`, but the darkroom's two persisted seams still | |
| 1523 | + // owe the save `drag_release` would have paid -- without it | |
| 1524 | + // the drag holds for the session and reverts on restart. | |
| 1525 | + _ => { | |
| 1526 | + self.split_drag = None; | |
| 1527 | + if matches!(split, Split::Dock | Split::Bench) { | |
| 1528 | + save_stance_splits(&self.splits); | |
| 1529 | + } | |
| 1530 | + } | |
| 1524 | 1531 | } |
| 1525 | 1532 | return; |
| 1526 | 1533 | } |
| @@ -1725,8 +1732,21 @@ impl Player { | ||
| 1725 | 1732 | window: &mut Window, |
| 1726 | 1733 | cx: &mut Context<Self>, |
| 1727 | 1734 | ) { |
| 1735 | + let viewport = window.viewport_size(); | |
| 1736 | + let raw = split_drag_size(split, at, viewport); | |
| 1737 | + // Clamped here, through the same door [`Player::split_px`] draws | |
| 1738 | + // through, at the one place a hand's pick ever reaches | |
| 1739 | + // `self.splits` -- so what a later save writes to disk is never a | |
| 1740 | + // number the seam itself would have refused to draw at. A floor | |
| 1741 | + // enforced only on read still leaves a `bench=-1` line in the file. | |
| 1742 | + let lanes = self | |
| 1743 | + .session | |
| 1744 | + .as_ref() | |
| 1745 | + .map_or(2, |session| session.lanes().len()); | |
| 1746 | + let view = self.view(); | |
| 1747 | + let scroll = view.duration > view.span(); | |
| 1728 | 1748 | self.splits |
| 1729 | - .set(split, split_drag_size(split, at, window.viewport_size())); | |
| 1749 | + .set(split, split_size(split, Some(raw), lanes, viewport, scroll)); | |
| 1730 | 1750 | cx.notify(); |
| 1731 | 1751 | } |
| 1732 | 1752 | } |
crates/app/src/tests/layout.rsmodified+37 -5
| @@ -1743,9 +1743,7 @@ fn a_dragged_divider_stops_before_either_panel_disappears() { | ||
| 1743 | 1743 | #[test] |
| 1744 | 1744 | fn the_darkroom_seams_stop_before_either_side_disappears() { |
| 1745 | 1745 | use crate::ui::theme::INSPECTOR_MIN_W; |
| 1746 | - use crate::{ | |
| 1747 | - BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, split_drag_size, split_size, | |
| 1748 | - }; | |
| 1746 | + use crate::{BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, split_bounds, split_drag_size, split_size}; | |
| 1749 | 1747 | use gpui::{point, px, size}; |
| 1750 | 1748 | |
| 1751 | 1749 | let window = size(px(1280.), px(720.)); |
| @@ -1770,15 +1768,18 @@ fn the_darkroom_seams_stop_before_either_side_disappears() { | ||
| 1770 | 1768 | split_size(Split::Bench, Some(0.), 2, window, false), |
| 1771 | 1769 | BENCH_MIN_H |
| 1772 | 1770 | ); |
| 1773 | - // ...nor the ceiling. | |
| 1771 | + // ...nor the ceiling. The bench's is not a window-share one -- it leaves | |
| 1772 | + // the screen and time band a fixed 160px, [`split_bounds`]'s own reason. | |
| 1774 | 1773 | assert_eq!( |
| 1775 | 1774 | split_size(Split::Dock, Some(9000.), 2, window, false), |
| 1776 | 1775 | 1280. * SIDE_MAX_FRAC |
| 1777 | 1776 | ); |
| 1777 | + let (_, bench_max) = split_bounds(Split::Bench, 2, window, false); | |
| 1778 | 1778 | assert_eq!( |
| 1779 | 1779 | split_size(Split::Bench, Some(9000.), 2, window, false), |
| 1780 | - 720. * TIMELINE_MAX_SHARE | |
| 1780 | + bench_max | |
| 1781 | 1781 | ); |
| 1782 | + assert!(bench_max < 720.); | |
| 1782 | 1783 | // The pointer turned into a size, half a strip off for the same reason |
| 1783 | 1784 | // the legacy seams read it that way. |
| 1784 | 1785 | assert_eq!( |
| @@ -1791,6 +1792,37 @@ fn the_darkroom_seams_stop_before_either_side_disappears() { | ||
| 1791 | 1792 | ); |
| 1792 | 1793 | } |
| 1793 | 1794 | |
| 1795 | +/// A round trip through the file: what is saved is what the next load reads | |
| 1796 | +/// back, one seam touched and the other left at its default -- a scratch | |
| 1797 | +/// path, not the real config, the same isolation `keymap::tests`' own | |
| 1798 | +/// `load_from`/`save_to` already takes. | |
| 1799 | +#[test] | |
| 1800 | +fn a_saved_seam_survives_a_reload() { | |
| 1801 | + use crate::{Split, Splits, load_stance_splits_from, save_stance_splits_to}; | |
| 1802 | + | |
| 1803 | + let dir = engine::scratch::Scratch::dir("edith-stance-splits"); | |
| 1804 | + let path = dir.join("stance-splits"); | |
| 1805 | + | |
| 1806 | + let mut splits = Splits::default(); | |
| 1807 | + splits.set(Split::Dock, 333.); | |
| 1808 | + save_stance_splits_to(&splits, &path); | |
| 1809 | + let loaded = load_stance_splits_from(&path); | |
| 1810 | + assert_eq!(loaded.get(Split::Dock), Some(333.)); | |
| 1811 | + assert_eq!(loaded.get(Split::Bench), None); | |
| 1812 | +} | |
| 1813 | + | |
| 1814 | +/// A missing file leaves every region at its default -- the silent fallback | |
| 1815 | +/// `load_stance_splits`'s doc comment promises. | |
| 1816 | +#[test] | |
| 1817 | +fn a_missing_stance_splits_file_leaves_every_region_at_its_default() { | |
| 1818 | + use crate::{Split, load_stance_splits_from}; | |
| 1819 | + | |
| 1820 | + let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing"); | |
| 1821 | + let splits = load_stance_splits_from(&dir.join("nothing-here")); | |
| 1822 | + assert_eq!(splits.get(Split::Dock), None); | |
| 1823 | + assert_eq!(splits.get(Split::Bench), None); | |
| 1824 | +} | |
| 1825 | + | |
| 1794 | 1826 | /// Every seam in the main layout has a handle on it, and every region draws |
| 1795 | 1827 | /// itself at the size that handle sets: a region still measuring itself off the |
| 1796 | 1828 | /// window's own share is a panel whose divider moves nothing. |
crates/app/src/ui/stance.rsmodified+4 -2
| @@ -18,8 +18,10 @@ use crate::ui::type_scale::{self, Typeset}; | ||
| 18 | 18 | /// Left rail, full height (DESIGN §5). |
| 19 | 19 | const SPINE_W: f32 = 56.; |
| 20 | 20 | /// Fixed strip under the screen: timecode, transport, cut readout, contact |
| 21 | -/// strip, Export -- all placeholder at this step. | |
| 22 | -const TIME_BAND_H: f32 = 88.; | |
| 21 | +/// strip, Export -- all placeholder at this step. Kept `pub(crate)` for | |
| 22 | +/// `layout::split_bounds`'s bench ceiling, the same one-door reason | |
| 23 | +/// [`LEDGER_H`] already is. | |
| 24 | +pub(crate) const TIME_BAND_H: f32 = 88.; | |
| 23 | 25 | /// The bench's untouched height -- [`Split::Bench`]'s own default, read by |
| 24 | 26 | /// `layout::split_size` the same way the legacy tree's `library_w`/ |
| 25 | 27 | /// `inspector_w` feed `Split::Library`/`Split::Inspector`. A hand on the |