forge
Explore
Log in

Don't you dare go Hollow

All five panel seams persist, clamped to the window at load

Browse files at this commit

6fef2f2b736c0305500272263328cb7c8a9a21b5Ahmet Kaan GümüşParent: 7867c90d35aa29
  • feat
    • all five panel seams persist, clamped to the window at load
Show full message
✨ feat(layout): all five panel seams persist, clamped to the window at load
crates/app/src/layout.rsmodified+34 -16
@@ -398,12 +398,19 @@ pub(crate) enum Split {
398398 }
399399
400400 impl Split {
401- /// The two persisted seams -- library/inspector/timeline stay
402- /// unpersisted, out of this diff's scope, same as before it. Read by
403- /// [`load_stance_splits`] and [`save_stance_splits`] together so the
404- /// two can never learn a different set of keys from each other, the
405- /// gap a sixth region would otherwise fall through silently.
406- const PERSISTED: [Split; 2] = [Split::Dock, Split::Bench];
401+ /// Every seam that survives a restart -- all five regions, the file
402+ /// itself the only store (view state stays out of `.edith`, the
403+ /// settled convention). Read by [`load_stance_splits`] and
404+ /// [`save_stance_splits`] together so the set can never learn a
405+ /// different set of keys from each other, the gap a sixth region
406+ /// would otherwise fall through silently.
407+ pub(crate) const PERSISTED: [Split; 5] = [
408+ Split::Library,
409+ Split::Inspector,
410+ Split::Timeline,
411+ Split::Dock,
412+ Split::Bench,
413+ ];
407414
408415 fn key(self) -> &'static str {
409416 match self {
@@ -518,23 +525,30 @@ impl Splits {
518525 }
519526 }
520527
521-/// Where the darkroom's own two dragged sizes live -- dock and bench, the
522-/// only pair with a hand on them so far. Same small, silent round trip as
523-/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves both
528+/// Where every seam's dragged size lives. Same small, silent round trip as
529+/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves a seam
524530 /// `None`, which [`split_size`] already reads as "give it the window's own
525531 /// share".
526532 pub(crate) fn stance_splits_config_path() -> std::path::PathBuf {
527533 crate::keymap::Keymap::config_path().with_file_name("stance-splits")
528534 }
529535
530-pub(crate) fn load_stance_splits() -> Splits {
531- load_stance_splits_from(&stance_splits_config_path())
536+pub(crate) fn load_stance_splits(window: Size<Pixels>) -> Splits {
537+ load_stance_splits_from(&stance_splits_config_path(), window)
532538 }
533539
534540 /// One `split=pixels` line per touched seam, read from `path` -- factored out
535541 /// of [`load_stance_splits`] so a test can round-trip a scratch file instead
536-/// of the real config.
537-pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits {
542+/// of the real config. `window` is the size the layout is about to be drawn
543+/// at -- a file written by a wider or taller window can hold a seam past
544+/// this one's own ceiling, so each value is clamped to it here, before it
545+/// ever reaches [`Splits`]. [`split_size`] still re-clamps every frame on
546+/// top of this, but that clamp needs a lane count and a scroll state
547+/// nothing here has yet; this one runs on the three bounds that do not --
548+/// [`SIDE_MAX_FRAC`], [`TIMELINE_MAX_SHARE`] and [`BENCH_MIN_H`] -- so a
549+/// value this open never reaches even the first frame.
550+pub(crate) fn load_stance_splits_from(path: &std::path::Path, window: Size<Pixels>) -> Splits {
551+ let (w, h) = (f32::from(window.width), f32::from(window.height));
538552 let mut splits = Splits::default();
539553 if let Ok(text) = std::fs::read_to_string(path) {
540554 for line in text.lines() {
@@ -547,15 +561,19 @@ pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits {
547561 let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else {
548562 continue;
549563 };
564+ let px = match split {
565+ Split::Library | Split::Inspector | Split::Dock => px.min(w * SIDE_MAX_FRAC),
566+ Split::Timeline => px.min(h * TIMELINE_MAX_SHARE),
567+ Split::Bench => px.max(BENCH_MIN_H),
568+ };
550569 splits.set(split, px);
551570 }
552571 }
553572 splits
554573 }
555574
556-/// Writes the sizes a hand has actually dragged -- the legacy three stay
557-/// unpersisted, as they already were before this diff (out of its scope).
558-/// Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field,
575+/// Writes the sizes a hand has actually dragged, one line per seam a hand
576+/// has touched. Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field,
559577 /// so a region added there needs no second, separately-maintained list here.
560578 pub(crate) fn save_stance_splits(splits: &Splits) {
561579 save_stance_splits_to(splits, &stance_splits_config_path());
crates/app/src/main.rsmodified+1 -1
@@ -931,7 +931,7 @@ fn main() {
931931 hw_caps: None,
932932 clipboard: None,
933933 scrubbing: false,
934- splits: load_stance_splits(),
934+ splits: load_stance_splits(bounds.size),
935935 split_drag: None,
936936 trim: None,
937937 fade_drag: None,
crates/app/src/player/timeline_edit.rsmodified+8 -8
@@ -12,7 +12,7 @@ use crate::*;
1212 /// from a live `MouseExitEvent` still cannot be, and is proven by driving
1313 /// instead.
1414 pub(crate) fn split_drag_owes_save(split: Option<Split>) -> bool {
15- matches!(split, Some(Split::Dock) | Some(Split::Bench))
15+ split.is_some_and(|split| Split::PERSISTED.contains(&split))
1616 }
1717
1818 impl Player {
@@ -1750,9 +1750,9 @@ impl Player {
17501750 Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx),
17511751 // Released outside the window: the up below never came, so this
17521752 // is where the gesture ends. The size is already written to
1753- // `self.splits`, but the darkroom's two persisted seams still
1754- // owe the save `drag_release` would have paid -- without it
1755- // the drag holds for the session and reverts on restart.
1753+ // `self.splits`, but a persisted seam still owes the save
1754+ // `drag_release` would have paid -- without it the drag
1755+ // holds for the session and reverts on restart.
17561756 _ => {
17571757 self.split_drag = None;
17581758 if split_drag_owes_save(Some(split)) {
@@ -1889,10 +1889,10 @@ impl Player {
18891889 }
18901890 if let Some(split) = self.split_drag.take() {
18911891 self.drag_split(split, event.position, window, cx);
1892- // The darkroom's own two seams outlive the window: written once,
1893- // on the release that ends the gesture, the same small-file
1894- // round trip `ui::dock_stance`'s tab pick uses -- not on every
1895- // sample in between, which `drag_move` above never owed a write.
1892+ // Every seam outlives the window: written once, on the release
1893+ // that ends the gesture, the same small-file round trip
1894+ // `ui::dock_stance`'s tab pick uses -- not on every sample in
1895+ // between, which `drag_move` above never owed a write.
18961896 if split_drag_owes_save(Some(split)) {
18971897 save_stance_splits(&self.splits);
18981898 }
crates/app/src/tests/layout.rsmodified+43 -12
@@ -2135,22 +2135,48 @@ fn the_notice_plate_declares_a_bounded_wrapping_text_layout() {
21352135 }
21362136
21372137 /// A round trip through the file: what is saved is what the next load reads
2138-/// back, one seam touched and the other left at its default -- a scratch
2139-/// path, not the real config, the same isolation `keymap::tests`' own
2140-/// `load_from`/`save_to` already takes.
2138+/// back, all five seams touched -- a scratch path, not the real config, the
2139+/// same isolation `keymap::tests`' own `load_from`/`save_to` already takes.
2140+/// One of the five is written past its own ceiling (the library, past
2141+/// `SIDE_MAX_FRAC` of the window it is loaded back into): a file written at
2142+/// a wider window must not hand a narrower one an illegal layout, so the
2143+/// load clamps it back down rather than reading it verbatim.
21412144 #[test]
21422145 fn a_saved_seam_survives_a_reload() {
2143- use crate::{Split, Splits, load_stance_splits_from, save_stance_splits_to};
2146+ use crate::{
2147+ BENCH_MIN_H, SIDE_MAX_FRAC, Split, Splits, load_stance_splits_from, save_stance_splits_to,
2148+ };
2149+ use gpui::{Pixels, Size, px, size};
21442150
21452151 let dir = engine::scratch::Scratch::dir("edith-stance-splits");
21462152 let path = dir.join("stance-splits");
2153+ let window: Size<Pixels> = size(px(1280.), px(720.));
21472154
21482155 let mut splits = Splits::default();
2156+ splits.set(Split::Library, 9000.);
2157+ splits.set(Split::Inspector, 200.);
2158+ splits.set(Split::Timeline, 250.);
21492159 splits.set(Split::Dock, 333.);
2160+ splits.set(Split::Bench, 200.);
21502161 save_stance_splits_to(&splits, &path);
2151- let loaded = load_stance_splits_from(&path);
2162+ let loaded = load_stance_splits_from(&path, window);
2163+ assert_eq!(
2164+ loaded.get(Split::Library),
2165+ Some(1280. * SIDE_MAX_FRAC),
2166+ "a library past its own ceiling should clamp to it on load"
2167+ );
2168+ assert_eq!(loaded.get(Split::Inspector), Some(200.));
2169+ assert_eq!(loaded.get(Split::Timeline), Some(250.));
21522170 assert_eq!(loaded.get(Split::Dock), Some(333.));
2153- assert_eq!(loaded.get(Split::Bench), None);
2171+ assert_eq!(loaded.get(Split::Bench), Some(200.));
2172+
2173+ // A bench saved below its own floor clamps up to it, the same ceiling
2174+ // logic mirrored on the one seam whose bound is a minimum.
2175+ let mut low_bench = Splits::default();
2176+ low_bench.set(Split::Bench, 1.);
2177+ save_stance_splits_to(&low_bench, &path);
2178+ let loaded = load_stance_splits_from(&path, window);
2179+ assert_eq!(loaded.get(Split::Bench), Some(BENCH_MIN_H));
21542180 }
21552181
21562182 /// The guard [`crate::split_drag_owes_save`] runs at the moment a drag ends
@@ -2158,18 +2184,18 @@ fn a_saved_seam_survives_a_reload() {
21582184 /// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary
21592185 /// cannot raise -- see `tests/media.rs`'s own note on the same limit, and
21602186 /// the harness drive `D2` in this session's report for the wiring itself).
2161-/// What *is* checkable here without a window: exactly the two persisted
2187+/// What *is* checkable here without a window: exactly the persisted
21622188 /// seams owe that save, the same set `Split::PERSISTED` already names, and a
21632189 /// drag that never started (`None`) owes nothing.
21642190 #[test]
2165-fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() {
2191+fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() {
21662192 use crate::{Split, player::timeline_edit::split_drag_owes_save};
21672193
21682194 assert!(split_drag_owes_save(Some(Split::Dock)));
21692195 assert!(split_drag_owes_save(Some(Split::Bench)));
2170- assert!(!split_drag_owes_save(Some(Split::Library)));
2171- assert!(!split_drag_owes_save(Some(Split::Inspector)));
2172- assert!(!split_drag_owes_save(Some(Split::Timeline)));
2196+ assert!(split_drag_owes_save(Some(Split::Library)));
2197+ assert!(split_drag_owes_save(Some(Split::Inspector)));
2198+ assert!(split_drag_owes_save(Some(Split::Timeline)));
21732199 assert!(!split_drag_owes_save(None));
21742200 }
21752201
@@ -2178,9 +2204,14 @@ fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() {
21782204 #[test]
21792205 fn a_missing_stance_splits_file_leaves_every_region_at_its_default() {
21802206 use crate::{Split, load_stance_splits_from};
2207+ use gpui::{Pixels, Size, px, size};
21812208
21822209 let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing");
2183- let splits = load_stance_splits_from(&dir.join("nothing-here"));
2210+ let window: Size<Pixels> = size(px(1280.), px(720.));
2211+ let splits = load_stance_splits_from(&dir.join("nothing-here"), window);
2212+ assert_eq!(splits.get(Split::Library), None);
2213+ assert_eq!(splits.get(Split::Inspector), None);
2214+ assert_eq!(splits.get(Split::Timeline), None);
21842215 assert_eq!(splits.get(Split::Dock), None);
21852216 assert_eq!(splits.get(Split::Bench), None);
21862217 }