Panels grow and shrink by dragging the seams between them
Browse files at this commit- feat
- panels grow and shrink by dragging the seams between them
9 changed files +353 -15
- crates/app/src/interact.rs +28 -0
- crates/app/src/layout.rs +131 -0
- crates/app/src/main.rs +10 -0
- crates/app/src/player/timeline_edit.rs +50 -2
- crates/app/src/render.rs +12 -8
- crates/app/src/tests/layout.rs +108 -0
- crates/app/src/ui/inspector.rs +1 -1
- crates/app/src/ui/timeline.rs +5 -2
- crates/app/src/ui/toolbar.rs +8 -2
crates/app/src/interact.rsmodified+28 -0
| @@ -168,6 +168,34 @@ pub(crate) fn drag_scrim(cx: &mut Context<Player>) -> Div { | |||
| 168 | .on_mouse_up(MouseButton::Left, cx.listener(Player::drag_release)) | 168 | .on_mouse_up(MouseButton::Left, cx.listener(Player::drag_release)) |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | +/// The seam between two panels, and the handle that resizes them: a strip | ||
| 172 | +/// [`SPLIT_W`] wide with the resize cursor of its axis on it, which is the whole | ||
| 173 | +/// of how a person finds out the layout moves at all. | ||
| 174 | +/// | ||
| 175 | +/// The press is all this element does. The gesture itself is the root's, like | ||
| 176 | +/// every other drag in this window ([`Player::drag_move`]): a 6 px strip is not | ||
| 177 | +/// where the pointer stays, and a divider whose own listeners tracked it would | ||
| 178 | +/// stop following the hand on the first move. `stop_propagation` so the press | ||
| 179 | +/// never reaches the region under it -- a seam over the timeline must not scrub. | ||
| 180 | +pub(crate) fn divider(split: Split, cx: &mut Context<Player>) -> Div { | ||
| 181 | + let across = matches!(split, Split::Timeline); | ||
| 182 | + div() | ||
| 183 | + .flex_none() | ||
| 184 | + .when(across, |d| d.h(px(SPLIT_W)).w_full().cursor_row_resize()) | ||
| 185 | + .when(!across, |d| d.w(px(SPLIT_W)).h_full().cursor_col_resize()) | ||
| 186 | + .bg(rgb(STROKE_DIVIDER())) | ||
| 187 | + // Lit under the pointer: the second half of "this can be dragged", said | ||
| 188 | + // before the button goes down rather than after. | ||
| 189 | + .hover(|s| s.bg(rgb(ACCENT_PRIMARY()))) | ||
| 190 | + .on_mouse_down( | ||
| 191 | + MouseButton::Left, | ||
| 192 | + cx.listener(move |this, _: &MouseDownEvent, _, cx| { | ||
| 193 | + this.split_drag = Some(split); | ||
| 194 | + cx.stop_propagation(); | ||
| 195 | + }), | ||
| 196 | + ) | ||
| 197 | +} | ||
| 198 | + | ||
| 171 | /// A press that stops here. What every card's body hands its scrim: the scrim | 199 | /// A press that stops here. What every card's body hands its scrim: the scrim |
| 172 | /// closes the card on a press, and the card is painted after it, so this listener | 200 | /// closes the card on a press, and the card is painted after it, so this listener |
| 173 | /// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant | 201 | /// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant |
crates/app/src/layout.rsmodified+131 -0
| @@ -1,5 +1,7 @@ | |||
| 1 | //! The window's fixed geometry: what every region is measured in. | 1 | //! The window's fixed geometry: what every region is measured in. |
| 2 | 2 | ||
| 3 | +use crate::*; | ||
| 4 | + | ||
| 3 | /// ...and the narrowest it is drawn: a library row whose length the engine has | 5 | /// ...and the narrowest it is drawn: a library row whose length the engine has |
| 4 | /// not measured yet has a landing place but no width, and a head marker says | 6 | /// not measured yet has a landing place but no width, and a head marker says |
| 5 | /// where it goes where a zero-width box would say nothing. | 7 | /// where it goes where a zero-width box would say nothing. |
| @@ -294,3 +296,132 @@ pub(crate) const ZOOM_OUT_MARGIN: f64 = 1.05; | |||
| 294 | /// short -- the thing a bed scaled to the content's own length cannot say. | 296 | /// short -- the thing a bed scaled to the content's own length cannot say. |
| 295 | /// [`View::fit`] is the one way back to "the whole timeline across the bed". | 297 | /// [`View::fit`] is the one way back to "the whole timeline across the bed". |
| 296 | pub(crate) const PPS_DEFAULT: f64 = 40.; | 298 | pub(crate) const PPS_DEFAULT: f64 = 40.; |
| 299 | + | ||
| 300 | +// -- the seams between the regions, and where a hand has dragged them --------- | ||
| 301 | + | ||
| 302 | +/// Which divider a hand has hold of. The three seams the main layout has -- | ||
| 303 | +/// library|picture, picture|inspector and the timeline's top edge -- and so the | ||
| 304 | +/// only three sizes in this window a person sets rather than is given. | ||
| 305 | +#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
| 306 | +pub(crate) enum Split { | ||
| 307 | + Library, | ||
| 308 | + Inspector, | ||
| 309 | + Timeline, | ||
| 310 | +} | ||
| 311 | + | ||
| 312 | +/// How wide a divider is drawn *and* hit. Wider than the 1 px stroke it stands | ||
| 313 | +/// in for: a seam nobody can put a pointer on is a seam nobody can drag, which | ||
| 314 | +/// is why every editor that ships this draws a strip rather than the hairline | ||
| 315 | +/// it looks like. | ||
| 316 | +pub(crate) const SPLIT_W: f32 = 6.; | ||
| 317 | + | ||
| 318 | +/// The most of the window one side column may be dragged to. A third each, so | ||
| 319 | +/// the picture keeps the middle at every size -- the rule [`library_w`] and | ||
| 320 | +/// [`inspector_w`] already lay an untouched window out by, kept once the hand | ||
| 321 | +/// takes over. | ||
| 322 | +pub(crate) const SIDE_MAX_FRAC: f32 = 1. / 3.; | ||
| 323 | + | ||
| 324 | +/// The most of the window the timeline may be dragged to. Past | ||
| 325 | +/// [`TIMELINE_SHARE`], which is what it is *given*: a hand asking for a tall | ||
| 326 | +/// timeline is asking on purpose, and the picture still keeps most of a third. | ||
| 327 | +pub(crate) const TIMELINE_MAX_SHARE: f32 = 0.7; | ||
| 328 | + | ||
| 329 | +/// What a hand has done to the three seams: the size it dragged each panel to, | ||
| 330 | +/// or `None` where nobody has touched one and the window's own share still | ||
| 331 | +/// answers. Held in the model and not recomputed, so a size outlives the | ||
| 332 | +/// release -- and read through [`split_size`], so it cannot outlive the window | ||
| 333 | +/// it was set in. | ||
| 334 | +#[derive(Clone, Copy, Default)] | ||
| 335 | +pub(crate) struct Splits { | ||
| 336 | + library: Option<f32>, | ||
| 337 | + inspector: Option<f32>, | ||
| 338 | + timeline: Option<f32>, | ||
| 339 | +} | ||
| 340 | + | ||
| 341 | +impl Splits { | ||
| 342 | + pub(crate) fn get(&self, split: Split) -> Option<f32> { | ||
| 343 | + match split { | ||
| 344 | + Split::Library => self.library, | ||
| 345 | + Split::Inspector => self.inspector, | ||
| 346 | + Split::Timeline => self.timeline, | ||
| 347 | + } | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + pub(crate) fn set(&mut self, split: Split, size: f32) { | ||
| 351 | + *match split { | ||
| 352 | + Split::Library => &mut self.library, | ||
| 353 | + Split::Inspector => &mut self.inspector, | ||
| 354 | + Split::Timeline => &mut self.timeline, | ||
| 355 | + } = Some(size); | ||
| 356 | + } | ||
| 357 | +} | ||
| 358 | + | ||
| 359 | +/// How small a panel may be dragged and how large: the floor is the size it | ||
| 360 | +/// still shows something at, the ceiling is what its neighbour needs to stay a | ||
| 361 | +/// region rather than a sliver. Neither end is passable -- a panel dragged to | ||
| 362 | +/// nothing is a panel nobody can get back, and a picture squeezed out by two | ||
| 363 | +/// side columns is the same loss on the other side of the window. | ||
| 364 | +pub(crate) fn split_bounds(split: Split, window: Size<Pixels>) -> (f32, f32) { | ||
| 365 | + let (w, h) = (f32::from(window.width), f32::from(window.height)); | ||
| 366 | + match split { | ||
| 367 | + Split::Library => (LIBRARY_MIN_W, w * SIDE_MAX_FRAC), | ||
| 368 | + Split::Inspector => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC), | ||
| 369 | + // One whole lane under the chrome: a timeline shorter than that is a | ||
| 370 | + // ruler with nothing beneath it. | ||
| 371 | + Split::Timeline => (TIMELINE_FIXED_H + LANE_H, h * TIMELINE_MAX_SHARE), | ||
| 372 | + } | ||
| 373 | +} | ||
| 374 | + | ||
| 375 | +/// How big the panel at this seam is drawn: what the hand dragged it to, held | ||
| 376 | +/// inside the window *being drawn now* -- the window is resizable, and a width | ||
| 377 | +/// set at 1920 px is not a width at 640 -- or the share the untouched layout | ||
| 378 | +/// gives it. | ||
| 379 | +pub(crate) fn split_size( | ||
| 380 | + split: Split, | ||
| 381 | + set: Option<f32>, | ||
| 382 | + lanes: usize, | ||
| 383 | + window: Size<Pixels>, | ||
| 384 | +) -> f32 { | ||
| 385 | + let (w, h) = (f32::from(window.width), f32::from(window.height)); | ||
| 386 | + let (min, max) = split_bounds(split, window); | ||
| 387 | + let default = match split { | ||
| 388 | + Split::Library => library_w(w), | ||
| 389 | + Split::Inspector => inspector_w(w), | ||
| 390 | + Split::Timeline => timeline_h(lanes).min(h * TIMELINE_SHARE), | ||
| 391 | + }; | ||
| 392 | + // The floor wins a window too small to honour both ends: a panel at its | ||
| 393 | + // floor is still a panel, and `clamp` panics outright on a ceiling under | ||
| 394 | + // its floor. | ||
| 395 | + set.unwrap_or(default).clamp(min, max.max(min)) | ||
| 396 | +} | ||
| 397 | + | ||
| 398 | +/// Where a divider drag puts the panel it belongs to: the pointer's position | ||
| 399 | +/// turned into that panel's size. Half a strip is taken off each answer because | ||
| 400 | +/// the strip is grabbed by its middle -- without it the panel jumps a strip's | ||
| 401 | +/// width on the press and then trails the pointer for the rest of the gesture. | ||
| 402 | +pub(crate) fn split_drag_size(split: Split, at: Point<Pixels>, window: Size<Pixels>) -> f32 { | ||
| 403 | + let (x, y) = (f32::from(at.x), f32::from(at.y)); | ||
| 404 | + let (w, h) = (f32::from(window.width), f32::from(window.height)); | ||
| 405 | + match split { | ||
| 406 | + Split::Library => x - SPLIT_W / 2., | ||
| 407 | + Split::Inspector => w - x - SPLIT_W / 2., | ||
| 408 | + // This seam sits above the edit toolbar, which is a fixed height: what | ||
| 409 | + // is under the pointer is the toolbar and the timeline together. | ||
| 410 | + Split::Timeline => h - y - TOOLBAR_H - SPLIT_W / 2., | ||
| 411 | + } | ||
| 412 | +} | ||
| 413 | + | ||
| 414 | +impl Player { | ||
| 415 | + /// How big the panel on this seam is this frame -- the one door every | ||
| 416 | + /// region measures itself through, so a dragged size and a drawn one cannot | ||
| 417 | + /// disagree. | ||
| 418 | + pub(crate) fn split_px(&self, split: Split, window: Size<Pixels>) -> f32 { | ||
| 419 | + // The pair a fresh project starts with where there is no session yet, | ||
| 420 | + // which is what the timeline itself draws (`Player::timeline`). | ||
| 421 | + let lanes = self | ||
| 422 | + .session | ||
| 423 | + .as_ref() | ||
| 424 | + .map_or(2, |session| session.lanes().len()); | ||
| 425 | + split_size(split, self.splits.get(split), lanes, window) | ||
| 426 | + } | ||
| 427 | +} | ||
crates/app/src/main.rsmodified+10 -0
| @@ -210,6 +210,14 @@ struct Player { | |||
| 210 | /// A drag that started on the ruler. Moves anywhere in the window scrub | 210 | /// A drag that started on the ruler. Moves anywhere in the window scrub |
| 211 | /// while it is set; the release commits the exact position. | 211 | /// while it is set; the release commits the exact position. |
| 212 | scrubbing: bool, | 212 | scrubbing: bool, |
| 213 | + /// What the hand has made of the three panel seams, and which one it is | ||
| 214 | + /// holding now. Kept here rather than worked out per frame from the | ||
| 215 | + /// window's own shares: a size a person dragged is a size that has to | ||
| 216 | + /// survive the release ([`Splits`]). | ||
| 217 | + splits: Splits, | ||
| 218 | + /// A drag that started on a divider, tracked on the root for `scrubbing`'s | ||
| 219 | + /// reason -- the strip is 6 px and the pointer leaves it at once. | ||
| 220 | + split_drag: Option<Split>, | ||
| 213 | /// A drag that started on a clip's edge, tracked on the root for | 221 | /// A drag that started on a clip's edge, tracked on the root for |
| 214 | /// `scrubbing`'s reason: a 6 px strip is not where the pointer stays. See | 222 | /// `scrubbing`'s reason: a 6 px strip is not where the pointer stays. See |
| 215 | /// [`Trim`]. | 223 | /// [`Trim`]. |
| @@ -665,6 +673,8 @@ fn main() { | |||
| 665 | hw_caps: None, | 673 | hw_caps: None, |
| 666 | clipboard: None, | 674 | clipboard: None, |
| 667 | scrubbing: false, | 675 | scrubbing: false, |
| 676 | + splits: Splits::default(), | ||
| 677 | + split_drag: None, | ||
| 668 | trim: None, | 678 | trim: None, |
| 669 | grab: 0, | 679 | grab: 0, |
| 670 | snap: true, | 680 | snap: true, |
crates/app/src/player/timeline_edit.rsmodified+50 -2
| @@ -1012,7 +1012,26 @@ impl Player { | |||
| 1012 | /// where it sits (`Hitbox::is_hovered`, window.rs:788), so while a card is | 1012 | /// where it sits (`Hitbox::is_hovered`, window.rs:788), so while a card is |
| 1013 | /// up the root is not hovered anywhere under it and hears none of this: the | 1013 | /// up the root is not hovered anywhere under it and hears none of this: the |
| 1014 | /// press set a value and the drag then froze on it. | 1014 | /// press set a value and the drag then froze on it. |
| 1015 | - pub(crate) fn drag_move(&mut self, event: &MouseMoveEvent, _: &mut Window, cx: &mut Context<Self>) { | 1015 | + pub(crate) fn drag_move( |
| 1016 | + &mut self, | ||
| 1017 | + event: &MouseMoveEvent, | ||
| 1018 | + window: &mut Window, | ||
| 1019 | + cx: &mut Context<Self>, | ||
| 1020 | + ) { | ||
| 1021 | + // A divider is answered before every gesture below it: it is pressed on | ||
| 1022 | + // a strip of its own that nothing else is under, so neither can swallow | ||
| 1023 | + // the other -- a seam over the timeline never scrubs, and a scrub is | ||
| 1024 | + // never mistaken for a resize. | ||
| 1025 | + if let Some(split) = self.split_drag { | ||
| 1026 | + match event.pressed_button { | ||
| 1027 | + Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx), | ||
| 1028 | + // Released outside the window: the up below never came, so this | ||
| 1029 | + // is where the gesture ends. Nothing is owed -- every move has | ||
| 1030 | + // already been written. | ||
| 1031 | + _ => self.split_drag = None, | ||
| 1032 | + } | ||
| 1033 | + return; | ||
| 1034 | + } | ||
| 1016 | // A handle is 10 px across and the pointer leaves it at once, so | 1035 | // A handle is 10 px across and the pointer leaves it at once, so |
| 1017 | // the equalizer drag is tracked here for the ruler's reason. | 1036 | // the equalizer drag is tracked here for the ruler's reason. |
| 1018 | if self.eq_dragging { | 1037 | if self.eq_dragging { |
| @@ -1092,7 +1111,18 @@ impl Player { | |||
| 1092 | /// live-writing bars -- is paid here. On the root and on a card's scrim | 1111 | /// live-writing bars -- is paid here. On the root and on a card's scrim |
| 1093 | /// both, for [`Player::drag_move`]'s reason: a release over an open card | 1112 | /// both, for [`Player::drag_move`]'s reason: a release over an open card |
| 1094 | /// never reaches the root. | 1113 | /// never reaches the root. |
| 1095 | - pub(crate) fn drag_release(&mut self, event: &MouseUpEvent, _: &mut Window, cx: &mut Context<Self>) { | 1114 | + pub(crate) fn drag_release( |
| 1115 | + &mut self, | ||
| 1116 | + event: &MouseUpEvent, | ||
| 1117 | + window: &mut Window, | ||
| 1118 | + cx: &mut Context<Self>, | ||
| 1119 | + ) { | ||
| 1120 | + // The panel is left exactly where the hand let go, for the reason every | ||
| 1121 | + // other release here lands one last sample. | ||
| 1122 | + if let Some(split) = self.split_drag.take() { | ||
| 1123 | + self.drag_split(split, event.position, window, cx); | ||
| 1124 | + return; | ||
| 1125 | + } | ||
| 1096 | if std::mem::take(&mut self.eq_dragging) { | 1126 | if std::mem::take(&mut self.eq_dragging) { |
| 1097 | // The release lands exactly, then the gesture is written | 1127 | // The release lands exactly, then the gesture is written |
| 1098 | // once -- the append-only table's whole reason. | 1128 | // once -- the append-only table's whole reason. |
| @@ -1130,4 +1160,22 @@ impl Player { | |||
| 1130 | self.scrub_to(event.position.x, true, cx); | 1160 | self.scrub_to(event.position.x, true, cx); |
| 1131 | } | 1161 | } |
| 1132 | } | 1162 | } |
| 1163 | + | ||
| 1164 | + /// Where the hand has taken a divider, live: the panel it belongs to is set | ||
| 1165 | + /// to what the pointer says and the next frame draws it there. Nothing else | ||
| 1166 | + /// is written -- a layout is not an edit, so there is no undo step to take | ||
| 1167 | + /// and no worker to flush. The clamps are the *reader's* | ||
| 1168 | + /// ([`split_size`]), so a size set in one window is still a size in the | ||
| 1169 | + /// next one it is drawn in. | ||
| 1170 | + fn drag_split( | ||
| 1171 | + &mut self, | ||
| 1172 | + split: Split, | ||
| 1173 | + at: Point<Pixels>, | ||
| 1174 | + window: &mut Window, | ||
| 1175 | + cx: &mut Context<Self>, | ||
| 1176 | + ) { | ||
| 1177 | + self.splits | ||
| 1178 | + .set(split, split_drag_size(split, at, window.viewport_size())); | ||
| 1179 | + cx.notify(); | ||
| 1180 | + } | ||
| 1133 | } | 1181 | } |
crates/app/src/render.rsmodified+12 -8
| @@ -555,10 +555,14 @@ impl Render for Player { | |||
| 555 | .min_h(px(0.)) | 555 | .min_h(px(0.)) |
| 556 | .flex() | 556 | .flex() |
| 557 | .child(self.library( | 557 | .child(self.library( |
| 558 | - library_w(f32::from(window.viewport_size().width)), | 558 | + self.split_px(Split::Library, window.viewport_size()), |
| 559 | f32::from(window.viewport_size().height), | 559 | f32::from(window.viewport_size().height), |
| 560 | cx, | 560 | cx, |
| 561 | )) | 561 | )) |
| 562 | + // The seams, one per pair of regions: what a hand drags to | ||
| 563 | + // give a panel more room and its neighbour less | ||
| 564 | + // ([`divider`]). | ||
| 565 | + .child(divider(Split::Library, cx)) | ||
| 562 | .child( | 566 | .child( |
| 563 | div() | 567 | div() |
| 564 | .flex_1() | 568 | .flex_1() |
| @@ -636,21 +640,21 @@ impl Render for Player { | |||
| 636 | .child(self.transport_bar( | 640 | .child(self.transport_bar( |
| 637 | position, | 641 | position, |
| 638 | state, | 642 | state, |
| 639 | - f32::from(window.viewport_size().width), | 643 | + window.viewport_size(), |
| 640 | cx, | 644 | cx, |
| 641 | )), | 645 | )), |
| 642 | ) | 646 | ) |
| 647 | + .child(divider(Split::Inspector, cx)) | ||
| 643 | // The settings cards live in here rather than over the | 648 | // The settings cards live in here rather than over the |
| 644 | // timeline: adjusting a clip must not hide the clip. | 649 | // timeline: adjusting a clip must not hide the clip. |
| 645 | .child(self.inspector(window.viewport_size(), cx)), | 650 | .child(self.inspector(window.viewport_size(), cx)), |
| 646 | ) | 651 | ) |
| 652 | + // Above the toolbar rather than under it: the toolbar is a fixed | ||
| 653 | + // strip belonging to the timeline, so the pair moves as one and the | ||
| 654 | + // edge the hand is pulling is the edge under the pointer. | ||
| 655 | + .child(divider(Split::Timeline, cx)) | ||
| 647 | .child(self.toolbar(cx)) | 656 | .child(self.toolbar(cx)) |
| 648 | - .child(self.timeline( | 657 | + .child(self.timeline(position, state, window.viewport_size(), cx)) |
| 649 | - position, | ||
| 650 | - state, | ||
| 651 | - f32::from(window.viewport_size().height), | ||
| 652 | - cx, | ||
| 653 | - )) | ||
| 654 | // Over the region they were opened on, and under the modal cards: | 658 | // Over the region they were opened on, and under the modal cards: |
| 655 | // they are only ever up while none of those is (`modal`). | 659 | // they are only ever up while none of those is (`modal`). |
| 656 | .children(self.context_card(window.viewport_size(), cx)) | 660 | .children(self.context_card(window.viewport_size(), cx)) |
crates/app/src/tests/layout.rsmodified+108 -0
| @@ -1202,3 +1202,111 @@ fn the_volume_slider_lands_where_it_paints() { | |||
| 1202 | ); | 1202 | ); |
| 1203 | } | 1203 | } |
| 1204 | } | 1204 | } |
| 1205 | + | ||
| 1206 | +/// The three seams a hand may move, and the two ends neither of them may be | ||
| 1207 | +/// dragged past: a panel dragged to nothing is a panel nobody can get back, and | ||
| 1208 | +/// a picture squeezed out by its two neighbours is that same loss from the | ||
| 1209 | +/// other side of the window. | ||
| 1210 | +#[test] | ||
| 1211 | +fn a_dragged_divider_stops_before_either_panel_disappears() { | ||
| 1212 | + use crate::ui::theme::INSPECTOR_MIN_W; | ||
| 1213 | + use crate::{ | ||
| 1214 | + SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w, | ||
| 1215 | + split_drag_size, split_size, timeline_h, | ||
| 1216 | + }; | ||
| 1217 | + use gpui::{point, px, size}; | ||
| 1218 | + | ||
| 1219 | + let window = size(px(1280.), px(720.)); | ||
| 1220 | + // Untouched, every region is still the share the window gives it. | ||
| 1221 | + assert_eq!(split_size(Split::Library, None, 2, window), library_w(1280.)); | ||
| 1222 | + assert_eq!( | ||
| 1223 | + split_size(Split::Inspector, None, 2, window), | ||
| 1224 | + inspector_w(1280.) | ||
| 1225 | + ); | ||
| 1226 | + assert_eq!( | ||
| 1227 | + split_size(Split::Timeline, None, 2, window), | ||
| 1228 | + timeline_h(2).min(720. * TIMELINE_SHARE) | ||
| 1229 | + ); | ||
| 1230 | + // Dragged, it is what the hand asked for... | ||
| 1231 | + assert_eq!(split_size(Split::Library, Some(300.), 2, window), 300.); | ||
| 1232 | + assert_eq!(split_size(Split::Timeline, Some(300.), 2, window), 300.); | ||
| 1233 | + // ...and never past either end of it. | ||
| 1234 | + assert_eq!( | ||
| 1235 | + split_size(Split::Library, Some(0.), 2, window), | ||
| 1236 | + LIBRARY_MIN_W | ||
| 1237 | + ); | ||
| 1238 | + assert_eq!( | ||
| 1239 | + split_size(Split::Library, Some(9000.), 2, window), | ||
| 1240 | + 1280. * SIDE_MAX_FRAC | ||
| 1241 | + ); | ||
| 1242 | + assert_eq!( | ||
| 1243 | + split_size(Split::Inspector, Some(-40.), 2, window), | ||
| 1244 | + INSPECTOR_MIN_W | ||
| 1245 | + ); | ||
| 1246 | + assert_eq!( | ||
| 1247 | + split_size(Split::Timeline, Some(0.), 2, window), | ||
| 1248 | + TIMELINE_FIXED_H + LANE_H | ||
| 1249 | + ); | ||
| 1250 | + assert_eq!( | ||
| 1251 | + split_size(Split::Timeline, Some(9000.), 2, window), | ||
| 1252 | + 720. * TIMELINE_MAX_SHARE | ||
| 1253 | + ); | ||
| 1254 | + // A window too narrow to honour both ends keeps the floor rather than | ||
| 1255 | + // panicking inside `clamp`, which is what a ceiling under its own floor | ||
| 1256 | + // does. | ||
| 1257 | + let narrow = size(px(600.), px(360.)); | ||
| 1258 | + assert_eq!( | ||
| 1259 | + split_size(Split::Inspector, Some(9000.), 2, narrow), | ||
| 1260 | + INSPECTOR_MIN_W | ||
| 1261 | + ); | ||
| 1262 | + | ||
| 1263 | + // The pointer turned into a size: the panel follows the hand, and the two | ||
| 1264 | + // that do not start at the window's own edge are measured from the far one. | ||
| 1265 | + // Half a strip off each, because the strip is grabbed by its middle. | ||
| 1266 | + assert_eq!( | ||
| 1267 | + split_drag_size(Split::Library, point(px(300.), px(400.)), window), | ||
| 1268 | + 300. - SPLIT_W / 2. | ||
| 1269 | + ); | ||
| 1270 | + assert_eq!( | ||
| 1271 | + split_drag_size(Split::Inspector, point(px(1000.), px(400.)), window), | ||
| 1272 | + 280. - SPLIT_W / 2. | ||
| 1273 | + ); | ||
| 1274 | + // The seam sits above the fixed toolbar, so what the pointer leaves under | ||
| 1275 | + // it is that strip and the timeline together. | ||
| 1276 | + assert_eq!( | ||
| 1277 | + split_drag_size(Split::Timeline, point(px(300.), px(500.)), window), | ||
| 1278 | + 220. - TOOLBAR_H - SPLIT_W / 2. | ||
| 1279 | + ); | ||
| 1280 | +} | ||
| 1281 | + | ||
| 1282 | +/// Every seam in the main layout has a handle on it, and every region draws | ||
| 1283 | +/// itself at the size that handle sets: a region still measuring itself off the | ||
| 1284 | +/// window's own share is a panel whose divider moves nothing. | ||
| 1285 | +#[test] | ||
| 1286 | +fn every_seam_in_the_layout_has_a_divider_on_it() { | ||
| 1287 | + let render = src_text("render.rs"); | ||
| 1288 | + for split in ["Split::Library", "Split::Inspector", "Split::Timeline"] { | ||
| 1289 | + assert!( | ||
| 1290 | + render.contains(&format!("divider({split}")), | ||
| 1291 | + "{split} has no divider to drag" | ||
| 1292 | + ); | ||
| 1293 | + } | ||
| 1294 | + // The strip is drawn wide enough to hit and says which way it moves -- | ||
| 1295 | + // an invisible hairline is a feature nobody finds. | ||
| 1296 | + let interact = src_text("interact.rs"); | ||
| 1297 | + assert!( | ||
| 1298 | + interact.contains("cursor_col_resize") && interact.contains("cursor_row_resize"), | ||
| 1299 | + "a divider with no resize cursor on it" | ||
| 1300 | + ); | ||
| 1301 | + // ...and nothing lays a region out off the untouched share any more. | ||
| 1302 | + for (file, stale) in [ | ||
| 1303 | + ("ui/inspector.rs", "inspector_w("), | ||
| 1304 | + ("ui/toolbar.rs", "library_w("), | ||
| 1305 | + ("render.rs", "library_w("), | ||
| 1306 | + ] { | ||
| 1307 | + assert!( | ||
| 1308 | + !src_text(file).contains(stale), | ||
| 1309 | + "{file} still measures a panel with {stale}" | ||
| 1310 | + ); | ||
| 1311 | + } | ||
| 1312 | +} | ||
crates/app/src/ui/inspector.rsmodified+1 -1
| @@ -16,7 +16,7 @@ impl Player { | |||
| 16 | /// is open, which is a section of this panel rather than a sheet over the | 16 | /// is open, which is a section of this panel rather than a sheet over the |
| 17 | /// window. | 17 | /// window. |
| 18 | pub(crate) fn inspector(&self, viewport: Size<Pixels>, cx: &mut Context<Self>) -> impl IntoElement { | 18 | pub(crate) fn inspector(&self, viewport: Size<Pixels>, cx: &mut Context<Self>) -> impl IntoElement { |
| 19 | - let width = inspector_w(f32::from(viewport.width)); | 19 | + let width = self.split_px(Split::Inspector, viewport); |
| 20 | // The cards measure themselves against the room they are given, and the | 20 | // The cards measure themselves against the room they are given, and the |
| 21 | // room they are given is this column -- not the window. | 21 | // room they are given is this column -- not the window. |
| 22 | let room = size(px(width), viewport.height); | 22 | let room = size(px(width), viewport.height); |
crates/app/src/ui/timeline.rsmodified+5 -2
| @@ -13,7 +13,7 @@ impl Player { | |||
| 13 | &self, | 13 | &self, |
| 14 | position: f64, | 14 | position: f64, |
| 15 | state: Transport, | 15 | state: Transport, |
| 16 | - viewport_h: f32, | 16 | + viewport: Size<Pixels>, |
| 17 | cx: &mut Context<Self>, | 17 | cx: &mut Context<Self>, |
| 18 | ) -> impl IntoElement { | 18 | ) -> impl IntoElement { |
| 19 | // Where the playhead is *on the bed*, in pixels from its left edge. | 19 | // Where the playhead is *on the bed*, in pixels from its left edge. |
| @@ -79,7 +79,10 @@ impl Player { | |||
| 79 | // number a scroll is measured against, and the one the affordance below | 79 | // number a scroll is measured against, and the one the affordance below |
| 80 | // counts with. The line it costs is taken off the box before the count, | 80 | // counts with. The line it costs is taken off the box before the count, |
| 81 | // or the row that says "1 more" would be the row hiding it. | 81 | // or the row that says "1 more" would be the row hiding it. |
| 82 | - let region_h = timeline_h(lanes.len()).min(viewport_h * TIMELINE_SHARE); | 82 | + // What the lane count asks for against its share of the window -- or |
| 83 | + // what a hand dragged the seam above to, which wins both | ||
| 84 | + // ([`Player::split_px`]). | ||
| 85 | + let region_h = self.split_px(Split::Timeline, viewport); | ||
| 83 | let lanes_box = (region_h - TIMELINE_FIXED_H).max(LANE_H); | 86 | let lanes_box = (region_h - TIMELINE_FIXED_H).max(LANE_H); |
| 84 | let overflows = lanes.len() > lanes_shown(lanes_box); | 87 | let overflows = lanes.len() > lanes_shown(lanes_box); |
| 85 | let lanes_box = match overflows { | 88 | let lanes_box = match overflows { |
crates/app/src/ui/toolbar.rsmodified+8 -2
| @@ -131,7 +131,7 @@ impl Player { | |||
| 131 | &self, | 131 | &self, |
| 132 | position: f64, | 132 | position: f64, |
| 133 | state: Transport, | 133 | state: Transport, |
| 134 | - viewport_w: f32, | 134 | + viewport: Size<Pixels>, |
| 135 | cx: &mut Context<Self>, | 135 | cx: &mut Context<Self>, |
| 136 | ) -> impl IntoElement { | 136 | ) -> impl IntoElement { |
| 137 | let muted = self.volume.muted; | 137 | let muted = self.volume.muted; |
| @@ -140,7 +140,13 @@ impl Player { | |||
| 140 | // level together do not fit -- so the level's *bar* stands down (its | 140 | // level together do not fit -- so the level's *bar* stands down (its |
| 141 | // button, its keys and its row on the actions card all remain), and | 141 | // button, its keys and its row on the actions card all remain), and |
| 142 | // the clock keeps a narrower rect rather than being pushed off. | 142 | // the clock keeps a narrower rect rather than being pushed off. |
| 143 | - let room = viewport_w - library_w(viewport_w) - inspector_w(viewport_w); | 143 | + // The two panels as they are *now*, dividers and all: a room worked out |
| 144 | + // from the window's own shares would go stale the moment a seam moved, | ||
| 145 | + // and the clock would be sized for a column that is no longer there. | ||
| 146 | + let room = f32::from(viewport.width) | ||
| 147 | + - self.split_px(Split::Library, viewport) | ||
| 148 | + - self.split_px(Split::Inspector, viewport) | ||
| 149 | + - 2. * SPLIT_W; | ||
| 144 | let clock_w = TIME_W.min(room - 140.).max(96.); | 150 | let clock_w = TIME_W.min(room - 140.).max(96.); |
| 145 | let slider = room >= TRANSPORT_ROOMY; | 151 | let slider = room >= TRANSPORT_ROOMY; |
| 146 | div() | 152 | div() |