The seam is a ghost until a hand finds it, and a double press puts it back
Browse files at this commit373d93f8cfc6e37f614ea909d5f4aec94c581312Parent: 7fbbd0f- style
- the seam is a ghost until a hand finds it, and a double press puts it back
4 changed files +111 -11
- crates/app/src/interact.rs +39 -7
- crates/app/src/layout.rs +14 -2
- crates/app/src/tests/layout.rs +56 -0
- crates/app/src/ui/stance.rs +2 -2
crates/app/src/interact.rsmodified+39 -7
| @@ -238,20 +238,52 @@ pub(crate) fn drag_scrim(cx: &mut Context<Player>) -> Div { | |||
| 238 | /// where the pointer stays, and a divider whose own listeners tracked it would | 238 | /// where the pointer stays, and a divider whose own listeners tracked it would |
| 239 | /// stop following the hand on the first move. `stop_propagation` so the press | 239 | /// stop following the hand on the first move. `stop_propagation` so the press |
| 240 | /// never reaches the region under it -- a seam over the timeline must not scrub. | 240 | /// never reaches the region under it -- a seam over the timeline must not scrub. |
| 241 | -pub(crate) fn divider(split: Split, cx: &mut Context<Player>) -> Div { | 241 | +/// |
| 242 | +/// Drawn to the ghost grammar (DESIGN §11.2): nothing at rest -- a room whose | ||
| 243 | +/// every seam is inked is the "crowded" the user named -- then one hairline of | ||
| 244 | +/// dim ink under the pointer, and the same line one step brighter while the | ||
| 245 | +/// hand is actually holding it. The 6 px strip is the *hit* area throughout; | ||
| 246 | +/// only its 1 px edge is ever painted. `held` is the seam this window is | ||
| 247 | +/// dragging right now ([`Player::split_drag`]), which the pointer leaves on the | ||
| 248 | +/// first move -- so the lit line has to come from the model, not from `hover`. | ||
| 249 | +/// | ||
| 250 | +/// A double press resets the seam to the window's own share | ||
| 251 | +/// ([`Splits::clear`]): the cheap way back from a layout dragged somewhere | ||
| 252 | +/// unusable, and the one every editor's dividers answer to. | ||
| 253 | +pub(crate) fn divider(split: Split, held: bool, cx: &mut Context<Player>) -> Div { | ||
| 242 | let across = matches!(split, Split::Timeline | Split::Bench); | 254 | let across = matches!(split, Split::Timeline | Split::Bench); |
| 243 | div() | 255 | div() |
| 244 | .flex_none() | 256 | .flex_none() |
| 245 | - .when(across, |d| d.h(px(SPLIT_W)).w_full().cursor_row_resize()) | 257 | + .when(across, |d| { |
| 246 | - .when(!across, |d| d.w(px(SPLIT_W)).h_full().cursor_col_resize()) | 258 | + d.h(px(SPLIT_W)).w_full().cursor_row_resize().border_t_1() |
| 247 | - .bg(rgb(STROKE_DIVIDER())) | 259 | + }) |
| 260 | + .when(!across, |d| { | ||
| 261 | + d.w(px(SPLIT_W)).h_full().cursor_col_resize().border_l_1() | ||
| 262 | + }) | ||
| 263 | + .border_color(match held { | ||
| 264 | + true => gpui::Hsla::from(rgb(INK3())), | ||
| 265 | + false => gpui::transparent_black(), | ||
| 266 | + }) | ||
| 248 | // Lit under the pointer: the second half of "this can be dragged", said | 267 | // Lit under the pointer: the second half of "this can be dragged", said |
| 249 | // before the button goes down rather than after. | 268 | // before the button goes down rather than after. |
| 250 | - .hover(|s| s.bg(rgb(ACCENT_PRIMARY()))) | 269 | + .when(!held, |d| { |
| 270 | + d.hover(|s| s.border_color(rgb(STROKE_DIVIDER()))) | ||
| 271 | + }) | ||
| 251 | .on_mouse_down( | 272 | .on_mouse_down( |
| 252 | MouseButton::Left, | 273 | MouseButton::Left, |
| 253 | - cx.listener(move |this, _: &MouseDownEvent, _, cx| { | 274 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { |
| 254 | - this.split_drag = Some(split); | 275 | + match event.click_count >= 2 { |
| 276 | + // The reset is written where a release would have written | ||
| 277 | + // the drag, the same small round trip: a seam put back by | ||
| 278 | + // hand must not come back on the next launch. | ||
| 279 | + true => { | ||
| 280 | + this.split_drag = None; | ||
| 281 | + this.splits.clear(split); | ||
| 282 | + crate::layout::save_stance_splits(&this.splits); | ||
| 283 | + } | ||
| 284 | + false => this.split_drag = Some(split), | ||
| 285 | + } | ||
| 286 | + cx.notify(); | ||
| 255 | cx.stop_propagation(); | 287 | cx.stop_propagation(); |
| 256 | }), | 288 | }), |
| 257 | ) | 289 | ) |
crates/app/src/layout.rsmodified+14 -2
| @@ -373,14 +373,26 @@ impl Splits { | |||
| 373 | } | 373 | } |
| 374 | } | 374 | } |
| 375 | 375 | ||
| 376 | + /// Forgets a seam's dragged size, which is exactly what | ||
| 377 | + /// [`split_size`] reads as "the window's own share answers again" -- | ||
| 378 | + /// the double-click reset, one field rather than a second table of | ||
| 379 | + /// defaults that could disagree with the one already there. | ||
| 380 | + pub(crate) fn clear(&mut self, split: Split) { | ||
| 381 | + *self.slot(split) = None; | ||
| 382 | + } | ||
| 383 | + | ||
| 376 | pub(crate) fn set(&mut self, split: Split, size: f32) { | 384 | pub(crate) fn set(&mut self, split: Split, size: f32) { |
| 377 | - *match split { | 385 | + *self.slot(split) = Some(size); |
| 386 | + } | ||
| 387 | + | ||
| 388 | + fn slot(&mut self, split: Split) -> &mut Option<f32> { | ||
| 389 | + match split { | ||
| 378 | Split::Library => &mut self.library, | 390 | Split::Library => &mut self.library, |
| 379 | Split::Inspector => &mut self.inspector, | 391 | Split::Inspector => &mut self.inspector, |
| 380 | Split::Timeline => &mut self.timeline, | 392 | Split::Timeline => &mut self.timeline, |
| 381 | Split::Dock => &mut self.dock, | 393 | Split::Dock => &mut self.dock, |
| 382 | Split::Bench => &mut self.bench, | 394 | Split::Bench => &mut self.bench, |
| 383 | - } = Some(size); | 395 | + } |
| 384 | } | 396 | } |
| 385 | } | 397 | } |
| 386 | 398 | ||
crates/app/src/tests/layout.rsmodified+56 -0
| @@ -2649,3 +2649,59 @@ fn hitmap_names_every_darkroom_pointer_entry_surface() { | |||
| 2649 | } | 2649 | } |
| 2650 | } | 2650 | } |
| 2651 | } | 2651 | } |
| 2652 | + | ||
| 2653 | +/// The way back from a layout dragged somewhere unusable: a double press on | ||
| 2654 | +/// the seam forgets the size, and the region is the window's own share again | ||
| 2655 | +/// -- the *same* share an untouched window gives it, not a second default | ||
| 2656 | +/// kept beside the first ([`Splits::clear`]). | ||
| 2657 | +#[test] | ||
| 2658 | +fn a_double_pressed_divider_forgets_the_size_it_was_dragged_to() { | ||
| 2659 | + use crate::layout::{Split, Splits, split_size}; | ||
| 2660 | + use gpui::{px, size}; | ||
| 2661 | + | ||
| 2662 | + let window = size(px(1280.), px(720.)); | ||
| 2663 | + let mut splits = Splits::default(); | ||
| 2664 | + for split in Split::PERSISTED { | ||
| 2665 | + let default = split_size(split, None, 2, window, false); | ||
| 2666 | + // A hand takes the seam somewhere else... | ||
| 2667 | + splits.set(split, split_size(split, Some(300.), 2, window, false)); | ||
| 2668 | + assert_ne!( | ||
| 2669 | + splits.get(split), | ||
| 2670 | + None, | ||
| 2671 | + "{split:?} kept nothing of the drag" | ||
| 2672 | + ); | ||
| 2673 | + // ...and the double press puts it back where an untouched window | ||
| 2674 | + // would have drawn it. | ||
| 2675 | + splits.clear(split); | ||
| 2676 | + assert_eq!(splits.get(split), None, "{split:?} still holds a size"); | ||
| 2677 | + assert_eq!( | ||
| 2678 | + split_size(split, splits.get(split), 2, window, false), | ||
| 2679 | + default, | ||
| 2680 | + "{split:?} came back to something other than its own share" | ||
| 2681 | + ); | ||
| 2682 | + } | ||
| 2683 | +} | ||
| 2684 | + | ||
| 2685 | +/// The seam is a ghost (DESIGN §11.2): 6 px of hit area with *nothing* painted | ||
| 2686 | +/// at rest, one hairline of dim ink under the pointer, the same line one step | ||
| 2687 | +/// brighter while it is held. The scan is the guard because the failure it | ||
| 2688 | +/// catches -- a `bg` on the strip, which is what the divider shipped with -- | ||
| 2689 | +/// draws a 6 px band of colour down the room at rest and reads as the chrome | ||
| 2690 | +/// the user called crowded. | ||
| 2691 | +#[test] | ||
| 2692 | +fn the_seam_paints_nothing_until_a_pointer_finds_it() { | ||
| 2693 | + let src = src_text("interact.rs"); | ||
| 2694 | + let start = src.find("pub(crate) fn divider(").expect("the divider"); | ||
| 2695 | + let body = &src[start..start + src[start..].find("\n}\n").expect("its end")]; | ||
| 2696 | + assert!( | ||
| 2697 | + !body.contains(".bg("), | ||
| 2698 | + "the divider fills its strip at rest: {body}" | ||
| 2699 | + ); | ||
| 2700 | + assert!( | ||
| 2701 | + body.contains("gpui::transparent_black()"), | ||
| 2702 | + "the divider's line is inked at rest: {body}" | ||
| 2703 | + ); | ||
| 2704 | + for step in [".hover(", "STROKE_DIVIDER()", "INK3()", "border_t_1()", "border_l_1()"] { | ||
| 2705 | + assert!(body.contains(step), "the divider is missing {step}"); | ||
| 2706 | + } | ||
| 2707 | +} | ||
crates/app/src/ui/stance.rsmodified+2 -2
| @@ -1085,7 +1085,7 @@ pub(crate) fn render( | |||
| 1085 | })) | 1085 | })) |
| 1086 | .child(screen(player, position, window, cx)) | 1086 | .child(screen(player, position, window, cx)) |
| 1087 | .child(time_band(player, position, cx)) | 1087 | .child(time_band(player, position, cx)) |
| 1088 | - .child(divider(Split::Bench, cx)) | 1088 | + .child(divider(Split::Bench, player.split_drag == Some(Split::Bench), cx)) |
| 1089 | .child(bench(player, bench_h, window, cx)) | 1089 | .child(bench(player, bench_h, window, cx)) |
| 1090 | .child(ledger(player, position)) | 1090 | .child(ledger(player, position)) |
| 1091 | .when(player.keys_open, |el| { | 1091 | .when(player.keys_open, |el| { |
| @@ -1135,7 +1135,7 @@ pub(crate) fn render( | |||
| 1135 | .children(player.subtitle_style_card(window_size, cx)) | 1135 | .children(player.subtitle_style_card(window_size, cx)) |
| 1136 | }), | 1136 | }), |
| 1137 | ) | 1137 | ) |
| 1138 | - .child(divider(Split::Dock, cx)) | 1138 | + .child(divider(Split::Dock, player.split_drag == Some(Split::Dock), cx)) |
| 1139 | .child(dock(player, dock_w, window_size, window, cx)) | 1139 | .child(dock(player, dock_w, window_size, window, cx)) |
| 1140 | // The library row menu mounts on the ROOT, not inside | 1140 | // The library row menu mounts on the ROOT, not inside |
| 1141 | // `stance-centre` like the clip menu beside it: it is opened from a | 1141 | // `stance-centre` like the clip menu beside it: it is opened from a |