diff --git a/crates/app/src/interact.rs b/crates/app/src/interact.rs index 163ca37..1b50577 100644 --- a/crates/app/src/interact.rs +++ b/crates/app/src/interact.rs @@ -238,20 +238,52 @@ pub(crate) fn drag_scrim(cx: &mut Context) -> Div { /// where the pointer stays, and a divider whose own listeners tracked it would /// 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 { +/// +/// Drawn to the ghost grammar (DESIGN §11.2): nothing at rest -- a room whose +/// every seam is inked is the "crowded" the user named -- then one hairline of +/// dim ink under the pointer, and the same line one step brighter while the +/// hand is actually holding it. The 6 px strip is the *hit* area throughout; +/// only its 1 px edge is ever painted. `held` is the seam this window is +/// dragging right now ([`Player::split_drag`]), which the pointer leaves on the +/// first move -- so the lit line has to come from the model, not from `hover`. +/// +/// A double press resets the seam to the window's own share +/// ([`Splits::clear`]): the cheap way back from a layout dragged somewhere +/// unusable, and the one every editor's dividers answer to. +pub(crate) fn divider(split: Split, held: bool, cx: &mut Context) -> Div { let across = matches!(split, Split::Timeline | Split::Bench); div() .flex_none() - .when(across, |d| d.h(px(SPLIT_W)).w_full().cursor_row_resize()) - .when(!across, |d| d.w(px(SPLIT_W)).h_full().cursor_col_resize()) - .bg(rgb(STROKE_DIVIDER())) + .when(across, |d| { + d.h(px(SPLIT_W)).w_full().cursor_row_resize().border_t_1() + }) + .when(!across, |d| { + d.w(px(SPLIT_W)).h_full().cursor_col_resize().border_l_1() + }) + .border_color(match held { + true => gpui::Hsla::from(rgb(INK3())), + false => gpui::transparent_black(), + }) // Lit under the pointer: the second half of "this can be dragged", said // before the button goes down rather than after. - .hover(|s| s.bg(rgb(ACCENT_PRIMARY()))) + .when(!held, |d| { + d.hover(|s| s.border_color(rgb(STROKE_DIVIDER()))) + }) .on_mouse_down( MouseButton::Left, - cx.listener(move |this, _: &MouseDownEvent, _, cx| { - this.split_drag = Some(split); + cx.listener(move |this, event: &MouseDownEvent, _, cx| { + match event.click_count >= 2 { + // The reset is written where a release would have written + // the drag, the same small round trip: a seam put back by + // hand must not come back on the next launch. + true => { + this.split_drag = None; + this.splits.clear(split); + crate::layout::save_stance_splits(&this.splits); + } + false => this.split_drag = Some(split), + } + cx.notify(); cx.stop_propagation(); }), ) diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index ecba611..569952b 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -373,14 +373,26 @@ impl Splits { } } + /// Forgets a seam's dragged size, which is exactly what + /// [`split_size`] reads as "the window's own share answers again" -- + /// the double-click reset, one field rather than a second table of + /// defaults that could disagree with the one already there. + pub(crate) fn clear(&mut self, split: Split) { + *self.slot(split) = None; + } + pub(crate) fn set(&mut self, split: Split, size: f32) { - *match split { + *self.slot(split) = Some(size); + } + + fn slot(&mut self, split: Split) -> &mut Option { + match split { 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); + } } } diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index b4b49b3..30124a0 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2649,3 +2649,59 @@ fn hitmap_names_every_darkroom_pointer_entry_surface() { } } } + +/// The way back from a layout dragged somewhere unusable: a double press on +/// the seam forgets the size, and the region is the window's own share again +/// -- the *same* share an untouched window gives it, not a second default +/// kept beside the first ([`Splits::clear`]). +#[test] +fn a_double_pressed_divider_forgets_the_size_it_was_dragged_to() { + use crate::layout::{Split, Splits, split_size}; + use gpui::{px, size}; + + let window = size(px(1280.), px(720.)); + let mut splits = Splits::default(); + for split in Split::PERSISTED { + let default = split_size(split, None, 2, window, false); + // A hand takes the seam somewhere else... + splits.set(split, split_size(split, Some(300.), 2, window, false)); + assert_ne!( + splits.get(split), + None, + "{split:?} kept nothing of the drag" + ); + // ...and the double press puts it back where an untouched window + // would have drawn it. + splits.clear(split); + assert_eq!(splits.get(split), None, "{split:?} still holds a size"); + assert_eq!( + split_size(split, splits.get(split), 2, window, false), + default, + "{split:?} came back to something other than its own share" + ); + } +} + +/// The seam is a ghost (DESIGN §11.2): 6 px of hit area with *nothing* painted +/// at rest, one hairline of dim ink under the pointer, the same line one step +/// brighter while it is held. The scan is the guard because the failure it +/// catches -- a `bg` on the strip, which is what the divider shipped with -- +/// draws a 6 px band of colour down the room at rest and reads as the chrome +/// the user called crowded. +#[test] +fn the_seam_paints_nothing_until_a_pointer_finds_it() { + let src = src_text("interact.rs"); + let start = src.find("pub(crate) fn divider(").expect("the divider"); + let body = &src[start..start + src[start..].find("\n}\n").expect("its end")]; + assert!( + !body.contains(".bg("), + "the divider fills its strip at rest: {body}" + ); + assert!( + body.contains("gpui::transparent_black()"), + "the divider's line is inked at rest: {body}" + ); + for step in [".hover(", "STROKE_DIVIDER()", "INK3()", "border_t_1()", "border_l_1()"] { + assert!(body.contains(step), "the divider is missing {step}"); + } +} diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index a197dac..9d59c50 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -1085,7 +1085,7 @@ pub(crate) fn render( })) .child(screen(player, position, window, cx)) .child(time_band(player, position, cx)) - .child(divider(Split::Bench, cx)) + .child(divider(Split::Bench, player.split_drag == Some(Split::Bench), cx)) .child(bench(player, bench_h, window, cx)) .child(ledger(player, position)) .when(player.keys_open, |el| { @@ -1135,7 +1135,7 @@ pub(crate) fn render( .children(player.subtitle_style_card(window_size, cx)) }), ) - .child(divider(Split::Dock, cx)) + .child(divider(Split::Dock, player.split_drag == Some(Split::Dock), cx)) .child(dock(player, dock_w, window_size, window, cx)) // The library row menu mounts on the ROOT, not inside // `stance-centre` like the clip menu beside it: it is opened from a