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 {
398 }398 }
399 399
400 impl Split {400 impl Split {
401- /// The two persisted seams -- library/inspector/timeline stay401+ /// Every seam that survives a restart -- all five regions, the file
402- /// unpersisted, out of this diff's scope, same as before it. Read by402+ /// itself the only store (view state stays out of `.edith`, the
403- /// [`load_stance_splits`] and [`save_stance_splits`] together so the403+ /// settled convention). Read by [`load_stance_splits`] and
404- /// two can never learn a different set of keys from each other, the404+ /// [`save_stance_splits`] together so the set can never learn a
405- /// gap a sixth region would otherwise fall through silently.405+ /// different set of keys from each other, the gap a sixth region
406- const PERSISTED: [Split; 2] = [Split::Dock, Split::Bench];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+ ];
407 414
408 fn key(self) -> &'static str {415 fn key(self) -> &'static str {
409 match self {416 match self {
@@ -518,23 +525,30 @@ impl Splits {
518 }525 }
519 }526 }
520 527
521-/// Where the darkroom's own two dragged sizes live -- dock and bench, the528+/// Where every seam's dragged size lives. Same small, silent round trip as
522-/// only pair with a hand on them so far. Same small, silent round trip as529+/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves a seam
523-/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves both
524 /// `None`, which [`split_size`] already reads as "give it the window's own530 /// `None`, which [`split_size`] already reads as "give it the window's own
525 /// share".531 /// share".
526 pub(crate) fn stance_splits_config_path() -> std::path::PathBuf {532 pub(crate) fn stance_splits_config_path() -> std::path::PathBuf {
527 crate::keymap::Keymap::config_path().with_file_name("stance-splits")533 crate::keymap::Keymap::config_path().with_file_name("stance-splits")
528 }534 }
529 535
530-pub(crate) fn load_stance_splits() -> Splits {536+pub(crate) fn load_stance_splits(window: Size<Pixels>) -> Splits {
531- load_stance_splits_from(&stance_splits_config_path())537+ load_stance_splits_from(&stance_splits_config_path(), window)
532 }538 }
533 539
534 /// One `split=pixels` line per touched seam, read from `path` -- factored out540 /// One `split=pixels` line per touched seam, read from `path` -- factored out
535 /// of [`load_stance_splits`] so a test can round-trip a scratch file instead541 /// of [`load_stance_splits`] so a test can round-trip a scratch file instead
536-/// of the real config.542+/// of the real config. `window` is the size the layout is about to be drawn
537-pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits {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));
538 let mut splits = Splits::default();552 let mut splits = Splits::default();
539 if let Ok(text) = std::fs::read_to_string(path) {553 if let Ok(text) = std::fs::read_to_string(path) {
540 for line in text.lines() {554 for line in text.lines() {
@@ -547,15 +561,19 @@ pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits {
547 let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else {561 let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else {
548 continue;562 continue;
549 };563 };
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+ };
550 splits.set(split, px);569 splits.set(split, px);
551 }570 }
552 }571 }
553 splits572 splits
554 }573 }
555 574
556-/// Writes the sizes a hand has actually dragged -- the legacy three stay575+/// Writes the sizes a hand has actually dragged, one line per seam a hand
557-/// unpersisted, as they already were before this diff (out of its scope).576+/// has touched. Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field,
558-/// Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field,
559 /// so a region added there needs no second, separately-maintained list here.577 /// so a region added there needs no second, separately-maintained list here.
560 pub(crate) fn save_stance_splits(splits: &Splits) {578 pub(crate) fn save_stance_splits(splits: &Splits) {
561 save_stance_splits_to(splits, &stance_splits_config_path());579 save_stance_splits_to(splits, &stance_splits_config_path());
crates/app/src/main.rsmodified+1 -1
@@ -931,7 +931,7 @@ fn main() {
931 hw_caps: None,931 hw_caps: None,
932 clipboard: None,932 clipboard: None,
933 scrubbing: false,933 scrubbing: false,
934- splits: load_stance_splits(),934+ splits: load_stance_splits(bounds.size),
935 split_drag: None,935 split_drag: None,
936 trim: None,936 trim: None,
937 fade_drag: None,937 fade_drag: None,
crates/app/src/player/timeline_edit.rsmodified+8 -8
@@ -12,7 +12,7 @@ use crate::*;
12 /// from a live `MouseExitEvent` still cannot be, and is proven by driving12 /// from a live `MouseExitEvent` still cannot be, and is proven by driving
13 /// instead.13 /// instead.
14 pub(crate) fn split_drag_owes_save(split: Option<Split>) -> bool {14 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))
16 }16 }
17 17
18 impl Player {18 impl Player {
@@ -1750,9 +1750,9 @@ impl Player {
1750 Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx),1750 Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx),
1751 // Released outside the window: the up below never came, so this1751 // Released outside the window: the up below never came, so this
1752 // is where the gesture ends. The size is already written to1752 // is where the gesture ends. The size is already written to
1753- // `self.splits`, but the darkroom's two persisted seams still1753+ // `self.splits`, but a persisted seam still owes the save
1754- // owe the save `drag_release` would have paid -- without it1754+ // `drag_release` would have paid -- without it the drag
1755- // the drag holds for the session and reverts on restart.1755+ // holds for the session and reverts on restart.
1756 _ => {1756 _ => {
1757 self.split_drag = None;1757 self.split_drag = None;
1758 if split_drag_owes_save(Some(split)) {1758 if split_drag_owes_save(Some(split)) {
@@ -1889,10 +1889,10 @@ impl Player {
1889 }1889 }
1890 if let Some(split) = self.split_drag.take() {1890 if let Some(split) = self.split_drag.take() {
1891 self.drag_split(split, event.position, window, cx);1891 self.drag_split(split, event.position, window, cx);
1892- // The darkroom's own two seams outlive the window: written once,1892+ // Every seam outlives the window: written once, on the release
1893- // on the release that ends the gesture, the same small-file1893+ // that ends the gesture, the same small-file round trip
1894- // round trip `ui::dock_stance`'s tab pick uses -- not on every1894+ // `ui::dock_stance`'s tab pick uses -- not on every sample in
1895- // sample in between, which `drag_move` above never owed a write.1895+ // between, which `drag_move` above never owed a write.
1896 if split_drag_owes_save(Some(split)) {1896 if split_drag_owes_save(Some(split)) {
1897 save_stance_splits(&self.splits);1897 save_stance_splits(&self.splits);
1898 }1898 }
crates/app/src/tests/layout.rsmodified+43 -12
@@ -2135,22 +2135,48 @@ fn the_notice_plate_declares_a_bounded_wrapping_text_layout() {
2135 }2135 }
2136 2136
2137 /// A round trip through the file: what is saved is what the next load reads2137 /// 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 scratch2138+/// back, all five seams touched -- a scratch path, not the real config, the
2139-/// path, not the real config, the same isolation `keymap::tests`' own2139+/// same isolation `keymap::tests`' own `load_from`/`save_to` already takes.
2140-/// `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.
2141 #[test]2144 #[test]
2142 fn a_saved_seam_survives_a_reload() {2145 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};
2144 2150
2145 let dir = engine::scratch::Scratch::dir("edith-stance-splits");2151 let dir = engine::scratch::Scratch::dir("edith-stance-splits");
2146 let path = dir.join("stance-splits");2152 let path = dir.join("stance-splits");
2153+ let window: Size<Pixels> = size(px(1280.), px(720.));
2147 2154
2148 let mut splits = Splits::default();2155 let mut splits = Splits::default();
2156+ splits.set(Split::Library, 9000.);
2157+ splits.set(Split::Inspector, 200.);
2158+ splits.set(Split::Timeline, 250.);
2149 splits.set(Split::Dock, 333.);2159 splits.set(Split::Dock, 333.);
2160+ splits.set(Split::Bench, 200.);
2150 save_stance_splits_to(&splits, &path);2161 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.));
2152 assert_eq!(loaded.get(Split::Dock), Some(333.));2170 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));
2154 }2180 }
2155 2181
2156 /// The guard [`crate::split_drag_owes_save`] runs at the moment a drag ends2182 /// 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() {
2158 /// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary2184 /// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary
2159 /// cannot raise -- see `tests/media.rs`'s own note on the same limit, and2185 /// cannot raise -- see `tests/media.rs`'s own note on the same limit, and
2160 /// the harness drive `D2` in this session's report for the wiring itself).2186 /// the harness drive `D2` in this session's report for the wiring itself).
2161-/// What *is* checkable here without a window: exactly the two persisted2187+/// What *is* checkable here without a window: exactly the persisted
2162 /// seams owe that save, the same set `Split::PERSISTED` already names, and a2188 /// seams owe that save, the same set `Split::PERSISTED` already names, and a
2163 /// drag that never started (`None`) owes nothing.2189 /// drag that never started (`None`) owes nothing.
2164 #[test]2190 #[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() {
2166 use crate::{Split, player::timeline_edit::split_drag_owes_save};2192 use crate::{Split, player::timeline_edit::split_drag_owes_save};
2167 2193
2168 assert!(split_drag_owes_save(Some(Split::Dock)));2194 assert!(split_drag_owes_save(Some(Split::Dock)));
2169 assert!(split_drag_owes_save(Some(Split::Bench)));2195 assert!(split_drag_owes_save(Some(Split::Bench)));
2170- assert!(!split_drag_owes_save(Some(Split::Library)));2196+ assert!(split_drag_owes_save(Some(Split::Library)));
2171- assert!(!split_drag_owes_save(Some(Split::Inspector)));2197+ assert!(split_drag_owes_save(Some(Split::Inspector)));
2172- assert!(!split_drag_owes_save(Some(Split::Timeline)));2198+ assert!(split_drag_owes_save(Some(Split::Timeline)));
2173 assert!(!split_drag_owes_save(None));2199 assert!(!split_drag_owes_save(None));
2174 }2200 }
2175 2201
@@ -2178,9 +2204,14 @@ fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() {
2178 #[test]2204 #[test]
2179 fn a_missing_stance_splits_file_leaves_every_region_at_its_default() {2205 fn a_missing_stance_splits_file_leaves_every_region_at_its_default() {
2180 use crate::{Split, load_stance_splits_from};2206 use crate::{Split, load_stance_splits_from};
2207+ use gpui::{Pixels, Size, px, size};
2181 2208
2182 let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing");2209 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);
2184 assert_eq!(splits.get(Split::Dock), None);2215 assert_eq!(splits.get(Split::Dock), None);
2185 assert_eq!(splits.get(Split::Bench), None);2216 assert_eq!(splits.get(Split::Bench), None);
2186 }2217 }