Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

feat(gui): animate a pane zooming and panes being moved

RoversX7b3150aedb1b
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index d409fcb7..f0f93e8c 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -220,7 +220,7 @@ settings-text-contrast-7 = 7:1
settings-overlay-scrollbar = Bildlaufleiste
settings-overlay-scrollbar-description = Beim Scrollen erscheint am rechten Rand des Fensterbereichs eine schmale Bildlaufleiste, die danach ausblendet; sie lässt sich ziehen.
settings-split-animation = Teilungsanimation
-settings-split-animation-description = Ein neu geteilter Bereich gleitet vom Rand herein und beim Schließen auf demselben Weg hinaus.
+settings-split-animation-description = Ein neu geteilter Bereich gleitet vom Rand herein und beim Schließen auf demselben Weg hinaus. Ein vergrößerter Bereich schiebt die anderen hinaus.
settings-bottom-quote = Zitat am unteren Rand
settings-bottom-quote-description = Zeigt ein kurzes Zitat am unteren Rand des Terminalfensters.
settings-quote-font-size = Schriftgröße des Zitats
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index da1b3224..957c0085 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -220,7 +220,7 @@ settings-text-contrast-7 = 7:1
settings-overlay-scrollbar = Scrollbar
settings-overlay-scrollbar-description = A thin scrollbar appears over the right edge of a pane while it scrolls and fades out afterwards; it can be dragged.
settings-split-animation = Split animation
-settings-split-animation-description = A new split slides in from the edge, and a closed one slides back out.
+settings-split-animation-description = A new split slides in from the edge, and a closed one slides back out. A zoomed pane pushes the others out of the way.
settings-bottom-quote = Bottom Quote
settings-bottom-quote-description = Show a short quote at the bottom of the terminal window.
settings-quote-font-size = Quote Font Size
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index c87047b8..7ac004ba 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -220,7 +220,7 @@ settings-text-contrast-7 = 7:1
settings-overlay-scrollbar = Barre de défilement
settings-overlay-scrollbar-description = Une fine barre de défilement apparaît sur le bord droit du volet pendant le défilement puis disparaît en fondu ; elle peut être glissée.
settings-split-animation = Animation de division
-settings-split-animation-description = Un nouveau volet glisse depuis le bord, et repart du même côté quand on le ferme.
+settings-split-animation-description = Un nouveau volet glisse depuis le bord, et repart du même côté quand on le ferme. Un volet agrandi repousse les autres.
settings-bottom-quote = Citation inférieure
settings-bottom-quote-description = Affiche une courte citation en bas de la fenêtre du terminal.
settings-quote-font-size = Taille de la citation
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index f61c0946..67bf6426 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -217,7 +217,7 @@ settings-text-contrast-7 = 7:1
settings-overlay-scrollbar = スクロールバー
settings-overlay-scrollbar-description = スクロール中はペインの右端に細いスクロールバーが表示され、その後フェードアウトします。ドラッグもできます。
settings-split-animation = 分割アニメーション
-settings-split-animation-description = 新しく分割したペインが端からスライドして入り、閉じると同じ方向へ出ていきます。
+settings-split-animation-description = 新しく分割したペインが端からスライドして入り、閉じると同じ方向へ出ていきます。ペインを拡大すると、ほかのペインを押し出します。
settings-bottom-quote = 下部の引用文
settings-bottom-quote-description = ターミナルウィンドウの下部に短い引用文を表示します。
settings-quote-font-size = 引用文のフォントサイズ
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index f76a383e..c2519a3e 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -217,7 +217,7 @@ settings-text-contrast-7 = 7:1
settings-overlay-scrollbar = 滚动条
settings-overlay-scrollbar-description = 滚动时在面板右侧显示一条细滚动条,停止后自动淡出;可以拖动。
settings-split-animation = 分屏动画
-settings-split-animation-description = 新开分屏时从边上滑进来,关掉时原路滑出去。
+settings-split-animation-description = 新开分屏时从边上滑进来,关掉时原路滑出去;放大窗格时把旁边的推出去。
settings-bottom-quote = 底部语录
settings-bottom-quote-description = 在终端窗口底部显示一条简短语录。
settings-quote-font-size = 语录字号
diff --git a/thinkterm-render/src/quad.rs b/thinkterm-render/src/quad.rs
index a23dc314..28c358fe 100644
--- a/thinkterm-render/src/quad.rs
+++ b/thinkterm-render/src/quad.rs
@@ -375,6 +375,21 @@ impl QuadTrait for BoxedQuad {
}
}
+/// One quad's `verts` translated and cropped to `clip` as a recorded quad is
+/// on replay, for one drawn outside the quad layers -- a picture on a texture
+/// of its own -- that has to go along with them. `None` where none of it is
+/// left.
+pub fn translated_clipped_vertices(
+ verts: &[Vertex; VERTICES_PER_CELL],
+ offset_x: f32,
+ offset_y: f32,
+ clip: QuadClipRect,
+) -> Option<[Vertex; VERTICES_PER_CELL]> {
+ BoxedQuad::from_vertices(verts)
+ .translated_clipped(offset_x, offset_y, clip)
+ .map(|quad| quad.to_vertices())
+}
+
impl BoxedQuad {
fn from_vertices(verts: &[Vertex; VERTICES_PER_CELL]) -> Self {
let [x1, y1] = verts[V_TOP_LEFT].tex;
diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rs
index f3a54617..5d180d13 100644
--- a/wezterm-gui/src/native_settings.rs
+++ b/wezterm-gui/src/native_settings.rs
@@ -591,7 +591,8 @@ pub(crate) struct NativeTerminalSettings {
#[serde(default = "default_true")]
pub(crate) overlay_scrollbar: bool,
/// A pane opened by a split slides in from the side it opened on, and
- /// a closed one goes back out that way.
+ /// a closed one goes back out that way; a zoomed one pushes the others
+ /// out of the tab, and lets them back in.
#[serde(default = "default_true")]
pub(crate) split_animation: bool,
pub(crate) font_size: Option<f64>,
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 5b7a248f..ab927a83 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -3079,6 +3079,8 @@ pub struct TermWindow {
split_slides: render::split_slide::SplitSlides,
/// Set while a closed pane is painted on its way out.
closed_pane_nav: Option<render::split_slide::ClosedNav>,
+ /// Set while a pane carried into another stack is painted on its way.
+ nav_morph: Option<render::split_slide::NavMorph>,
/// A mouse binding took the right button's press: its release does not
/// run the built-in right click as well.
right_press_claimed: bool,
@@ -4843,6 +4845,7 @@ impl TermWindow {
pending_paste: None,
split_slides: Default::default(),
closed_pane_nav: None,
+ nav_morph: None,
right_press_claimed: false,
recording_overlay: Default::default(),
command_palette: None,
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index f04247cb..c6d39b3a 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -1,5 +1,6 @@
use crate::quad::{
- HeapQuadAllocator, HeapQuadMark, QuadClipRect, QuadTrait, TripleLayerQuadAllocator, Vertex,
+ translated_clipped_vertices, HeapQuadAllocator, HeapQuadMark, QuadClipRect, QuadTrait,
+ TripleLayerQuadAllocator, Vertex,
};
use crate::termwindow::content_view::{ContentViewTypography, TerminalPreviewRequest};
use crate::termwindow::render::{LineToEleShapeCacheKey, RenderScreenLineParams};
@@ -12,9 +13,10 @@ use ::window::WindowOps;
use anyhow::Context;
use mux::renderable::{RenderableDimensions, StableCursorPosition};
use crate::termwindow::render::split_slide::{
- self, ClosedNav, Drawn, Leaving, SlideFrame, TabLayout,
+ self, ClosedNav, Drawn, Leaving, MovingPane, Nav, NavMorph, OtherPane, Placed, SlideFrame,
+ TabLayout,
};
-use mux::tab::{PositionedPane, SplitDirection, TabId};
+use mux::tab::{PositionedPane, PositionedSplit, SplitDirection, TabId};
use smol::Timer;
use std::collections::hash_map::DefaultHasher;
use std::collections::HashSet;
@@ -319,6 +321,31 @@ pub(crate) struct ImageCompositeBatch {
pub groups: Vec<ImageComposite>,
}
+/// Where an `ImageCompositeBatch` stood, to take back what was pushed after.
+#[derive(Clone, Copy)]
+pub(crate) struct ImageCompositeMark {
+ verts: usize,
+ groups: usize,
+ /// How many quads its last group had then.
+ last_quads: usize,
+}
+
+/// One quad on a dedicated image texture, taken back from the batch.
+pub(crate) type ImageCompositeQuad = (
+ Rc<crate::termwindow::webgpu::ImageTexture>,
+ ImageCompositeSlot,
+ [Vertex; 4],
+);
+
+/// A pane painted into a recording for a slide to replay where it draws
+/// it, with the pictures it drew on textures of their own: those go to the
+/// window's composite batch, not the recording, and would stay put.
+#[derive(Default)]
+struct RecordedPane {
+ quads: HeapQuadAllocator,
+ images: Vec<ImageCompositeQuad>,
+}
+
impl ImageCompositeBatch {
pub fn push_quad(
&mut self,
@@ -350,6 +377,36 @@ impl ImageCompositeBatch {
self.groups.clear();
}
+ pub fn mark(&self) -> ImageCompositeMark {
+ ImageCompositeMark {
+ verts: self.verts.len(),
+ groups: self.groups.len(),
+ last_quads: self.groups.last().map_or(0, |group| group.quad_count),
+ }
+ }
+
+ /// Take back the quads pushed since `mark`, each with its texture and
+ /// slot.
+ pub fn take_since(&mut self, mark: ImageCompositeMark) -> Vec<ImageCompositeQuad> {
+ let mut taken = vec![];
+ // The last group from before may have taken some of them in.
+ for group in &self.groups[mark.groups.saturating_sub(1)..] {
+ let begin = group.first_vertex.max(mark.verts);
+ let end = group.first_vertex + group.quad_count * 4;
+ for first in (begin..end).step_by(4) {
+ let mut quad: [Vertex; 4] = Default::default();
+ quad.copy_from_slice(&self.verts[first..first + 4]);
+ taken.push((Rc::clone(&group.texture), group.slot, quad));
+ }
+ }
+ self.verts.truncate(mark.verts);
+ self.groups.truncate(mark.groups);
+ if let Some(group) = self.groups.last_mut() {
+ group.quad_count = mark.last_quads;
+ }
+ taken
+ }
+
pub fn max_quad_count(&self) -> usize {
self.groups.iter().map(|g| g.quad_count).max().unwrap_or(0)
}
@@ -1639,6 +1696,7 @@ impl crate::TermWindow {
fn advance_split_slide(
&mut self,
panes: &[PositionedPane],
+ splits: &[PositionedSplit],
now: Instant,
) -> split_slide::Slides {
// A hidden window painted all the same -- a resize finishing, a
@@ -1649,6 +1707,8 @@ impl crate::TermWindow {
return split_slide::Slides {
coming: None,
going: None,
+ zooming: None,
+ rearranging: None,
};
}
let layout = mux::Mux::get()
@@ -1657,10 +1717,15 @@ impl crate::TermWindow {
let slides = self.split_slides.advance(
layout,
panes,
+ splits,
crate::native_settings::split_animation(),
now,
);
- if slides.coming.is_some() || slides.going.is_some() {
+ if slides.coming.is_some()
+ || slides.going.is_some()
+ || slides.zooming.is_some()
+ || slides.rearranging.is_some()
+ {
if let Some(window) = self.window.as_ref() {
window.invalidate();
}
@@ -1675,6 +1740,14 @@ impl crate::TermWindow {
Ok(self.pane_background_rect(pos).union(&self.pane_frame_rect(pos)?))
}
+ /// That, and the corner its text is laid out from.
+ fn split_slide_placed(&self, pos: &PositionedPane) -> anyhow::Result<Placed> {
+ Ok(Placed {
+ rect: self.split_slide_place(pos)?,
+ origin: self.pane_content_origin(pos)?,
+ })
+ }
+
/// Where a slide may draw: the terminal's own part of the window. The
/// ground of a pane along the window's left edge runs on under the
/// sidebar, which covers it; the text and the dividers a slide took in
@@ -1729,6 +1802,78 @@ impl crate::TermWindow {
let place = self.split_slide_place(&leaving.pane)?;
return Ok(SlideFrame::going(leaving, *out, place, &moving, cell, area));
}
+ if let Some((zooming, toward_whole)) = slides.zooming.as_ref() {
+ if let Some(pos) = panes.iter().find(|pos| pos.pane.pane_id() == zooming.pane_id) {
+ // Zoomed, the others are held by the zoom rather than in
+ // the tab's panes.
+ let others = zooming
+ .others
+ .iter()
+ .chain(panes.iter().filter(|other| other.pane.pane_id() != zooming.pane_id))
+ .map(|other| Ok(OtherPane::of(other, self.split_slide_place(other)?)))
+ .collect::<anyhow::Result<Vec<_>>>()?;
+ let (at_place, at_whole) = (zooming.at_place(pos), zooming.at_whole(pos));
+ let nav = match self.pane_nav_band(pos)? {
+ Some((band, buttons)) => {
+ let top_of = |at: &PositionedPane| -> anyhow::Result<f32> {
+ Ok(self
+ .pane_nav_band(at)?
+ .map_or(band.min_y(), |(band, _)| band.min_y()))
+ };
+ Some(Nav {
+ band,
+ buttons,
+ top_from: top_of(&at_place)?,
+ top_to: top_of(&at_whole)?,
+ })
+ }
+ None => None,
+ };
+ return Ok(SlideFrame::zoom(
+ zooming,
+ *toward_whole,
+ self.split_slide_placed(&at_place)?,
+ self.split_slide_placed(&at_whole)?,
+ nav,
+ &others,
+ area,
+ ));
+ }
+ }
+ if let Some((rearranging, along)) = slides.rearranging.as_ref() {
+ let mut moving = vec![];
+ for pane_id in rearranging.moving() {
+ let Some(pos) = panes.iter().find(|pos| pos.pane.pane_id() == pane_id) else {
+ continue;
+ };
+ let Some(was) = rearranging.was(pos) else {
+ continue;
+ };
+ let nav = match self.pane_nav_band(pos)? {
+ Some((band, buttons)) => Some(Nav {
+ band,
+ buttons,
+ top_from: self
+ .pane_nav_band(&was)?
+ .map_or(band.min_y(), |(band, _)| band.min_y()),
+ top_to: band.min_y(),
+ }),
+ None => None,
+ };
+ moving.push(MovingPane::new(
+ pos,
+ self.split_slide_placed(&was)?,
+ self.split_slide_placed(pos)?,
+ nav,
+ ));
+ }
+ let still = self.split_slide_places(panes, |pos| !rearranging.moves(pos))?;
+ let hidden = self.split_slide_places(&rearranging.hidden, |_| true)?;
+ let line = self.render_metrics.underline_height as f32;
+ return Ok(SlideFrame::rearrange(
+ &moving, &still, &hidden, *along, line, area,
+ ));
+ }
Ok(SlideFrame::default())
}
@@ -1748,13 +1893,50 @@ impl crate::TermWindow {
)
}
+ /// Paint `pos` as it stands into a recording, for a slide to replay.
+ fn record_pane(&mut self, pos: &PositionedPane) -> anyhow::Result<RecordedPane> {
+ let images = self.image_composites.borrow().mark();
+ let mut quads = HeapQuadAllocator::default();
+ {
+ let mut layers = TripleLayerQuadAllocator::Heap(&mut quads);
+ self.paint_pane(pos, &mut layers).context("paint_pane")?;
+ if let Ok(frame) = self.pane_mask_frame(pos) {
+ self.paint_pane_recording_masks(pos, frame, &mut layers)?;
+ }
+ }
+ let images = self.image_composites.borrow_mut().take_since(images);
+ Ok(RecordedPane { quads, images })
+ }
+
+ /// Replay `recorded` as a slide's frame draws it, its pictures along.
+ fn replay_pane(
+ &self,
+ recorded: &RecordedPane,
+ layers: &mut TripleLayerQuadAllocator,
+ drawn: Drawn,
+ ) -> anyhow::Result<()> {
+ self.replay_drawn(&recorded.quads, layers, drawn)?;
+ if !recorded.images.is_empty() {
+ let clip = self.clip_of(drawn.clip);
+ let mut batch = self.image_composites.borrow_mut();
+ for (texture, slot, quad) in &recorded.images {
+ if let Some(quad) =
+ translated_clipped_vertices(quad, drawn.shift.0, drawn.shift.1, clip)
+ {
+ batch.push_quad(texture, *slot, quad);
+ }
+ }
+ }
+ Ok(())
+ }
+
/// A closed pane on its way out, painted where it stood, and the
/// divider it goes with. What it registers for the pointer is dropped
/// again: it takes no clicks, its divider no drags.
fn record_leaving_pane(
&mut self,
leaving: &Leaving,
- ) -> anyhow::Result<(HeapQuadAllocator, HeapQuadAllocator)> {
+ ) -> anyhow::Result<(RecordedPane, HeapQuadAllocator)> {
let pos = &leaving.pane;
let ui_items = self.ui_items.len();
// As `can_collapse_pane_stack` had it last frame, when it stood
@@ -1771,21 +1953,14 @@ impl crate::TermWindow {
.iter()
.any(|pane| collapsed(&pane.pane_stack_id))
});
- let mut pane = HeapQuadAllocator::default();
- {
- let mut layers = TripleLayerQuadAllocator::Heap(&mut pane);
- self.closed_pane_nav = Some(ClosedNav {
- pane: Arc::clone(&pos.pane),
- tab: leaving.showed_tab(),
- collapsible,
- });
- let painted = self.paint_pane(pos, &mut layers);
- self.closed_pane_nav = None;
- painted.context("paint_pane")?;
- if let Ok(frame) = self.pane_mask_frame(pos) {
- self.paint_pane_recording_masks(pos, frame, &mut layers)?;
- }
- }
+ self.closed_pane_nav = Some(ClosedNav {
+ pane: Arc::clone(&pos.pane),
+ tab: leaving.showed_tab(),
+ collapsible,
+ });
+ let pane = self.record_pane(pos);
+ self.closed_pane_nav = None;
+ let pane = pane?;
let mut divider = HeapQuadAllocator::default();
if let Some(active) = self.get_active_pane_or_overlay() {
self.paint_split(
@@ -1799,6 +1974,47 @@ impl crate::TermWindow {
Ok((pane, divider))
}
+ /// A pane a move put out of sight in a stack, painted where it stood as
+ /// it was: its nav bar shows itself, not the stack it is in now. What
+ /// it registers for the pointer is dropped again.
+ fn record_hidden_pane(
+ &mut self,
+ pos: &PositionedPane,
+ showed_tab: bool,
+ ) -> anyhow::Result<RecordedPane> {
+ let ui_items = self.ui_items.len();
+ let pane = self.record_pane_alone(pos, showed_tab);
+ self.ui_items.truncate(ui_items);
+ pane
+ }
+
+ /// `pos` painted into a recording with its nav bar showing itself
+ /// alone, if anything, rather than the stack it is in.
+ fn record_pane_alone(
+ &mut self,
+ pos: &PositionedPane,
+ tab: bool,
+ ) -> anyhow::Result<RecordedPane> {
+ self.closed_pane_nav = Some(ClosedNav {
+ pane: Arc::clone(&pos.pane),
+ tab,
+ collapsible: self.can_collapse_pane_stack(pos),
+ });
+ let pane = self.record_pane(pos);
+ self.closed_pane_nav = None;
+ pane
+ }
+
+ /// A pane a zoom pushes out, out of the tab's frames, painted where it
+ /// stood. What it registers for the pointer is dropped again: it is not
+ /// there to click.
+ fn record_pushed_out_pane(&mut self, pos: &PositionedPane) -> anyhow::Result<RecordedPane> {
+ let ui_items = self.ui_items.len();
+ let pane = self.record_pane(pos)?;
+ self.ui_items.truncate(ui_items);
+ Ok(pane)
+ }
+
/// The terminal's ground across the window, as see-through as the window
/// is: the dark interface's, a lone pane's own, or the palette's.
fn window_terminal_ground(&mut self, panes: &[PositionedPane]) -> LinearRgba {
@@ -3353,9 +3569,6 @@ impl crate::TermWindow {
self.paint_drag_ghost_pill(&label, anchor)
}
- /// Translucent preview of where a dragged level-2 pane tab would land
- /// (full pane = move into its stack, half pane = split), plus the
- /// floating tab-title pill. Registers no UIItem (hit-transparent).
/// Reorder drag of a left-sidebar Project/thread row: a 2px accent
/// insert line at the gap releasing would drop into, plus the floating
/// ghost pill with the row's title.
@@ -3409,6 +3622,10 @@ impl crate::TermWindow {
self.paint_drag_ghost_pill(&label, anchor)
}
+ /// Translucent preview of where a dragged level-2 pane tab would land
+ /// (its tab bar = move into its stack, full pane = swap with it, half
+ /// pane = split), plus the floating tab-title pill. Registers no UIItem
+ /// (hit-transparent).
fn paint_pane_tab_drag_overlay(&mut self) -> anyhow::Result<()> {
let Some(state) = self.pane_tab_drag.as_ref() else {
// The drag ended (dropped or cancelled): the layout underneath
@@ -4225,7 +4442,8 @@ impl crate::TermWindow {
self.reconcile_active_mux_tab_size_before_paint();
self.sync_pane_font_sizes();
let panes = self.get_panes_to_render();
- let slides = self.advance_split_slide(&panes, frame_now);
+ let splits = self.get_splits();
+ let slides = self.advance_split_slide(&panes, &splits, frame_now);
let focused = self.focused.is_some();
let window_is_transparent =
!self.window_background.is_empty() || self.config.window_background_opacity != 1.0;
@@ -4398,10 +4616,55 @@ impl crate::TermWindow {
// being active.
for (pane_id, rect) in &slide_frame.fills {
if let Some(pos) = panes.iter().find(|pos| pos.pane.pane_id() == *pane_id) {
- self.paint_room_of(&mut layers, pos, *rect)
+ self.paint_room_of(&mut layers, pos, *rect, slide_frame.fills_shift)
.context("split slide room")?;
}
}
+ for (pane_id, rect) in &slide_frame.grounds {
+ if let Some(pos) = panes.iter().find(|pos| pos.pane.pane_id() == *pane_id) {
+ self.paint_ground_of(&mut layers, pos, *rect)
+ .context("zoom ground")?;
+ }
+ }
+ for (pane_id, rect, nav_shift) in &slide_frame.rooms {
+ if let Some(pos) = panes.iter().find(|pos| pos.pane.pane_id() == *pane_id) {
+ self.paint_room_of(&mut layers, pos, *rect, *nav_shift)
+ .context("rearranged room")?;
+ }
+ }
+ for rect in &slide_frame.backdrop {
+ self.paint_slide_backdrop(&mut layers, *rect)
+ .context("rearranged backdrop")?;
+ }
+ // The panes a zoom pushes out of the tab's frames: painted from
+ // the zoom's hold on them, ahead of the panes, as a closed one is.
+ if let Some((zooming, _)) = slides.zooming.as_ref() {
+ for pos in &zooming.others {
+ if let Some(drawn) = slide_frame.pane(pos) {
+ let recorded = self
+ .record_pushed_out_pane(pos)
+ .context("record pushed out pane")?;
+ self.replay_pane(&recorded, &mut layers, drawn)?;
+ }
+ }
+ }
+ // The panes a move put out of sight in a stack: from its hold
+ // on them, under the panes on their way, until they are covered.
+ if let Some((rearranging, _)) = slides.rearranging.as_ref() {
+ for pos in &rearranging.hidden {
+ let Some(pieces) = slide_frame.pieces(pos).filter(|pieces| !pieces.is_empty())
+ else {
+ continue;
+ };
+ let showed_tab = rearranging.showed_tab(pos.pane.pane_id());
+ let recorded = self
+ .record_hidden_pane(pos, showed_tab)
+ .context("record hidden pane")?;
+ for drawn in pieces {
+ self.replay_pane(&recorded, &mut layers, *drawn)?;
+ }
+ }
+ }
for pos in panes {
if pos.is_active {
if focused {
@@ -4409,18 +4672,32 @@ impl crate::TermWindow {
mux::Mux::get().record_focus_for_current_identity(pos.pane.pane_id());
}
}
- match slide_frame.pane(&pos) {
- Some(drawn) => {
- let mut recorded = HeapQuadAllocator::default();
- {
- let mut pane_layers = TripleLayerQuadAllocator::Heap(&mut recorded);
- self.paint_pane(&pos, &mut pane_layers)
- .context("paint_pane")?;
- if let Ok(frame) = self.pane_mask_frame(&pos) {
- self.paint_pane_recording_masks(&pos, frame, &mut pane_layers)?;
- }
+ let drawn = slide_frame.pane(&pos);
+ let pieces = match (slide_frame.pieces(&pos), drawn.as_ref()) {
+ (Some(pieces), _) => Some(pieces),
+ (None, drawn) => drawn.map(std::slice::from_ref),
+ };
+ match pieces {
+ Some(pieces) => {
+ // One on its way into another stack goes from the
+ // tabs it showed to the stack's along the way.
+ self.nav_morph =
+ slides.rearranging.as_ref().and_then(|(rearranging, along)| {
+ let (from_lead, from) =
+ rearranging.tabs_before(pos.pane.pane_id())?;
+ Some(NavMorph {
+ pane_id: pos.pane.pane_id(),
+ from: from.to_vec(),
+ from_lead,
+ along: *along,
+ })
+ });
+ let recorded = self.record_pane(&pos);
+ self.nav_morph = None;
+ let recorded = recorded?;
+ for drawn in pieces {
+ self.replay_pane(&recorded, &mut layers, *drawn)?;
}
- self.replay_drawn(&recorded, &mut layers, drawn)?;
}
None => {
self.paint_pane(&pos, &mut layers).context("paint_pane")?;
@@ -4431,7 +4708,7 @@ impl crate::TermWindow {
}
}
if let Some(((pane, _), (drawn, _))) = going.as_ref() {
- self.replay_drawn(pane, &mut layers, *drawn)?;
+ self.replay_pane(pane, &mut layers, *drawn)?;
}
// Part of the terminal, gone with the panes wherever they are:
@@ -4440,8 +4717,26 @@ impl crate::TermWindow {
self.paint_terminal_bar(&mut layers)
.context("paint_terminal_bar")?;
if let Some(pane) = self.get_active_pane_or_overlay() {
- let splits = self.get_splits();
for split in &splits {
+ // Panes rearranged: clear of those on their way, and of
+ // where each stood and goes.
+ if let Some(clips) = slide_frame.divider_clips() {
+ let mut recorded = HeapQuadAllocator::default();
+ self.paint_split(
+ &mut TripleLayerQuadAllocator::Heap(&mut recorded),
+ split,
+ &pane,
+ )
+ .context("paint_split")?;
+ for clip in clips {
+ let drawn = Drawn {
+ shift: (0., 0.),
+ clip: *clip,
+ };
+ self.replay_drawn(&recorded, &mut layers, drawn)?;
+ }
+ continue;
+ }
match slide_frame.split(split) {
// Along with the panes either side of it.
Some(drawn) => {
@@ -4459,6 +4754,32 @@ impl crate::TermWindow {
.context("paint_split")?,
}
}
+ // The edges of the panes on their way, where no divider is.
+ if !slide_frame.edges.is_empty() {
+ let color = pane.palette().split.to_linear();
+ for edge in &slide_frame.edges {
+ self.filled_rectangle(&mut layers, 2, *edge, color)
+ .context("rearranged edge")?;
+ }
+ }
+ // Those between the panes a zoom pushes out are out of the
+ // tab's too: from the zoom's hold, taking no drags.
+ if let Some((zooming, _)) = slides.zooming.as_ref() {
+ let ui_items = self.ui_items.len();
+ for split in &zooming.dividers {
+ if let Some(drawn) = slide_frame.split(split) {
+ let mut recorded = HeapQuadAllocator::default();
+ self.paint_split(
+ &mut TripleLayerQuadAllocator::Heap(&mut recorded),
+ split,
+ &pane,
+ )
+ .context("paint_split")?;
+ self.replay_drawn(&recorded, &mut layers, drawn)?;
+ }
+ }
+ self.ui_items.truncate(ui_items);
+ }
}
if let Some(((_, divider), (_, drawn))) = going.as_ref() {
self.replay_drawn(divider, &mut layers, *drawn)?;
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index 803df99c..157f6ad6 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -31,6 +31,7 @@ use anyhow::Context;
use config::VisualBellTarget;
use mux::pane::{PaneId, WithPaneLines};
use mux::renderable::{RenderableDimensions, StableCursorPosition};
+use crate::termwindow::render::split_slide::TabPlace;
use mux::tab::{CollapsedPaneLayout, PaneStackTab, PositionedPane, SplitDirection};
use mux::Mux;
use ordered_float::NotNan;
@@ -196,6 +197,35 @@ impl crate::TermWindow {
.saturating_add(self.ui_px(PANE_NAV_INSET))
}
+ /// The band `pos`'s nav bar runs along, and where along it the buttons
+ /// at its end start; `None` without one, or for a stack collapsed to a
+ /// strip, which is all nav bar.
+ pub(crate) fn pane_nav_band(
+ &self,
+ pos: &PositionedPane,
+ ) -> anyhow::Result<Option<(RectF, f32)>> {
+ let nav_height = self.pane_nav_bar_height_for_pane(pos);
+ if nav_height == 0
+ || pos.width == 0
+ || self.collapsed_pane_layouts.contains_key(&pos.pane_stack_id)
+ {
+ return Ok(None);
+ }
+ let (_, pane_y) = self.pane_content_origin(pos)?;
+ let (pane_x, pane_width) = self.pane_chrome_span(pos)?;
+ let buttons = pane_x + pane_width
+ - self.pane_nav_action_reserved_width(pos, nav_height) as f32;
+ Ok(Some((
+ euclid::rect(
+ pane_x,
+ pane_y - self.pane_nav_lift(pos),
+ pane_width,
+ nav_height as f32,
+ ),
+ buttons.max(pane_x),
+ )))
+ }
+
/// Horizontal room the *collapsed* strip leaves for its tabs.
///
/// The expanded bar's `pane_nav_tab_viewport_width` does not describe this
@@ -250,7 +280,7 @@ impl crate::TermWindow {
.saturating_sub(self.right_sidebar_width()) as f32
}
- fn pane_content_origin(&self, pos: &PositionedPane) -> anyhow::Result<(f32, f32)> {
+ pub(crate) fn pane_content_origin(&self, pos: &PositionedPane) -> anyhow::Result<(f32, f32)> {
let (top_bar_height, _) = self.pane_area_insets();
let border = self.get_os_border();
let (padding_left, _) = self.padding_left_top();
@@ -448,19 +478,21 @@ impl crate::TermWindow {
}
/// Fill `rect` as `pos` fills its own room: in its nav bar's colour
- /// across the rows that takes, and with its ground above and below.
+ /// across the rows that takes, drawn `nav_shift` further down than it
+ /// stands, and with its ground above and below.
pub(crate) fn paint_room_of(
&self,
layers: &mut TripleLayerQuadAllocator,
pos: &PositionedPane,
rect: RectF,
+ nav_shift: f32,
) -> anyhow::Result<()> {
let nav_height = self.pane_nav_bar_height_for_pane(pos) as f32;
let band = if nav_height > 0.0
&& !self.collapsed_pane_layouts.contains_key(&pos.pane_stack_id)
{
let (_, pane_y) = self.pane_content_origin(pos)?;
- let top = pane_y - self.pane_nav_lift(pos);
+ let top = pane_y - self.pane_nav_lift(pos) + nav_shift;
euclid::rect(rect.min_x(), top, rect.width(), nav_height).intersection(&rect)
} else {
None
@@ -487,6 +519,27 @@ impl crate::TermWindow {
Ok(())
}
+ /// Fill `rect`, room no pane covers while panes are rearranged, in the
+ /// ground the sidebar has, darker than a pane's: the panes are seen to
+ /// cross it. With a background image the panes leave their ground
+ /// unfilled, and the picture shows here too.
+ pub(crate) fn paint_slide_backdrop(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ rect: RectF,
+ ) -> anyhow::Result<()> {
+ if !self.window_background.is_empty() || rect.is_empty() {
+ return Ok(());
+ }
+ self.filled_rectangle(
+ layers,
+ 0,
+ rect,
+ self.chrome_surface(self.chrome().workspace_sidebar_bg),
+ )?;
+ Ok(())
+ }
+
/// The pane's rectangle without that lift. Recording masks are kept as
/// fractions of it, so it has to move with the pane's rows when a
/// terminal bar comes or goes, as the whole frame did before the lift.
@@ -936,7 +989,7 @@ impl crate::TermWindow {
tabs
}
- fn can_collapse_pane_stack(&self, pos: &PositionedPane) -> bool {
+ pub(crate) fn can_collapse_pane_stack(&self, pos: &PositionedPane) -> bool {
if let Some(nav) = self
.closed_pane_nav
.as_ref()
@@ -1088,15 +1141,71 @@ impl crate::TermWindow {
|| self.tab_wheel_scroll_active();
let tab_height = button_size;
let tab_y = button_y;
- for (idx, tab) in tabs.into_iter().enumerate() {
+ // Where along the bar the first tab stands, scrolled: a pane carried
+ // into another stack goes on from where its tabs stood here.
+ let lead = tab_start as f32 - scroll_offset - pane_x;
+ self.split_slides
+ .nav(pos.pane.pane_id(), lead, tabs.iter().map(|tab| tab.pane_id));
+ // One carried goes from the tabs it showed to its new stack's on its
+ // way there (see `render::split_slide`).
+ let morph = self
+ .nav_morph
+ .as_ref()
+ .filter(|morph| morph.pane_id == pos.pane.pane_id());
+ let places = match morph {
+ Some(morph) => {
+ let from_width = self
+ .adaptive_tab_width(morph.from.len(), viewport_width as f32, tab_gap as f32)
+ .ceil() as usize;
+ let to: Vec<PaneId> = tabs.iter().map(|tab| tab.pane_id).collect();
+ morph.places(&to, (from_width + tab_gap) as f32, tab_step as f32, lead)
+ }
+ None => tabs
+ .iter()
+ .enumerate()
+ .map(|(idx, tab)| TabPlace {
+ pane_id: tab.pane_id,
+ x: lead + idx.saturating_mul(tab_step) as f32,
+ opacity: 1.0,
+ kept: true,
+ })
+ .collect(),
+ };
+ // Where the tabs drawn whole stand while one is carried: one fading
+ // in or out is cut short of them, its title in the layer over their
+ // capsules.
+ let whole: Vec<f32> = match morph {
+ Some(_) => places
+ .iter()
+ .filter(|place| place.kept && place.opacity >= 1.0)
+ .map(|place| pane_x + place.x)
+ .collect(),
+ None => vec![],
+ };
+ for place in places {
if tab_width <= icon_size + self.ui_px(PANE_NAV_ICON_GAP) + button_size
|| viewport_width == 0
{
break;
}
+ // One left behind is no longer in the stack, and fades out.
+ let left_behind;
+ let tab = match tabs.iter().find(|tab| tab.pane_id == place.pane_id) {
+ Some(tab) => tab,
+ None => match Mux::get().get_pane(place.pane_id) {
+ Some(pane) => {
+ left_behind = PaneStackTab {
+ pane_id: place.pane_id,
+ title: pane.title_without_waiting(),
+ is_active: false,
+ };
+ &left_behind
+ }
+ None => continue,
+ },
+ };
- let virtual_x = idx.saturating_mul(tab_step) as f32;
- let tab_left = tab_start as f32 + virtual_x - scroll_offset;
+ let tab_left = pane_x + place.x;
let tab_right = tab_left + tab_width as f32;
if tab_right <= tab_start as f32 || tab_left >= max_tab_right as f32 {
continue;
@@ -1108,13 +1217,34 @@ impl crate::TermWindow {
if visible_width <= 1.0 {
continue;
}
+ // Drawn within the strip, a shadow and all; one fading, only
+ // where the tabs drawn whole leave it.
+ let (mut shown_left, mut shown_right) = (tab_start as f32, max_tab_right as f32);
+ if place.opacity < 1.0 || !place.kept {
+ (shown_left, shown_right) = (visible_left, visible_right);
+ for other in &whole {
+ let other_right = other + tab_width as f32;
+ if other_right <= shown_left || *other >= shown_right {
+ continue;
+ }
+ if other - shown_left >= shown_right - other_right {
+ shown_right = shown_right.min(*other);
+ } else {
+ shown_left = shown_left.max(other_right);
+ }
+ }
+ if shown_right - shown_left <= 1.0 {
+ continue;
+ }
+ }
let selected_tab = tab.is_active;
let is_renaming_tab = self.is_renaming_pane_nav_tab(tab.pane_id);
let this_tab_fg = if selected_tab { tab_fg } else { muted_fg };
let hover_x = visible_left.max(0.0) as usize;
let hover_width = visible_width.max(0.0) as usize;
- let is_hovered = !suppress_hover
+ let is_hovered = place.kept
+ && !suppress_hover
&& self.is_pointer_over_ui_rect(hover_x, tab_y, hover_width, tab_height);
let tab_surface_color = if selected_tab {
chrome.active_tab_surface()
@@ -1128,17 +1258,19 @@ impl crate::TermWindow {
} else {
LinearRgba::TRANSPARENT
};
- self.ui_items.push(UIItem {
- x: visible_left.max(0.0) as usize,
- y: tab_y,
- width: visible_width.max(0.0) as usize,
- height: tab_height,
- item_type: UIItemType::PaneNav {
- pane_id: pos.pane.pane_id(),
- pane_index: pos.index,
- action: PaneNavAction::Activate(tab.pane_id),
- },
- });
+ if place.kept {
+ self.ui_items.push(UIItem {
+ x: visible_left.max(0.0) as usize,
+ y: tab_y,
+ width: visible_width.max(0.0) as usize,
+ height: tab_height,
+ item_type: UIItemType::PaneNav {
+ pane_id: pos.pane.pane_id(),
+ pane_index: pos.index,
+ action: PaneNavAction::Activate(tab.pane_id),
+ },
+ });
+ }
// Reborrow: the surrounding loop cannot move the caller's `&mut`.
let out_layers = &mut *layers;
@@ -1305,13 +1437,13 @@ impl crate::TermWindow {
tab_left,
0.0,
QuadClipRect::from_top_left_pixels(
- tab_start as f32,
+ shown_left,
tab_y as f32,
- max_tab_right as f32,
+ shown_right,
(tab_y + tab_height) as f32,
&self.dimensions,
),
- 1.0,
+ place.opacity,
)
.context("pane nav tab content")?;
}
diff --git a/wezterm-gui/src/termwindow/render/split_slide.rs b/wezterm-gui/src/termwindow/render/split_slide.rs
index 27dcdd63..d5a716b6 100644
--- a/wezterm-gui/src/termwindow/render/split_slide.rs
+++ b/wezterm-gui/src/termwindow/render/split_slide.rs
@@ -22,10 +22,30 @@
//! to a pane that used to cover the ground it now stands on. A closed pane
//! is read off it backwards: one pane fewer, nobody new, and a pane that
//! stood beside it covering its ground.
+//!
+//! A pane zoomed to the whole tab grows out of its place and pushes the
+//! others out past the tab's edges, each the way it lies from it; let back
+//! down, it shrinks into its place and they come back in. Here too the
+//! zoom has given the pane its size by then, once: its text goes along
+//! with its top left corner, the buttons at the end of its nav bar with its
+//! right edge. The others keep theirs, and are only moved. Zoomed, they are
+//! out of the tab's frames, and are painted from last frame's on their way
+//! out.
+//!
+//! A pane carried to another place in the tab -- dropped beside another,
+//! into another's stack or out of its own, swapped with another -- goes
+//! there from where it stood, over the others, and the panes that make way
+//! for it or take its room go to theirs at the same time. Each is drawn as
+//! a zoomed one is, laid out once where it goes. Room none of them covers
+//! yet shows a darker ground, the panes crossing it like cards. One that
+//! goes out of sight into a stack stays where it stood, under them, as
+//! last painted; one that comes out of a stack is where it stands. The
+//! move is read off the layout too: the same panes in the tab, one of them
+//! in another stack than it was.
use ::window::RectF;
use mux::pane::{Pane, PaneId};
-use mux::tab::{PositionedPane, PositionedSplit, SplitDirection, TabId};
+use mux::tab::{PaneStackId, PositionedPane, PositionedSplit, SplitDirection, TabId};
use std::sync::Arc;
use std::time::{Duration, Instant};
@@ -224,14 +244,31 @@ impl CellRect {
fn cols_overlap(&self, other: &Self) -> bool {
self.left < other.right() && other.left < self.right()
}
+
+
+ /// `pos` standing here instead.
+ fn at(&self, pos: &PositionedPane) -> PositionedPane {
+ let scaled = |pixels: usize, cells: usize, to: usize| pixels * to / cells.max(1);
+ PositionedPane {
+ left: self.left,
+ top: self.top,
+ width: self.width,
+ height: self.height,
+ pixel_width: scaled(pos.pixel_width, pos.width, self.width),
+ pixel_height: scaled(pos.pixel_height, pos.height, self.height),
+ ..pos.clone()
+ }
+ }
}
-/// The panes a tab showed in one frame.
+/// The panes a tab showed in one frame, each with the stack it is the
+/// shown one of.
#[derive(Debug, PartialEq, Eq)]
pub struct TabLayout {
tab_id: TabId,
zoomed: bool,
- panes: Vec<(PaneId, CellRect)>,
+ panes: Vec<(PaneId, CellRect, PaneStackId)>,
+ active: Option<PaneId>,
}
impl TabLayout {
@@ -241,23 +278,158 @@ impl TabLayout {
zoomed: panes.iter().any(|pos| pos.is_zoomed),
panes: panes
.iter()
- .map(|pos| (pos.pane.pane_id(), CellRect::of(pos)))
+ .map(|pos| (pos.pane.pane_id(), CellRect::of(pos), pos.pane_stack_id))
.collect(),
+ active: panes
+ .iter()
+ .find(|pos| pos.is_active)
+ .map(|pos| pos.pane.pane_id()),
}
}
fn rect(&self, pane_id: PaneId) -> Option<CellRect> {
self.panes
.iter()
- .find(|(id, _)| *id == pane_id)
- .map(|(_, rect)| *rect)
+ .find(|(id, _, _)| *id == pane_id)
+ .map(|(_, rect, _)| *rect)
+ }
+
+ /// Whether one of its panes is the shown one of `stack`.
+ fn shows(&self, stack: PaneStackId) -> bool {
+ self.panes.iter().any(|(_, _, shown)| *shown == stack)
+ }
+
+ fn stack_of(&self, pane_id: PaneId) -> Option<PaneStackId> {
+ self.panes
+ .iter()
+ .find(|(id, _, _)| *id == pane_id)
+ .map(|(_, _, stack)| *stack)
+ }
+
+ /// The panes `self` has elsewhere than `before` had them, by one carried
+ /// to another place in the tab: each with where it stood, the one
+ /// carried first; and those `before` showed that went out of sight into
+ /// a stack still shown, by their place in `before`. A carry puts panes
+ /// out of sight or in sight within their stacks, or changes how the
+ /// panes lie from one another: one that was beside another is now over
+ /// it. What else moves panes -- a divider dragged, the window resized --
+ /// leaves them lying as they did; what adds or takes away a pane has one
+ /// new to the tab or one gone from it. Stack ids alone do not tell: a
+ /// client's resync gives a stack of one pane a new one every time.
+ fn rearranged(&self, before: &Self) -> Option<Rearranged> {
+ if self.tab_id != before.tab_id || self.zoomed || before.zoomed {
+ return None;
+ }
+ // Each shown on one side is shown, or out of sight in a stack
+ // shown, on the other.
+ let new = self
+ .panes
+ .iter()
+ .any(|(id, _, stack)| before.rect(*id).is_none() && !before.shows(*stack));
+ let gone = before
+ .panes
+ .iter()
+ .any(|(id, _, stack)| self.rect(*id).is_none() && !self.shows(*stack));
+ if new || gone {
+ return None;
+ }
+ let mut moved: Vec<(PaneId, CellRect)> = self
+ .panes
+ .iter()
+ .filter_map(|(id, now, _)| {
+ let was = before.rect(*id)?;
+ (was != *now).then_some((*id, was))
+ })
+ .collect();
+ let hidden: Vec<usize> = before
+ .panes
+ .iter()
+ .enumerate()
+ .filter(|(_, (id, _, _))| self.rect(*id).is_none())
+ .map(|(index, _)| index)
+ .collect();
+ // A pane out of sight or in sight in a stack counts where the pane
+ // that stack shows on the other side is on its way: one carried in
+ // or out. Another tab of a strip expanded only shows in turn.
+ let moves = |pane_id: PaneId| moved.iter().any(|(id, _)| *id == pane_id);
+ let shown_in = |layout: &Self, stack: PaneStackId| {
+ layout
+ .panes
+ .iter()
+ .find(|(_, _, shown)| *shown == stack)
+ .map(|(id, _, _)| *id)
+ };
+ let carried_off = hidden
+ .iter()
+ .any(|index| shown_in(self, before.panes[*index].2).is_some_and(moves));
+ let carried_in = self.panes.iter().any(|(id, _, stack)| {
+ before.rect(*id).is_none() && shown_in(before, *stack).is_some_and(moves)
+ });
+ if moved.is_empty() || !(carried_off || carried_in || self.relaid(before)) {
+ return None;
+ }
+ // The ones carried first, in another stack than they were; of two
+ // swapped, the one the move left active. A move asked for from
+ // outside the window may leave its active pane as it was, and come
+ // with every stack of one pane renamed: then the one that went
+ // furthest.
+ moved.sort_by_key(|(id, was)| {
+ let now = self.rect(*id).unwrap_or(*was);
+ let (dx, dy) = (
+ (now.left * 2 + now.width) as isize - (was.left * 2 + was.width) as isize,
+ (now.top * 2 + now.height) as isize - (was.top * 2 + was.height) as isize,
+ );
+ (
+ before.stack_of(*id) == self.stack_of(*id),
+ Some(*id) != self.active,
+ std::cmp::Reverse(dx * dx + dy * dy),
+ )
+ });
+ let carried = moved
+ .iter()
+ .map(|(id, _)| *id)
+ .filter(|id| before.stack_of(*id) != self.stack_of(*id))
+ .collect();
+ Some(Rearranged {
+ moved,
+ hidden,
+ carried,
+ })
+ }
+
+ /// Whether two panes shown on both sides lie otherwise from one another
+ /// in `self` than in `before`: side by side then, one over the other
+ /// now, or the other way round. Two that keep one way they lie -- left
+ /// of the other both times, say -- have not: a divider dragged between
+ /// two others can put a corner of one past a corner of the other.
+ fn relaid(&self, before: &Self) -> bool {
+ let lies = |rect: CellRect, other: CellRect| {
+ [
+ rect.right() <= other.left,
+ other.right() <= rect.left,
+ rect.bottom() <= other.top,
+ other.bottom() <= rect.top,
+ ]
+ };
+ self.panes.iter().enumerate().any(|(index, (id, now, _))| {
+ self.panes[index + 1..].iter().any(|(other_id, other_now, _)| {
+ match (before.rect(*id), before.rect(*other_id)) {
+ (Some(was), Some(other_was)) => {
+ let (then, now) = (lies(was, other_was), lies(*now, *other_now));
+ !then.iter().zip(&now).any(|(then, now)| *then && *now)
+ }
+ _ => false,
+ }
+ })
+ })
}
/// The pane `self` gained over `before` by a split, the edge it comes
/// in from and a pane that made room for it. Anything else that adds a
/// pane -- a tab switched to, a zoom let go of, an overlay closed -- also
/// changes or removes one that was there, or leaves no neighbour that
- /// gave up the room.
+ /// gave up the room. A pane dragged out of its stack leaves another of
+ /// the stack shown where it was: that one was in the tab all along.
fn opened_by_split(&self, before: &Self) -> Option<(PaneId, Edge, PaneId)> {
if self.tab_id != before.tab_id
|| self.zoomed
@@ -268,16 +440,19 @@ impl TabLayout {
return None;
}
let mut new = None;
- for (id, rect) in &self.panes {
+ for (id, rect, stack) in &self.panes {
if before.rect(*id).is_none() {
if new.is_some() {
return None;
}
- new = Some((*id, *rect));
+ new = Some((*id, *rect, *stack));
}
}
- let (new_id, new) = new?;
- self.panes.iter().find_map(|(id, now)| {
+ let (new_id, new, stack) = new?;
+ if before.shows(stack) {
+ return None;
+ }
+ self.panes.iter().find_map(|(id, now, _)| {
let was = before.rect(*id)?;
// It stood where the new pane is now, and gave that up.
if was == *now || !was.overlaps(&new) {
@@ -301,7 +476,8 @@ impl TabLayout {
/// The pane `before` had that `self` lost by its closing, as its place
/// in `before`, and the edge it goes out by: away from the panes that
/// took its room. A tab switched away from or a zoom changes the tab or
- /// zooms it; an overlay puts another pane where one was.
+ /// zooms it; an overlay puts another pane where one was. A pane dropped
+ /// into another's stack hides that one behind it, in a stack still shown.
fn closed(&self, before: &Self) -> Option<(usize, Edge)> {
if self.tab_id != before.tab_id
|| self.zoomed
@@ -312,16 +488,19 @@ impl TabLayout {
return None;
}
let mut gone = None;
- for (index, (id, rect)) in before.panes.iter().enumerate() {
+ for (index, (id, rect, stack)) in before.panes.iter().enumerate() {
if self.rect(*id).is_none() {
if gone.is_some() {
return None;
}
- gone = Some((index, *rect));
+ gone = Some((index, *rect, *stack));
}
}
- let (index, gone) = gone?;
- self.panes.iter().find_map(|(id, now)| {
+ let (index, gone, stack) = gone?;
+ if self.shows(stack) {
+ return None;
+ }
+ self.panes.iter().find_map(|(id, now, _)| {
let was = before.rect(*id)?;
// It stood beside the closed pane, and has its ground now.
if was == *now || !now.overlaps(&gone) {
@@ -342,13 +521,41 @@ impl TabLayout {
})
}
+ /// The pane zoomed to the whole tab between `before` and `self`, or let
+ /// back down among the others, and which of the two: `true` zoomed. A
+ /// tab switched to or from zoomed changes the tab; a pane alone in its
+ /// tab already had all of it.
+ fn zoom(&self, before: &Self) -> Option<(PaneId, bool)> {
+ if self.tab_id != before.tab_id || self.zoomed == before.zoomed {
+ return None;
+ }
+ let (zoomed, all) = if self.zoomed {
+ (self, before)
+ } else {
+ (before, self)
+ };
+ let &[(pane_id, whole, _)] = zoomed.panes.as_slice() else {
+ return None;
+ };
+ let place = all.rect(pane_id)?;
+ (all.panes.len() > 1 && place != whole).then_some((pane_id, self.zoomed))
+ }
+
+ /// The cells its panes cover between them: the whole tab.
+ fn bounds(&self) -> Option<CellRect> {
+ self.panes
+ .iter()
+ .map(|(_, rect, _)| *rect)
+ .reduce(|all, rect| all.union(&rect))
+ }
+
/// The panes that moved over between `before` and `self` for a slide
/// through `edge` (see `Edge::moved`). The mux keeps the size of the
/// first of two panes and puts what changes on the second, so they move
/// as one block, all by as much.
fn moved(&self, before: &Self, edge: Edge, towards: bool) -> Option<Moved> {
let mut moved: Option<Moved> = None;
- for (id, now) in &self.panes {
+ for (id, now, _) in &self.panes {
let Some(was) = before.rect(*id) else {
continue;
};
@@ -377,6 +584,15 @@ struct Moved {
by: usize,
}
+/// See `TabLayout::rearranged`.
+#[derive(Debug, PartialEq, Eq)]
+struct Rearranged {
+ moved: Vec<(PaneId, CellRect)>,
+ hidden: Vec<usize>,
+ /// Those of `moved` in another stack than they were.
+ carried: Vec<PaneId>,
+}
+
/// A slide under way.
#[derive(Clone, Copy, Debug)]
pub struct SplitSlide {
@@ -462,6 +678,131 @@ impl Leaving {
}
}
+/// A pane zoomed to the whole tab, or let back down into its place, on its
+/// way there.
+#[derive(Clone, Debug)]
+pub struct Zooming<P = PositionedPane> {
+ pub pane_id: PaneId,
+ /// Zoomed, rather than let back down.
+ zoomed: bool,
+ /// Its place among the others.
+ place: CellRect,
+ /// The whole tab.
+ whole: CellRect,
+ /// Zoomed, the others and the dividers between them are out of the
+ /// tab's frames: as last painted, to paint them on their way out from.
+ pub others: Vec<P>,
+ pub dividers: Vec<PositionedSplit>,
+ tab_id: TabId,
+ started: Instant,
+ /// Frames shown with it so far.
+ shown: u32,
+ /// Times painted with it so far, shown or not.
+ paints: u32,
+}
+
+impl<P> Zooming<P> {
+ /// How far from its place towards the whole tab it is drawn, from 0 to
+ /// 1; `None` once it is where it goes.
+ fn toward_whole(&self, now: Instant) -> Option<f32> {
+ progress(self.started, self.shown, DURATION, now)
+ .map(ease_out)
+ .map(|t| if self.zoomed { t } else { 1.0 - t })
+ }
+
+ /// Have it set out from `toward_whole` of the way there a frame before
+ /// `now`: from where one the other way, taken back on its way, had got
+ /// to, rather than from its start.
+ fn set_out_from(&mut self, toward_whole: f32, now: Instant) {
+ // `toward_whole` played backwards.
+ let left = if self.zoomed {
+ 1.0 - toward_whole
+ } else {
+ toward_whole
+ };
+ let t = (1.0 - left.clamp(0.0, 1.0).sqrt()).clamp(0.0, 1.0);
+ self.started = now.checked_sub(DURATION.mul_f32(t)).unwrap_or(now);
+ self.shown = (t * MIN_FRAMES as f32).ceil() as u32;
+ }
+}
+
+impl Zooming {
+ /// `pos`, the pane on its way, standing in its place among the others.
+ pub fn at_place(&self, pos: &PositionedPane) -> PositionedPane {
+ self.place.at(pos)
+ }
+
+ /// `pos` standing over the whole tab.
+ pub fn at_whole(&self, pos: &PositionedPane) -> PositionedPane {
+ self.whole.at(pos)
+ }
+}
+
+/// Panes rearranged by one carried to another place in the tab, on their
+/// way from where they stood.
+#[derive(Clone, Debug)]
+pub struct Rearranging<P = PositionedPane> {
+ /// The panes on their way and where each stood, the one carried first.
+ moved: Vec<(PaneId, CellRect)>,
+ /// Those gone out of sight into a stack, as last painted, where they
+ /// stood: under the others until they are covered.
+ pub hidden: Vec<P>,
+ /// Those of them whose nav bar showed no tab.
+ bare: Vec<PaneId>,
+ /// The panes on their way into another stack, each with the tabs its
+ /// nav bar showed and where the first of them stood, if it was painted:
+ /// it goes from those to its new stack's on the way.
+ carried: Vec<(PaneId, Option<f32>, Vec<PaneId>)>,
+ tab_id: TabId,
+ started: Instant,
+ /// Frames shown with it so far.
+ shown: u32,
+ /// Times painted with it so far, shown or not.
+ paints: u32,
+}
+
+impl<P> Rearranging<P> {
+ /// How far from where they stood to where they stand the panes are
+ /// drawn, from 0 to 1; `None` once they are there.
+ fn along(&self, now: Instant) -> Option<f32> {
+ progress(self.started, self.shown, DURATION, now).map(ease_out)
+ }
+
+ /// The panes on their way, the one carried first.
+ pub fn moving(&self) -> impl Iterator<Item = PaneId> + '_ {
+ self.moved.iter().map(|(pane_id, _)| *pane_id)
+ }
+
+ /// Whether the nav bar of `pane_id`, out of sight now, showed its tab.
+ pub fn showed_tab(&self, pane_id: PaneId) -> bool {
+ !self.bare.contains(&pane_id)
+ }
+
+ /// The tabs the nav bar of `pane_id` showed, and where the first stood
+ /// along it, if it is on its way into another stack.
+ pub fn tabs_before(&self, pane_id: PaneId) -> Option<(Option<f32>, &[PaneId])> {
+ self.carried
+ .iter()
+ .find(|(carried, _, _)| *carried == pane_id)
+ .map(|(_, lead, tabs)| (*lead, tabs.as_slice()))
+ }
+}
+
+impl Rearranging {
+ /// Whether `pos` is on its way.
+ pub fn moves(&self, pos: &PositionedPane) -> bool {
+ self.moving().any(|pane_id| pane_id == pos.pane.pane_id())
+ }
+
+ /// `pos` standing where it stood, if it is on its way.
+ pub fn was(&self, pos: &PositionedPane) -> Option<PositionedPane> {
+ self.moved
+ .iter()
+ .find(|(pane_id, _)| *pane_id == pos.pane.pane_id())
+ .map(|(_, was)| was.at(pos))
+ }
+}
+
/// How far through a slide lasting `duration` is, from 0 to 1, in the
/// frame after `shown` frames; `None` once it is over.
fn progress(started: Instant, shown: u32, duration: Duration, now: Instant) -> Option<f32> {
@@ -538,6 +879,283 @@ fn beyond(edge: Edge, rect: RectF, area: RectF) -> RectF {
euclid::rect(left, top, (right - left).max(0.), (bottom - top).max(0.))
}
+/// `t` of the way from `from` to `to`.
+fn lerp(from: f32, to: f32, t: f32) -> f32 {
+ from + (to - from) * t
+}
+
+/// `t` of the way from `from` to `to`, each side.
+fn between(from: RectF, to: RectF, t: f32) -> RectF {
+ let left = lerp(from.min_x(), to.min_x(), t);
+ let top = lerp(from.min_y(), to.min_y(), t);
+ euclid::rect(
+ left,
+ top,
+ lerp(from.max_x(), to.max_x(), t) - left,
+ lerp(from.max_y(), to.max_y(), t) - top,
+ )
+}
+
+fn translated(rect: RectF, (dx, dy): (f32, f32)) -> RectF {
+ euclid::rect(rect.min_x() + dx, rect.min_y() + dy, rect.width(), rect.height())
+}
+
+/// The rows of `rect` from `top` to `bottom`.
+fn rows(rect: RectF, top: f32, bottom: f32) -> RectF {
+ let top = top.clamp(rect.min_y(), rect.max_y());
+ let bottom = bottom.clamp(top, rect.max_y());
+ euclid::rect(rect.min_x(), top, rect.width(), bottom - top)
+}
+
+/// The columns of `rect` from `left` to `right`.
+fn cols(rect: RectF, left: f32, right: f32) -> RectF {
+ let left = left.clamp(rect.min_x(), rect.max_x());
+ let right = right.clamp(left, rect.max_x());
+ euclid::rect(left, rect.min_y(), right - left, rect.height())
+}
+
+/// Less than this across is left out of what `without` leaves: what float
+/// sums put between two rects that meet.
+const SLIVER: f32 = 0.5;
+
+/// What of `rects` lies outside `cut`, as rects that do not overlap.
+fn without(rects: Vec<RectF>, cut: RectF) -> Vec<RectF> {
+ let mut left = Vec::with_capacity(rects.len());
+ for rect in rects {
+ let Some(inside) = rect.intersection(&cut).filter(|inside| !inside.is_empty()) else {
+ left.push(rect);
+ continue;
+ };
+ // Above and below it all across, beside it the rows between.
+ let beside = rows(rect, inside.min_y(), inside.max_y());
+ left.extend(
+ [
+ rows(rect, rect.min_y(), inside.min_y()),
+ rows(rect, inside.max_y(), rect.max_y()),
+ cols(beside, rect.min_x(), inside.min_x()),
+ cols(beside, inside.max_x(), rect.max_x()),
+ ]
+ .iter()
+ .copied()
+ .filter(|piece| piece.width() >= SLIVER && piece.height() >= SLIVER),
+ );
+ }
+ left
+}
+
+/// Where a pane stands: its ground with its nav bar, and the top left
+/// corner of its cells, which its text is laid out from.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Placed {
+ pub rect: RectF,
+ pub origin: (f32, f32),
+}
+
+/// The nav bar of a pane on its way: the band it runs along where the pane
+/// stands, where along that the buttons at its end start, and how high the
+/// band stands where the pane is drawn from and where it goes -- for a zoom,
+/// its place and the whole tab. A terminal bar along the top lifts the bands
+/// of the panes along the tab's top edge, so a band need not go along with
+/// the pane's text.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Nav {
+ pub band: RectF,
+ pub buttons: f32,
+ pub top_from: f32,
+ pub top_to: f32,
+}
+
+/// A pane on its way in a rearrangement: where it stood and where it stands,
+/// as drawn, and its nav bar.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct MovingPane {
+ pane_id: PaneId,
+ from: Placed,
+ to: Placed,
+ nav: Option<Nav>,
+}
+
+impl MovingPane {
+ /// `pos`, drawn `from` where it stood (see `Rearranging::was`) `to`
+ /// where it stands.
+ pub fn new(pos: &PositionedPane, from: Placed, to: Placed, nav: Option<Nav>) -> Self {
+ Self {
+ pane_id: pos.pane.pane_id(),
+ from,
+ to,
+ nav,
+ }
+ }
+}
+
+/// The pieces a pane painted where it `stands` is drawn in at `now`: its
+/// text and ground shifted by `shift`, its nav bar's band at the height
+/// given with it, its tabs with its left edge and the buttons at the end
+/// with its right. With them, what of `now` they leave bare, to be filled
+/// like the pane's own room, and how far down the band is drawn there.
+fn pieces(
+ stands: RectF,
+ now: RectF,
+ shift: (f32, f32),
+ nav: Option<(Nav, f32)>,
+ area: RectF,
+) -> (Vec<Drawn>, Vec<RectF>, f32) {
+ // What of the pane as painted a piece drawn so shifted covers.
+ let covered = |shift| translated(stands, shift);
+ let mut pieces = Vec::with_capacity(3);
+ let mut room = vec![now];
+ let mut nav_shift = shift.1;
+ match nav {
+ Some((nav, top)) => {
+ nav_shift = top - nav.band.min_y();
+ let bar = rows(now, top, top + nav.band.height());
+ let end_shift = now.max_x() - within(stands, area).max_x();
+ let ends = cols(bar, nav.buttons + end_shift, bar.max_x());
+ // Its tabs up to them, short of where they stand in it.
+ let title = cols(bar, bar.min_x(), nav.buttons + shift.0.min(end_shift));
+ // Its text under it, none of the bar with it.
+ let text = rows(
+ now,
+ bar.max_y().max(nav.band.max_y() + shift.1),
+ now.max_y(),
+ );
+ for (shift, clip) in [
+ ((shift.0, nav_shift), title),
+ ((end_shift, nav_shift), ends),
+ (shift, text),
+ ] {
+ if let Some(drawn) = clip.intersection(&covered(shift)) {
+ room = without(room, drawn);
+ }
+ pieces.push(Drawn { shift, clip });
+ }
+ }
+ None => {
+ pieces.push(Drawn { shift, clip: now });
+ room = without(room, covered(shift));
+ }
+ }
+ pieces.retain(|drawn| !drawn.clip.is_empty());
+ (pieces, room, nav_shift)
+}
+
+/// What of `rects` none of `over` covers.
+fn cut(rects: Vec<RectF>, over: &[RectF]) -> Vec<RectF> {
+ over.iter().fold(rects, |rects, over| without(rects, *over))
+}
+
+/// `pieces`, cut short of what is drawn over them.
+fn under(pieces: Vec<Drawn>, over: &[RectF]) -> Vec<Drawn> {
+ pieces
+ .into_iter()
+ .flat_map(|drawn| {
+ cut(vec![drawn.clip], over)
+ .into_iter()
+ .map(move |clip| Drawn {
+ shift: drawn.shift,
+ clip,
+ })
+ })
+ .collect()
+}
+
+/// One of the panes a zoom pushes out of its way: in cells, which tell the
+/// side of the pane zoomed it lies on, and where it stands.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct OtherPane {
+ pane_id: PaneId,
+ cells: CellRect,
+ rect: RectF,
+}
+
+impl OtherPane {
+ pub fn of(pos: &PositionedPane, rect: RectF) -> Self {
+ Self {
+ pane_id: pos.pane.pane_id(),
+ cells: CellRect::of(pos),
+ rect,
+ }
+ }
+}
+
+/// How far a zoom on its way pushes the panes beside the pane zoomed, by
+/// the side of its place they lie past: as far as that side of it has gone.
+#[derive(Clone, Copy, Debug, PartialEq)]
+struct Push {
+ /// The pane's place, in cells and where it is drawn.
+ place: CellRect,
+ from: RectF,
+ /// Where it is drawn now.
+ now: RectF,
+ /// The whole tab, that nothing is drawn outside of.
+ bounds: RectF,
+}
+
+impl Push {
+ /// Which sides of the pane's place `cells` lies past: left, right,
+ /// above, below. Told by cells, as the ground of a pane above another
+ /// can run on under the other's nav bar where the window is padded.
+ fn sides(&self, cells: CellRect) -> (bool, bool, bool, bool) {
+ let place = self.place;
+ (
+ cells.right() <= place.left,
+ cells.left >= place.right(),
+ cells.bottom() <= place.top,
+ cells.top >= place.bottom(),
+ )
+ }
+
+ /// The shift for something past these sides of the pane's place.
+ fn shift(&self, (left, right, above, below): (bool, bool, bool, bool)) -> Option<(f32, f32)> {
+ let dx = if left {
+ self.now.min_x() - self.from.min_x()
+ } else if right {
+ self.now.max_x() - self.from.max_x()
+ } else {
+ 0.
+ };
+ let dy = if above {
+ self.now.min_y() - self.from.min_y()
+ } else if below {
+ self.now.max_y() - self.from.max_y()
+ } else {
+ 0.
+ };
+ (left || right || above || below).then_some((dx, dy))
+ }
+
+ /// How a pane in `cells` is drawn: pushed, and cut to the side of the
+ /// pane zoomed it lies on, clear of it.
+ fn pane(&self, cells: CellRect) -> Option<Drawn> {
+ let sides = self.sides(cells);
+ let shift = self.shift(sides)?;
+ let (left, right, above, below) = sides;
+ let mut clip = self.bounds;
+ if left {
+ clip = cols(clip, clip.min_x(), self.now.min_x());
+ } else if right {
+ clip = cols(clip, self.now.max_x(), clip.max_x());
+ }
+ if above {
+ clip = rows(clip, clip.min_y(), self.now.min_y());
+ } else if below {
+ clip = rows(clip, self.now.max_y(), clip.max_y());
+ }
+ Some(Drawn { shift, clip })
+ }
+
+ /// How a divider running along `rect` is drawn: pushed with the panes
+ /// beside it. Its line runs along the edge of the pane past it, as it
+ /// does standing still, over the pane zoomed where that is the one.
+ fn divider(&self, rect: CellRect) -> Option<Drawn> {
+ let shift = self.shift(self.sides(rect))?;
+ Some(Drawn {
+ shift,
+ clip: self.bounds,
+ })
+ }
+}
+
/// How a pane or a divider is drawn in a frame of a slide: shifted by
/// `shift` from where it stands, and cut to `clip`.
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -568,6 +1186,30 @@ pub struct SlideFrame {
room: Option<(CellRect, Drawn)>,
/// Room no pane covers in this frame, and the pane to fill it like.
pub fills: Vec<(PaneId, RectF)>,
+ /// How far down from where it stands the nav bar of the pane a fill is
+ /// like is drawn, its band in the fill with it.
+ pub fills_shift: f32,
+ /// Room between panes pushed apart, and the pane whose ground fills it.
+ pub grounds: Vec<(PaneId, RectF)>,
+ /// A pane zoomed or let back down on its way, in the pieces that go
+ /// their own ways.
+ zooming: Option<(PaneId, Vec<Drawn>)>,
+ /// The panes it pushes out of its way, and the dividers between them.
+ pushed: Vec<(PaneId, Drawn)>,
+ push: Option<Push>,
+ /// Panes rearranged on their way, in their pieces, and those under them
+ /// they cross, cut short of them.
+ moving: Vec<(PaneId, Vec<Drawn>)>,
+ /// Room of a pane on its way that its pieces leave bare, and how far
+ /// down its nav bar is drawn there.
+ pub rooms: Vec<(PaneId, RectF, f32)>,
+ /// Room no pane covers yet, in the darker ground.
+ pub backdrop: Vec<RectF>,
+ /// The lines along the panes on their way, in the dividers' colour.
+ pub edges: Vec<RectF>,
+ /// Where the dividers are drawn while panes are rearranged: clear of
+ /// the panes on their way, and of where each stood and goes.
+ dividers: Option<Vec<RectF>>,
}
impl SlideFrame {
@@ -683,6 +1325,170 @@ impl SlideFrame {
frame
}
+ /// The pane `zooming` drawn `toward_whole` of the way from its place
+ /// towards the whole tab, standing at `place` or at `whole`, with its
+ /// nav bar `nav`, and the `others` pushed out of its way. Nothing is
+ /// drawn outside the whole tab, or outside `area`.
+ pub fn zoom<P>(
+ zooming: &Zooming<P>,
+ toward_whole: f32,
+ place: Placed,
+ whole: Placed,
+ nav: Option<Nav>,
+ others: &[OtherPane],
+ area: RectF,
+ ) -> Self {
+ let bounds = within(whole.rect, area);
+ let from = within(place.rect, area);
+ let now = between(from, bounds, toward_whole);
+ let stands = if zooming.zoomed { whole } else { place };
+ // Its text and its ground go with its top left corner, from where
+ // the zoom has laid them out.
+ let shift = (
+ lerp(place.origin.0, whole.origin.0, toward_whole) - stands.origin.0,
+ lerp(place.origin.1, whole.origin.1, toward_whole) - stands.origin.1,
+ );
+ // Its nav bar goes from where it stands in its place to where it
+ // stands over the whole tab.
+ let nav = nav.map(|nav| (nav, lerp(nav.top_from, nav.top_to, toward_whole)));
+ let (pieces, room, fills_shift) = pieces(stands.rect, now, shift, nav, area);
+ let push = Push {
+ place: zooming.place,
+ from,
+ now,
+ bounds,
+ };
+ let mut gaps = without(vec![bounds], now);
+ let mut pushed = Vec::with_capacity(others.len());
+ for other in others {
+ let Some(drawn) = push.pane(other.cells) else {
+ continue;
+ };
+ let image = translated(within(other.rect, area), drawn.shift);
+ if let Some(image) = image.intersection(&drawn.clip) {
+ gaps = without(gaps, image);
+ }
+ pushed.push((other.pane_id, drawn));
+ }
+ Self {
+ fills: room.into_iter().map(|rect| (zooming.pane_id, rect)).collect(),
+ fills_shift,
+ grounds: gaps.into_iter().map(|rect| (zooming.pane_id, rect)).collect(),
+ zooming: Some((zooming.pane_id, pieces)),
+ pushed,
+ push: Some(push),
+ ..Self::default()
+ }
+ }
+
+ /// The panes `moving` drawn `t` of the way from where they stood to
+ /// where they stand, the first over the rest, each edged with a `line`
+ /// wide as a divider; under them the `still` ones where they stand, and
+ /// under those the `hidden` ones, out of sight in a stack now, where
+ /// they stood. Nothing is drawn outside `area`.
+ pub fn rearrange(
+ moving: &[MovingPane],
+ still: &[(PaneId, RectF)],
+ hidden: &[(PaneId, RectF)],
+ t: f32,
+ line: f32,
+ area: RectF,
+ ) -> Self {
+ let mut frame = Self::default();
+ let mut ends = Vec::with_capacity(moving.len() * 2);
+ // What the panes so far are drawn in: each after goes under them.
+ let mut over = Vec::with_capacity(moving.len() + still.len() + hidden.len());
+ let bounds = moving
+ .iter()
+ .flat_map(|pane| [pane.from.rect, pane.to.rect])
+ .chain(still.iter().chain(hidden).map(|(_, rect)| *rect))
+ .map(|rect| within(rect, area))
+ .reduce(|bounds, rect| bounds.union(&rect));
+ for pane in moving {
+ let (from, to) = (within(pane.from.rect, area), within(pane.to.rect, area));
+ let now = between(from, to, t);
+ let shift = (
+ lerp(pane.from.origin.0, pane.to.origin.0, t) - pane.to.origin.0,
+ lerp(pane.from.origin.1, pane.to.origin.1, t) - pane.to.origin.1,
+ );
+ let nav = pane
+ .nav
+ .map(|nav| (nav, lerp(nav.top_from, nav.top_to, t)));
+ let (pieces, room, nav_shift) = pieces(pane.to.rect, now, shift, nav, area);
+ frame.moving.push((pane.pane_id, under(pieces, &over)));
+ frame.rooms.extend(
+ cut(room, &over)
+ .into_iter()
+ .map(|rect| (pane.pane_id, rect, nav_shift)),
+ );
+ // Edged where it meets the others, as dividers edge the panes
+ // standing still: just right of and under where two meet, so a
+ // line ends up where the divider takes over. Not along the
+ // window, where none do.
+ if let Some(bounds) = bounds {
+ let (x, y, w, h) = (now.min_x(), now.min_y(), now.width(), now.height());
+ let sides = [
+ (x - bounds.min_x(), euclid::rect(x, y, line, h)),
+ (bounds.max_x() - now.max_x(), euclid::rect(now.max_x(), y, line, h)),
+ (y - bounds.min_y(), euclid::rect(x, y, w, line)),
+ (bounds.max_y() - now.max_y(), euclid::rect(x, now.max_y(), w + line, line)),
+ ];
+ let edges = sides
+ .iter()
+ .filter(|(inside, _)| *inside >= SLIVER)
+ .filter_map(|(_, edge)| edge.intersection(&area))
+ .collect();
+ frame.edges.extend(cut(edges, &over));
+ }
+ // A divider beside where it stood or where it goes has no place
+ // until it gets there: its own edges run there meanwhile.
+ ends.extend([from, to].iter().map(|rect| rect.inflate(line, line)));
+ over.push(now);
+ }
+ frame.dividers = Some(cut(cut(vec![area], &over), &ends));
+ for (pane_id, rect) in still {
+ let rect = within(*rect, area);
+ // One nothing crosses is drawn as it stands; one beside it only
+ // meets it, give or take what float sums put between them.
+ let crossed = over.iter().any(|over| {
+ over.intersection(&rect).is_some_and(|crossed| {
+ crossed.width() >= SLIVER && crossed.height() >= SLIVER
+ })
+ });
+ if crossed {
+ let clips = cut(vec![rect], &over);
+ frame.moving.push((
+ *pane_id,
+ clips
+ .into_iter()
+ .map(|clip| Drawn {
+ shift: (0., 0.),
+ clip,
+ })
+ .collect(),
+ ));
+ }
+ over.push(rect);
+ }
+ for (pane_id, rect) in hidden {
+ let rect = within(*rect, area);
+ let clips = cut(vec![rect], &over);
+ frame.moving.push((
+ *pane_id,
+ clips
+ .into_iter()
+ .map(|clip| Drawn {
+ shift: (0., 0.),
+ clip,
+ })
+ .collect(),
+ ));
+ over.push(rect);
+ }
+ frame.backdrop = bounds.map_or_else(Vec::new, |bounds| cut(vec![bounds], &over));
+ frame
+ }
+
/// How the frame draws `pos`, where not as it stands.
pub fn pane(&self, pos: &PositionedPane) -> Option<Drawn> {
self.pane_at(pos.pane.pane_id(), CellRect::of(pos))
@@ -691,15 +1497,48 @@ impl SlideFrame {
fn pane_at(&self, pane_id: PaneId, rect: CellRect) -> Option<Drawn> {
match self.arriving {
Some((arriving, drawn)) if arriving == pane_id => Some(drawn),
- _ => self.moved_at(rect),
+ _ => self
+ .pushed
+ .iter()
+ .find(|(pushed, _)| *pushed == pane_id)
+ .map(|(_, drawn)| *drawn)
+ .or_else(|| self.moved_at(rect)),
}
}
+ /// The pieces the frame draws `pos` in: the pane zoomed or let back
+ /// down on its way, or one rearranged on its way or under those.
+ pub fn pieces(&self, pos: &PositionedPane) -> Option<&[Drawn]> {
+ self.pieces_of(pos.pane.pane_id())
+ }
+
+ fn pieces_of(&self, pane_id: PaneId) -> Option<&[Drawn]> {
+ match &self.zooming {
+ Some((zooming, pieces)) if *zooming == pane_id => Some(pieces),
+ _ => self
+ .moving
+ .iter()
+ .find(|(moving, _)| *moving == pane_id)
+ .map(|(_, pieces)| pieces.as_slice()),
+ }
+ }
+
+ /// Where the frame draws the dividers, the panes rearranged.
+ pub fn divider_clips(&self) -> Option<&[RectF]> {
+ self.dividers.as_deref()
+ }
+
/// How the frame draws `split`, where not as it stands.
pub fn split(&self, split: &PositionedSplit) -> Option<Drawn> {
match self.leading {
Some((edge, pane, drawn)) if edge.leads(pane, split) => Some(drawn),
- _ => self.moved_at(CellRect::of_split(split)),
+ _ => {
+ let rect = CellRect::of_split(split);
+ match self.push {
+ Some(push) => push.divider(rect),
+ None => self.moved_at(rect),
+ }
+ }
}
}
@@ -720,11 +1559,22 @@ pub struct SplitSlides<P = PositionedPane> {
last_panes: Vec<P>,
/// Swapped with `last_panes` each frame, so neither is allocated anew.
spare_panes: Vec<P>,
+ /// The dividers between them, held and swapped the same way: a zoom
+ /// pushes them out along with the panes.
+ last_splits: Vec<PositionedSplit>,
+ spare_splits: Vec<PositionedSplit>,
coming: Option<SplitSlide>,
going: Option<Leaving<P>>,
+ zooming: Option<Zooming<P>>,
+ rearranging: Option<Rearranging<P>>,
/// The panes whose nav bar the frame painted showed no tab, as one an
/// overlay stands in for does: one of them that closes goes out so.
bare_navs: Vec<PaneId>,
+ /// The tabs each nav bar the frame painted showed, by where they lie in
+ /// `nav_tabs`, and where along the bar its first tab stood, scrolled as
+ /// it was: one carried into another stack goes on from them.
+ navs: Vec<(PaneId, f32, std::ops::Range<usize>)>,
+ nav_tabs: Vec<PaneId>,
}
impl<P> Default for SplitSlides<P> {
@@ -733,34 +1583,47 @@ impl<P> Default for SplitSlides<P> {
last: None,
last_panes: vec![],
spare_panes: vec![],
+ last_splits: vec![],
+ spare_splits: vec![],
coming: None,
going: None,
+ zooming: None,
+ rearranging: None,
bare_navs: vec![],
+ navs: vec![],
+ nav_tabs: vec![],
}
}
}
-/// A frame's slides, each with how far out of its place it is drawn.
+/// A frame's slides, each with how far out of its place it is drawn; a
+/// zoom with how far from its place towards the whole tab, a rearrangement
+/// how far from where the panes stood to where they stand.
pub struct Slides<P = PositionedPane> {
pub coming: Option<(SplitSlide, f32)>,
pub going: Option<(Leaving<P>, f32)>,
+ pub zooming: Option<(Zooming<P>, f32)>,
+ pub rearranging: Option<(Rearranging<P>, f32)>,
}
impl<P: Clone> SplitSlides<P> {
- /// Take this frame's layout and the panes it was made of, in its order;
- /// the slides to paint the frame with. A frame painted again -- the
- /// quads ran out, a font came in -- takes the same layout again, and
- /// gets the same slides.
+ /// Take this frame's layout, the panes it was made of, in its order,
+ /// and the dividers between them; the slides to paint the frame with. A
+ /// frame painted again -- the quads ran out, a font came in -- takes the
+ /// same layout again, and gets the same slides.
pub fn advance(
&mut self,
layout: Option<TabLayout>,
panes: &[P],
+ splits: &[PositionedSplit],
enabled: bool,
now: Instant,
) -> Slides<P> {
let before = std::mem::replace(&mut self.last, layout);
std::mem::swap(&mut self.last_panes, &mut self.spare_panes);
+ std::mem::swap(&mut self.last_splits, &mut self.spare_splits);
self.last_panes.clear();
+ self.last_splits.clear();
if self
.last
.as_ref()
@@ -768,9 +1631,12 @@ impl<P: Clone> SplitSlides<P> {
{
self.last_panes.extend_from_slice(panes);
}
+ self.last_splits.extend_from_slice(splits);
if !enabled {
self.coming = None;
self.going = None;
+ self.zooming = None;
+ self.rearranging = None;
} else if let (Some(before), Some(layout)) = (before.as_ref(), self.last.as_ref()) {
let opened = layout.opened_by_split(before).and_then(|(pane_id, edge, from)| {
Some((pane_id, edge, from, layout.rect(pane_id)?))
@@ -779,6 +1645,8 @@ impl<P: Clone> SplitSlides<P> {
// One slide at a time: the panes a slide draws elsewhere are
// laid out for it alone. One still under way is cut short.
self.going = None;
+ self.zooming = None;
+ self.rearranging = None;
self.coming = Some(SplitSlide {
pane_id,
edge,
@@ -791,12 +1659,14 @@ impl<P: Clone> SplitSlides<P> {
});
}
if let Some((index, edge)) = layout.closed(before) {
- let (pane_id, rect) = before.panes[index];
+ let (pane_id, rect, _) = before.panes[index];
// Closed before it was all the way in: it has no place of
// its own to go out of.
let arriving = self.coming.is_some_and(|slide| slide.pane_id == pane_id);
if let Some(pane) = self.spare_panes.get(index).filter(|_| !arriving) {
self.coming = None;
+ self.zooming = None;
+ self.rearranging = None;
self.going = Some(Leaving {
pane: pane.clone(),
edge,
@@ -810,14 +1680,105 @@ impl<P: Clone> SplitSlides<P> {
});
}
}
+ let zoom = layout.zoom(before).and_then(|(pane_id, zoomed)| {
+ let (now_at, then_at) = (layout.rect(pane_id)?, before.rect(pane_id)?);
+ Some((pane_id, zoomed, now_at, then_at))
+ });
+ if let Some((pane_id, zoomed, now_at, then_at)) = zoom {
+ let (place, whole, others, dividers) = if zoomed {
+ // Out of the tab's frames from this one on.
+ let others = before
+ .panes
+ .iter()
+ .zip(&self.spare_panes)
+ .filter(|((id, _, _), _)| *id != pane_id)
+ .map(|(_, pane)| pane.clone())
+ .collect();
+ (then_at, now_at, others, std::mem::take(&mut self.spare_splits))
+ } else {
+ (now_at, then_at, vec![], vec![])
+ };
+ // Taken back on its way, it turns round where it has got to.
+ let turning = self
+ .zooming
+ .as_ref()
+ .filter(|zooming| {
+ zooming.pane_id == pane_id
+ && zooming.tab_id == layout.tab_id
+ && zooming.zoomed != zoomed
+ })
+ .and_then(|zooming| zooming.toward_whole(now));
+ let mut zooming = Zooming {
+ pane_id,
+ zoomed,
+ place,
+ whole,
+ others,
+ dividers,
+ tab_id: layout.tab_id,
+ started: now,
+ shown: 0,
+ paints: 0,
+ };
+ if let Some(toward_whole) = turning {
+ zooming.set_out_from(toward_whole, now);
+ }
+ self.coming = None;
+ self.going = None;
+ self.rearranging = None;
+ self.zooming = Some(zooming);
+ }
+ if let Some(rearranged) = layout.rearranged(before) {
+ let hidden = rearranged
+ .hidden
+ .iter()
+ .filter_map(|index| self.spare_panes.get(*index).cloned())
+ .collect();
+ let bare = rearranged
+ .hidden
+ .iter()
+ .map(|index| before.panes[*index].0)
+ .filter(|pane_id| self.bare_navs.contains(pane_id))
+ .collect();
+ let carried = rearranged
+ .carried
+ .iter()
+ .map(|pane_id| {
+ match self.navs.iter().find(|(nav, _, _)| nav == pane_id) {
+ Some((_, lead, tabs)) => {
+ (*pane_id, Some(*lead), self.nav_tabs[tabs.clone()].to_vec())
+ }
+ None => (*pane_id, None, vec![*pane_id]),
+ }
+ })
+ .collect();
+ self.coming = None;
+ self.going = None;
+ self.zooming = None;
+ self.rearranging = Some(Rearranging {
+ moved: rearranged.moved,
+ hidden,
+ bare,
+ carried,
+ tab_id: layout.tab_id,
+ started: now,
+ shown: 0,
+ paints: 0,
+ });
+ }
}
// Last frame's panes have been looked through: let go of them, a
// closed one among them.
self.spare_panes.clear();
+ self.spare_splits.clear();
self.bare_navs.clear();
+ self.navs.clear();
+ self.nav_tabs.clear();
Slides {
coming: self.advance_coming(now),
going: self.advance_going(now),
+ zooming: self.advance_zooming(now),
+ rearranging: self.advance_rearranging(now),
}
}
@@ -826,6 +1787,14 @@ impl<P: Clone> SplitSlides<P> {
self.bare_navs.push(pane_id);
}
+ /// The frame being painted shows `tabs` in `pane_id`'s nav bar, the
+ /// first `lead` along it.
+ pub fn nav(&mut self, pane_id: PaneId, lead: f32, tabs: impl IntoIterator<Item = PaneId>) {
+ let start = self.nav_tabs.len();
+ self.nav_tabs.extend(tabs);
+ self.navs.push((pane_id, lead, start..self.nav_tabs.len()));
+ }
+
/// The frame painted with the slides was shown: they are a frame on.
/// Counted here rather than in `advance`, which a frame painted again
/// calls again.
@@ -836,6 +1805,12 @@ impl<P: Clone> SplitSlides<P> {
if let Some(leaving) = self.going.as_mut() {
leaving.shown += 1;
}
+ if let Some(zooming) = self.zooming.as_mut() {
+ zooming.shown += 1;
+ }
+ if let Some(rearranging) = self.rearranging.as_mut() {
+ rearranging.shown += 1;
+ }
}
fn advance_coming(&mut self, now: Instant) -> Option<(SplitSlide, f32)> {
@@ -878,16 +1853,79 @@ impl<P: Clone> SplitSlides<P> {
}
}
+ fn advance_zooming(&mut self, now: Instant) -> Option<(Zooming<P>, f32)> {
+ let zooming = self.zooming.as_mut()?;
+ zooming.paints += 1;
+ // Another tab, the zoom taken back or the pane gone: nothing left
+ // to grow or shrink.
+ let layout = self.last.as_ref().filter(|layout| {
+ layout.tab_id == zooming.tab_id
+ && layout.zoomed == zooming.zoomed
+ && zooming.paints <= MOST_PAINTS
+ });
+ let rect = layout.and_then(|layout| layout.rect(zooming.pane_id));
+ match rect.and_then(|rect| Some((rect, zooming.toward_whole(now)?))) {
+ Some((rect, toward_whole)) => {
+ // Where it stands now, should the tab have changed size.
+ if zooming.zoomed {
+ zooming.whole = rect;
+ } else {
+ zooming.place = rect;
+ if let Some(whole) = layout.and_then(TabLayout::bounds) {
+ zooming.whole = whole;
+ }
+ }
+ Some((zooming.clone(), toward_whole))
+ }
+ None => {
+ self.zooming = None;
+ None
+ }
+ }
+ }
+
+ fn advance_rearranging(&mut self, now: Instant) -> Option<(Rearranging<P>, f32)> {
+ let rearranging = self.rearranging.as_mut()?;
+ rearranging.paints += 1;
+ // Another tab, or a zoom: nothing left to go anywhere.
+ let layout = self.last.as_ref().filter(|layout| {
+ layout.tab_id == rearranging.tab_id
+ && !layout.zoomed
+ && rearranging.paints <= MOST_PAINTS
+ });
+ if let Some(layout) = layout {
+ // One closed on its way has nowhere to go.
+ rearranging
+ .moved
+ .retain(|(pane_id, _)| layout.rect(*pane_id).is_some());
+ }
+ let along = layout
+ .filter(|_| !rearranging.moved.is_empty())
+ .and_then(|_| rearranging.along(now));
+ match along {
+ Some(along) => Some((rearranging.clone(), along)),
+ None => {
+ self.rearranging = None;
+ None
+ }
+ }
+ }
+
/// Let go of every pane held, and of the layout last painted. A window
/// that paints no frames would keep them until it painted one, a closed
/// pane among them alive, and then take whatever changed meanwhile for a
- /// split or a close to slide.
+ /// split, a close or a zoom to slide.
pub fn release(&mut self) {
self.last = None;
self.last_panes.clear();
+ self.last_splits.clear();
self.coming = None;
self.going = None;
+ self.zooming = None;
+ self.rearranging = None;
self.bare_navs.clear();
+ self.navs.clear();
+ self.nav_tabs.clear();
}
}
@@ -909,10 +1947,85 @@ impl ClosedNav {
}
}
+/// The nav bar of a pane carried into another stack, `along` of the way
+/// from the tabs it showed, `from`, to its new stack's. `from_lead` is how
+/// far along its old bar the first of them stood, scrolled as that was;
+/// `None` where that bar was not painted.
+#[derive(Clone, Debug, PartialEq)]
+pub struct NavMorph {
+ pub pane_id: PaneId,
+ pub from: Vec<PaneId>,
+ pub from_lead: Option<f32>,
+ pub along: f32,
+}
+
+/// One tab of a nav bar on its way: how far along the strip it is drawn,
+/// how opaque, and whether it is one of the stack's, to be clicked.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct TabPlace {
+ pub pane_id: PaneId,
+ pub x: f32,
+ pub opacity: f32,
+ pub kept: bool,
+}
+
+impl NavMorph {
+ /// Where along the bar its tabs are drawn, `to` being the new stack's,
+ /// the first of them `to_lead` along, and each step how far apart tabs
+ /// stand among as many as either list has: one in both goes from its
+ /// place among `from` to its place among `to`; one only in `to` comes
+ /// up where it goes, and one only in `from` fades where it was. At the
+ /// end they stand as the stack has them.
+ pub fn places(
+ &self,
+ to: &[PaneId],
+ from_step: f32,
+ to_step: f32,
+ to_lead: f32,
+ ) -> Vec<TabPlace> {
+ let from_lead = self.from_lead.unwrap_or(to_lead);
+ let mut places: Vec<TabPlace> = to
+ .iter()
+ .enumerate()
+ .map(|(index, pane_id)| {
+ let x = to_lead + index as f32 * to_step;
+ match self.from.iter().position(|from| from == pane_id) {
+ Some(was) => TabPlace {
+ pane_id: *pane_id,
+ x: lerp(from_lead + was as f32 * from_step, x, self.along),
+ opacity: 1.0,
+ kept: true,
+ },
+ None => TabPlace {
+ pane_id: *pane_id,
+ x,
+ opacity: self.along,
+ kept: true,
+ },
+ }
+ })
+ .collect();
+ places.extend(
+ self.from
+ .iter()
+ .enumerate()
+ .filter(|(_, pane_id)| !to.contains(pane_id))
+ .map(|(was, pane_id)| TabPlace {
+ pane_id: *pane_id,
+ x: from_lead + was as f32 * from_step,
+ opacity: 1.0 - self.along,
+ kept: false,
+ }),
+ );
+ places
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
+ /// Each pane alone in a stack of its own, numbered as it is.
fn layout(tab_id: TabId, panes: &[(PaneId, [usize; 4])]) -> TabLayout {
TabLayout {
tab_id,
@@ -928,12 +2041,24 @@ mod tests {
width: *width,
height: *height,
},
+ *id,
)
})
.collect(),
+ active: None,
}
}
+ /// `layout`, with `pane` shown in `stack` instead.
+ fn shown_in(mut layout: TabLayout, pane: PaneId, stack: PaneStackId) -> TabLayout {
+ for (id, _, shown) in &mut layout.panes {
+ if *id == pane {
+ *shown = stack;
+ }
+ }
+ layout
+ }
+
fn cells([left, top, width, height]: [usize; 4]) -> CellRect {
CellRect {
left,
@@ -996,7 +2121,8 @@ mod tests {
two.opened_by_split(&TabLayout {
tab_id: 1,
zoomed: false,
- panes: vec![]
+ panes: vec![],
+ active: None,
}),
None
);
@@ -1009,7 +2135,7 @@ mod tests {
fn panes_spec(&self) -> Vec<(PaneId, [usize; 4])> {
self.panes
.iter()
- .map(|(id, r)| (*id, [r.left, r.top, r.width, r.height]))
+ .map(|(id, r, _)| (*id, [r.left, r.top, r.width, r.height]))
.collect()
}
}
@@ -1027,13 +2153,13 @@ mod tests {
fn run(frame: Duration, passes: usize) -> Vec<f32> {
let start = Instant::now();
let mut slides = SplitSlides::<PaneId>::default();
- assert!(slides.advance(one(), &[1], true, start).coming.is_none());
+ assert!(slides.advance(one(), &[1], &[], true, start).coming.is_none());
let mut steps = vec![];
let mut now = start;
loop {
let mut painted = None;
for _ in 0..passes {
- painted = slides.advance(two(), &[1, 2], true, now).coming;
+ painted = slides.advance(two(), &[1, 2], &[], true, now).coming;
}
let Some((slide, remaining)) = painted else {
break;
@@ -1045,7 +2171,7 @@ mod tests {
assert!(steps.len() < 100);
}
// And it does not start again.
- assert!(slides.advance(two(), &[1, 2], true, now + frame).coming.is_none());
+ assert!(slides.advance(two(), &[1, 2], &[], true, now + frame).coming.is_none());
steps
}
@@ -1054,13 +2180,13 @@ mod tests {
fn run_close(frame: Duration, passes: usize) -> Vec<f32> {
let start = Instant::now();
let mut slides = SplitSlides::<PaneId>::default();
- assert!(slides.advance(two(), &[1, 2], true, start).going.is_none());
+ assert!(slides.advance(two(), &[1, 2], &[], true, start).going.is_none());
let mut steps = vec![];
let mut now = start;
loop {
let mut painted = None;
for _ in 0..passes {
- painted = slides.advance(one(), &[1], true, now).going;
+ painted = slides.advance(one(), &[1], &[], true, now).going;
}
let Some((leaving, out)) = painted else {
break;
@@ -1071,7 +2197,7 @@ mod tests {
now += frame;
assert!(steps.len() < 100);
}
- assert!(slides.advance(one(), &[1], true, now + frame).going.is_none());
+ assert!(slides.advance(one(), &[1], &[], true, now + frame).going.is_none());
steps
}
@@ -1080,27 +2206,27 @@ mod tests {
let steps = run(Duration::from_micros(8_333), 1);
// On its way from the first frame, never back, and there within
// its time.
- assert!(steps[0] < 1.0 && steps[0] > 0.6, "{steps:?}");
+ assert!(steps[0] < 1.0 && steps[0] > 0.6, "{:?}", steps);
// No frame jumps much more of the way than the first.
let first = 1.0 - steps[0];
assert!(
steps.windows(2).all(|w| w[0] - w[1] <= first * 1.05),
- "{steps:?}"
+ "{:?}", steps
);
- assert!(steps.windows(2).all(|w| w[1] < w[0]), "{steps:?}");
- assert!(steps.len() as u32 >= MIN_FRAMES, "{steps:?}");
- assert!(steps.len() <= 22, "{steps:?}");
+ assert!(steps.windows(2).all(|w| w[1] < w[0]), "{:?}", steps);
+ assert!(steps.len() as u32 >= MIN_FRAMES, "{:?}", steps);
+ assert!(steps.len() <= 22, "{:?}", steps);
assert_eq!(Edge::Right.shift(0.5, 300., 200.), (150., 0.));
}
#[test]
fn slow_frames_slow_the_slide_rather_than_skip_it() {
let steps = run(Duration::from_millis(60), 1);
- assert!(steps.len() as u32 >= MIN_FRAMES - 1, "{steps:?}");
- assert!(steps.windows(2).all(|w| w[1] < w[0]), "{steps:?}");
+ assert!(steps.len() as u32 >= MIN_FRAMES - 1, "{:?}", steps);
+ assert!(steps.windows(2).all(|w| w[1] < w[0]), "{:?}", steps);
let steps = run_close(Duration::from_millis(60), 1);
- assert!(steps.len() as u32 >= MIN_FRAMES - 1, "{steps:?}");
- assert!(steps.windows(2).all(|w| w[1] > w[0]), "{steps:?}");
+ assert!(steps.len() as u32 >= MIN_FRAMES - 1, "{:?}", steps);
+ assert!(steps.windows(2).all(|w| w[1] > w[0]), "{:?}", steps);
}
#[test]
@@ -1110,29 +2236,31 @@ mod tests {
let once = run(Duration::from_millis(60), 1);
let twice = run(Duration::from_millis(60), 2);
assert_eq!(twice.len(), once.len(), "{twice:?} {once:?}");
- assert!((twice[0] - once[0]).abs() < 0.01, "{twice:?} {once:?}");
+ assert!((twice[0] - once[0]).abs() < 0.01, "{:?} {:?}", twice, once);
let once = run_close(Duration::from_millis(60), 1);
let twice = run_close(Duration::from_millis(60), 2);
assert_eq!(twice.len(), once.len(), "{twice:?} {once:?}");
- assert!(twice[0] < 0.05, "{twice:?}");
+ assert!(twice[0] < 0.05, "{:?}", twice);
}
#[test]
fn with_the_setting_off_nothing_slides() {
let start = Instant::now();
let mut slides = SplitSlides::<PaneId>::default();
- assert!(slides.advance(one(), &[1], false, start).coming.is_none());
- assert!(slides.advance(two(), &[1, 2], false, start).coming.is_none());
- assert!(slides.advance(one(), &[1], false, start).going.is_none());
+ assert!(slides.advance(one(), &[1], &[], false, start).coming.is_none());
+ assert!(slides.advance(two(), &[1, 2], &[], false, start).coming.is_none());
+ assert!(slides.advance(one(), &[1], &[], false, start).going.is_none());
+ slides.advance(Some(three()), &[1, 2, 3], &[], false, start);
+ assert!(slides.advance(Some(zoomed(3)), &[3], &[], false, start).zooming.is_none());
}
#[test]
fn a_pane_closed_mid_slide_stops_it() {
let start = Instant::now();
let mut slides = SplitSlides::<PaneId>::default();
- slides.advance(one(), &[1], true, start);
- assert!(slides.advance(two(), &[1, 2], true, start).coming.is_some());
- let closed = slides.advance(one(), &[1], true, start + Duration::from_millis(10));
+ slides.advance(one(), &[1], &[], true, start);
+ assert!(slides.advance(two(), &[1, 2], &[], true, start).coming.is_some());
+ let closed = slides.advance(one(), &[1], &[], true, start + Duration::from_millis(10));
assert!(closed.coming.is_none());
// Nor does it go out of a place it never got to.
assert!(closed.going.is_none());
@@ -1153,14 +2281,14 @@ mod tests {
&[(2, [0, 0, 81, 12]), (3, [0, 13, 40, 11]), (4, [41, 13, 40, 11])],
);
let mut slides = SplitSlides::<PaneId>::default();
- slides.advance(two(), &[1, 2], true, start);
- assert!(slides.advance(Some(three), &[1, 2, 3], true, start).coming.is_some());
+ slides.advance(two(), &[1, 2], &[], true, start);
+ assert!(slides.advance(Some(three), &[1, 2, 3], &[], true, start).coming.is_some());
// Another pane closed while one comes in: that one is in at once.
- let closing = slides.advance(Some(column), &[2, 3], true, start);
+ let closing = slides.advance(Some(column), &[2, 3], &[], true, start);
assert!(closing.coming.is_none());
assert_eq!(closing.going.map(|(leaving, _)| leaving.pane), Some(1));
// And a split while one goes out.
- let splitting = slides.advance(Some(split), &[2, 3, 4], true, start);
+ let splitting = slides.advance(Some(split), &[2, 3, 4], &[], true, start);
assert!(splitting.going.is_none());
assert_eq!(splitting.coming.map(|(slide, _)| slide.pane_id), Some(4));
}
@@ -1218,15 +2346,43 @@ mod tests {
assert_eq!(closed(&one, &three), None);
}
+ #[test]
+ fn a_pane_dragged_into_or_out_of_a_stack_is_carried_neither_coming_nor_going() {
+ let start = Instant::now();
+ let two = layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);
+ // 1 dropped into 2's stack, shown there in front of 2.
+ let joined = shown_in(layout(1, &[(1, [0, 0, 81, 24])]), 1, 2);
+ assert_eq!(closed(&joined, &two), None);
+ // 2 dropped into 1's.
+ let joined_left = shown_in(layout(1, &[(2, [0, 0, 81, 24])]), 2, 1);
+ assert_eq!(closed(&joined_left, &two), None);
+ // 1 dragged back out to the right of its stack, leaving 2 shown.
+ let out = shown_in(
+ layout(1, &[(2, [0, 0, 40, 24]), (1, [41, 0, 40, 24])]),
+ 1,
+ 7,
+ );
+ assert_eq!(out.opened_by_split(&joined), None);
+
+ let mut slides = SplitSlides::<PaneId>::default();
+ slides.advance(Some(two), &[1, 2], &[], true, start);
+ let dropped = slides.advance(Some(joined), &[1], &[], true, start);
+ assert!(dropped.going.is_none() && dropped.coming.is_none());
+ assert!(dropped.rearranging.is_some());
+ let dragged = slides.advance(Some(out), &[2, 1], &[], true, start);
+ assert!(dragged.going.is_none() && dragged.coming.is_none());
+ assert!(dragged.rearranging.is_some());
+ }
+
#[test]
fn a_closed_pane_goes_out_the_way_it_came_and_sooner() {
let steps = run_close(Duration::from_micros(8_333), 1);
// Where it stood on the first frame, on its way after, never back.
- assert!(steps[0] < 0.05, "{steps:?}");
- assert!(steps.windows(2).all(|w| w[1] > w[0]), "{steps:?}");
- assert!(steps.len() as u32 >= MIN_FRAMES, "{steps:?}");
+ assert!(steps[0] < 0.05, "{:?}", steps);
+ assert!(steps.windows(2).all(|w| w[1] > w[0]), "{:?}", steps);
+ assert!(steps.len() as u32 >= MIN_FRAMES, "{:?}", steps);
let coming = run(Duration::from_micros(8_333), 1);
- assert!(steps.len() < coming.len(), "{steps:?} {coming:?}");
+ assert!(steps.len() < coming.len(), "{:?} {:?}", steps, coming);
}
#[test]
@@ -1238,7 +2394,7 @@ mod tests {
height: 11,
};
for edge in [Edge::Left, Edge::Right, Edge::Top, Edge::Bottom] {
- assert!(edge.leads(pane, &edge.divider(pane)), "{edge:?}");
+ assert!(edge.leads(pane, &edge.divider(pane)), "{:?}", edge);
}
assert_eq!(
Edge::Right.divider(pane),
@@ -1256,33 +2412,33 @@ mod tests {
fn a_window_that_lets_go_has_no_closed_pane_to_paint() {
let start = Instant::now();
let mut slides = SplitSlides::<PaneId>::default();
- slides.advance(two(), &[1, 2], true, start);
+ slides.advance(two(), &[1, 2], &[], true, start);
slides.release();
- assert!(slides.advance(one(), &[1], true, start).going.is_none());
+ assert!(slides.advance(one(), &[1], &[], true, start).going.is_none());
// Nor takes what was split meanwhile for a split to slide in.
slides.release();
- assert!(slides.advance(two(), &[1, 2], true, start).coming.is_none());
+ assert!(slides.advance(two(), &[1, 2], &[], true, start).coming.is_none());
// Nor a tab switched to mid-way out.
let mut slides = SplitSlides::<PaneId>::default();
- slides.advance(two(), &[1, 2], true, start);
- assert!(slides.advance(one(), &[1], true, start).going.is_some());
+ slides.advance(two(), &[1, 2], &[], true, start);
+ assert!(slides.advance(one(), &[1], &[], true, start).going.is_some());
let other = Some(layout(2, &[(5, [0, 0, 81, 24])]));
- assert!(slides.advance(other, &[5], true, start).going.is_none());
+ assert!(slides.advance(other, &[5], &[], true, start).going.is_none());
}
#[test]
fn a_pane_whose_nav_bar_showed_no_tab_goes_out_without_one() {
let start = Instant::now();
let mut slides = SplitSlides::<PaneId>::default();
- slides.advance(two(), &[1, 2], true, start);
+ slides.advance(two(), &[1, 2], &[], true, start);
// An overlay stood in for it, asking whether to close it.
slides.bare_nav(2);
- let closing = slides.advance(one(), &[1], true, start);
+ let closing = slides.advance(one(), &[1], &[], true, start);
assert_eq!(closing.going.map(|(leaving, _)| leaving.showed_tab()), Some(false));
let mut slides = SplitSlides::<PaneId>::default();
- slides.advance(two(), &[1, 2], true, start);
+ slides.advance(two(), &[1, 2], &[], true, start);
slides.bare_nav(1);
- let closing = slides.advance(one(), &[1], true, start);
+ let closing = slides.advance(one(), &[1], &[], true, start);
assert_eq!(closing.going.map(|(leaving, _)| leaving.showed_tab()), Some(true));
}
@@ -1290,19 +2446,19 @@ mod tests {
fn a_slide_whose_frames_are_never_shown_still_ends() {
let start = Instant::now();
let mut slides = SplitSlides::<PaneId>::default();
- slides.advance(one(), &[1], true, start);
+ slides.advance(one(), &[1], &[], true, start);
let mut now = start;
let mut paints = 0;
- while slides.advance(two(), &[1, 2], true, now).coming.is_some() {
+ while slides.advance(two(), &[1, 2], &[], true, now).coming.is_some() {
paints += 1;
now += Duration::from_millis(16);
- assert!(paints <= MOST_PAINTS, "{paints}");
+ assert!(paints <= MOST_PAINTS, "{}", paints);
}
assert_eq!(paints, MOST_PAINTS);
// Only frames that are not shown run into that: a slow one is
// still shown in whole.
let steps = run(Duration::from_millis(1500), 1);
- assert!(steps.len() as u32 >= MIN_FRAMES - 1, "{steps:?}");
+ assert!(steps.len() as u32 >= MIN_FRAMES - 1, "{:?}", steps);
}
#[test]
@@ -1458,7 +2614,7 @@ mod tests {
assert!(frame.fills.contains(&(1, rect(705., 0., 205., 500.))));
let covered = within(theirs.translate(euclid::vec2(drawn.shift.0, 0.)), drawn.clip);
for (_, fill) in &frame.fills {
- assert!(fill.intersection(&covered).is_none(), "{fill:?} {covered:?}");
+ assert!(fill.intersection(&covered).is_none(), "{:?} {:?}", fill, covered);
}
// The divider between them goes with both.
let divider = Edge::Left.divider(cells([0, 0, 40, 24]));
@@ -1574,4 +2730,967 @@ mod tests {
};
assert_eq!(frame.split(&beside), None);
}
+
+ /// A pane down the left of the tab, and two over and under each other
+ /// on its right.
+ fn three() -> TabLayout {
+ layout(
+ 1,
+ &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 11]), (3, [41, 12, 40, 12])],
+ )
+ }
+
+ fn zoomed(pane_id: PaneId) -> TabLayout {
+ TabLayout {
+ zoomed: true,
+ ..layout(1, &[(pane_id, [0, 0, 81, 24])])
+ }
+ }
+
+ /// The dividers of `three`: down beside the left pane, and across
+ /// between the two on its right.
+ fn three_splits() -> [PositionedSplit; 2] {
+ [
+ PositionedSplit {
+ index: 0,
+ direction: SplitDirection::Horizontal,
+ left: 40,
+ top: 0,
+ size: 24,
+ },
+ PositionedSplit {
+ index: 1,
+ direction: SplitDirection::Vertical,
+ left: 41,
+ top: 11,
+ size: 40,
+ },
+ ]
+ }
+
+ fn zooming(zoomed: bool, pane_id: PaneId, place: [usize; 4]) -> Zooming<PaneId> {
+ Zooming {
+ pane_id,
+ zoomed,
+ place: cells(place),
+ whole: cells([0, 0, 81, 24]),
+ others: vec![],
+ dividers: vec![],
+ tab_id: 1,
+ started: Instant::now(),
+ shown: 0,
+ paints: 0,
+ }
+ }
+
+ /// Where the panes of `three` stand in `area`, by their ids.
+ fn three_places() -> [(PaneId, RectF); 3] {
+ [
+ (1, rect(100., 0., 405., 500.)),
+ (2, rect(505., 0., 405., 230.)),
+ (3, rect(505., 230., 405., 270.)),
+ ]
+ }
+
+ /// A pane standing at `rect`, its text starting `inset` in from its
+ /// corner: further along the sidebar than half way across a divider.
+ fn placed(rect: RectF, inset: f32) -> Placed {
+ Placed {
+ rect,
+ origin: (rect.min_x() + inset, rect.min_y() + 10.),
+ }
+ }
+
+ fn whole() -> Placed {
+ placed(area(), 10.)
+ }
+
+ /// The others, standing where `three_places` has them.
+ fn others_of(pane_id: PaneId) -> Vec<OtherPane> {
+ let three = three();
+ three_places()
+ .iter()
+ .filter(|(id, _)| *id != pane_id)
+ .map(|(id, rect)| OtherPane {
+ pane_id: *id,
+ cells: three.rect(*id).unwrap(),
+ rect: *rect,
+ })
+ .collect()
+ }
+
+ /// A nav bar standing along `band`, with no terminal bar to lift it:
+ /// its top in either place is where the pane's text starts there.
+ fn nav(band: RectF, buttons: f32, place: Placed, whole: Placed) -> Option<Nav> {
+ Some(Nav {
+ band,
+ buttons,
+ top_from: place.origin.1,
+ top_to: whole.origin.1,
+ })
+ }
+
+ fn area_of(rects: &[RectF]) -> f32 {
+ rects.iter().map(|rect| rect.area()).sum()
+ }
+
+ /// Whether any two of `rects` overlap.
+ fn any_overlap(rects: &[RectF]) -> bool {
+ rects.iter().enumerate().any(|(i, a)| {
+ rects[i + 1..]
+ .iter()
+ .any(|b| a.intersection(b).is_some_and(|both| both.area() > 0.01))
+ })
+ }
+
+ /// What `frame` draws of the zooming pane, painted standing at `stood`,
+ /// and fills like its own: over where it is now, each once.
+ fn zooming_drawn(frame: &SlideFrame, pane_id: PaneId, stood: RectF) -> Vec<RectF> {
+ let mut drawn: Vec<RectF> = frame
+ .pieces_of(pane_id)
+ .unwrap()
+ .iter()
+ .filter_map(|piece| piece.clip.intersection(&translated(stood, piece.shift)))
+ .collect();
+ drawn.extend(frame.fills.iter().map(|(_, rect)| *rect));
+ drawn
+ }
+
+ #[test]
+ fn a_zoom_is_read_off_the_layout_both_ways() {
+ assert_eq!(zoomed(3).zoom(&three()), Some((3, true)));
+ assert_eq!(three().zoom(&zoomed(3)), Some((3, false)));
+ // Another tab, zoomed or not.
+ let other = TabLayout {
+ tab_id: 2,
+ ..zoomed(3)
+ };
+ assert_eq!(other.zoom(&three()), None);
+ // Zoomed both frames, or neither.
+ assert_eq!(zoomed(3).zoom(&zoomed(3)), None);
+ assert_eq!(three().zoom(&three()), None);
+ // A pane alone in its tab already had all of it.
+ let one = layout(1, &[(1, [0, 0, 81, 24])]);
+ assert_eq!(zoomed(1).zoom(&one), None);
+ // A window's first frame, and a pane zoomed that was not there.
+ assert_eq!(zoomed(3).zoom(&layout(1, &[])), None);
+ assert_eq!(zoomed(9).zoom(&three()), None);
+ // Nor is it a split or a close, either way.
+ assert_eq!(three().opened_by_split(&zoomed(3)), None);
+ assert_eq!(zoomed(3).closed(&three()), None);
+ }
+
+ #[test]
+ fn a_zoom_holds_the_others_and_their_dividers_on_their_way_out() {
+ let start = Instant::now();
+ let mut slides = SplitSlides::<PaneId>::default();
+ let splits = three_splits();
+ let frame = Duration::from_millis(16);
+ assert!(slides
+ .advance(Some(three()), &[1, 2, 3], &splits, true, start)
+ .zooming
+ .is_none());
+ let mut now = start;
+ let mut steps = vec![];
+ while let Some((zooming, toward_whole)) = slides
+ .advance(Some(zoomed(3)), &[3], &[], true, now)
+ .zooming
+ {
+ slides.shown();
+ assert_eq!(zooming.pane_id, 3);
+ assert_eq!(zooming.others, vec![1, 2]);
+ assert_eq!(zooming.dividers, splits.to_vec());
+ steps.push(toward_whole);
+ now += frame;
+ assert!(steps.len() < 100);
+ }
+ // On its way from the first frame, and steadily on.
+ assert!(steps.len() >= 8, "{:?}", steps);
+ assert!(steps[0] > 0.0 && steps[0] < 0.3, "{:?}", steps);
+ assert!(steps.windows(2).all(|two| two[0] < two[1]), "{:?}", steps);
+ // Let back down: the others are the tab's again, and come back in.
+ let mut steps = vec![];
+ while let Some((zooming, toward_whole)) = slides
+ .advance(Some(three()), &[1, 2, 3], &splits, true, now)
+ .zooming
+ {
+ slides.shown();
+ assert!(zooming.others.is_empty() && zooming.dividers.is_empty());
+ steps.push(toward_whole);
+ now += frame;
+ assert!(steps.len() < 100);
+ }
+ assert!(steps.len() >= 8, "{:?}", steps);
+ assert!(steps[0] < 1.0 && steps[0] > 0.7, "{:?}", steps);
+ assert!(steps.windows(2).all(|two| two[0] > two[1]), "{:?}", steps);
+ // One on the way is cut short by the next, the other way or a split.
+ assert!(slides
+ .advance(Some(zoomed(3)), &[3], &[], true, now)
+ .zooming
+ .is_some_and(|(zooming, _)| zooming.zoomed));
+ let back = slides.advance(Some(three()), &[1, 2, 3], &splits, true, now);
+ assert!(back.zooming.is_some_and(|(zooming, _)| !zooming.zoomed));
+ let split = layout(
+ 1,
+ &[
+ (1, [0, 0, 40, 24]),
+ (2, [41, 0, 40, 11]),
+ (3, [41, 12, 20, 12]),
+ (5, [62, 12, 19, 12]),
+ ],
+ );
+ let split = slides.advance(Some(split), &[1, 2, 3, 5], &splits, true, now);
+ assert!(split.coming.is_some() && split.zooming.is_none());
+ // And a split by a zoom; zoomed again, the window stops painting.
+ let zoom = slides.advance(Some(zoomed(3)), &[3], &[], true, now);
+ assert!(zoom.coming.is_none() && zoom.zooming.is_some());
+ slides.release();
+ assert!(slides.zooming.is_none());
+ assert!(slides.last_splits.is_empty() && slides.spare_splits.is_empty());
+ }
+
+ #[test]
+ fn a_zoomed_pane_pushes_the_others_out_past_the_tabs_edges() {
+ // The pane under the top right one zooms, half way there: it has
+ // grown up and to the left, from its place's corner at 505, 230.
+ let place = placed(rect(505., 230., 405., 270.), 5.);
+ let zoom = |toward_whole| {
+ SlideFrame::zoom(
+ &zooming(true, 3, [41, 12, 40, 12]),
+ toward_whole,
+ place,
+ whole(),
+ nav(rect(100., 10., 810., 30.), 790., place, whole()),
+ &others_of(3),
+ area(),
+ )
+ };
+ let frame = zoom(0.5);
+ let now = rect(302.5, 115., 607.5, 385.);
+ // Its tabs and its text with its top left corner, half way between
+ // where they started in its place and where they end up; the
+ // buttons at the end of its nav bar along its right edge, which has
+ // not moved.
+ let text = (200., 115.);
+ assert_eq!(
+ frame.pieces_of(3),
+ Some(
+ &[
+ Drawn {
+ shift: text,
+ clip: rect(302.5, 125., 487.5, 30.),
+ },
+ Drawn {
+ shift: (0., 115.),
+ clip: rect(790., 125., 120., 30.),
+ },
+ Drawn {
+ shift: text,
+ clip: rect(302.5, 155., 607.5, 345.),
+ },
+ ][..]
+ )
+ );
+ // Laid out for the whole tab it covers all it has grown into, but
+ // for the strip above its nav bar, which is its ground.
+ assert_eq!(frame.fills, vec![(3, rect(302.5, 115., 607.5, 10.))]);
+ assert_eq!(frame.fills_shift, 115.);
+ // The pane on the left goes out to the left, ahead of its left
+ // edge; the one above goes out the top.
+ assert_eq!(
+ frame.pane_at(1, cells([0, 0, 40, 24])),
+ Some(Drawn {
+ shift: (-202.5, 0.),
+ clip: rect(100., 0., 202.5, 500.),
+ })
+ );
+ assert_eq!(
+ frame.pane_at(2, cells([41, 0, 40, 11])),
+ Some(Drawn {
+ shift: (0., -115.),
+ clip: rect(100., 0., 810., 115.),
+ })
+ );
+ // Between the two of them, over its corner, room nobody covers.
+ assert_eq!(frame.grounds, vec![(3, rect(302.5, 0., 202.5, 115.))]);
+ assert_eq!(
+ area_of(&[now, rect(100., 0., 202.5, 500.), rect(505., 0., 405., 115.)])
+ + area_of(&[frame.grounds[0].1]),
+ area().area()
+ );
+ // The dividers go with the panes beside them.
+ let [down, across] = three_splits();
+ assert_eq!(frame.split(&down).unwrap().shift, (-202.5, 0.));
+ assert_eq!(frame.split(&across).unwrap().shift, (0., -115.));
+ // All the way there, the others are all the way out.
+ let there = zoom(1.0);
+ for (pane_id, stood) in [(1, cells([0, 0, 40, 24])), (2, cells([41, 0, 40, 11]))] {
+ assert!(there.pane_at(pane_id, stood).unwrap().clip.is_empty());
+ }
+ assert!(there.grounds.is_empty());
+ }
+
+ #[test]
+ fn the_side_a_pane_lies_on_is_told_by_its_cells() {
+ // Padded at the top by more than half a cell, the ground of the pane
+ // above runs on under the nav bar of the one below.
+ let place = placed(rect(505., 230., 405., 270.), 5.);
+ let mut others = others_of(3);
+ others[1].rect = rect(505., 0., 405., 240.);
+ let frame = SlideFrame::zoom(
+ &zooming(true, 3, [41, 12, 40, 12]),
+ 0.5,
+ place,
+ whole(),
+ nav(rect(100., 10., 810., 30.), 790., place, whole()),
+ &others,
+ area(),
+ );
+ // It still goes out the top, clear of the pane zoomed.
+ assert_eq!(
+ frame.pane_at(2, cells([41, 0, 40, 11])),
+ Some(Drawn {
+ shift: (0., -115.),
+ clip: rect(100., 0., 810., 115.),
+ })
+ );
+ }
+
+ #[test]
+ fn a_nav_bar_a_terminal_bar_lifts_goes_its_own_way() {
+ // A terminal bar 20px high along the top lifts the nav bars of the
+ // panes along the tab's top edge: over the whole tab the pane's nav
+ // bar stands 20px above where its text starts, in its place it
+ // stands where its text does.
+ let place = placed(rect(505., 230., 405., 270.), 5.);
+ let whole = Placed {
+ rect: area(),
+ origin: (110., 30.),
+ };
+ let zoom = |toward_whole| {
+ SlideFrame::zoom(
+ &zooming(true, 3, [41, 12, 40, 12]),
+ toward_whole,
+ place,
+ whole,
+ Some(Nav {
+ band: rect(100., 10., 810., 30.),
+ buttons: 790.,
+ top_from: 240.,
+ top_to: 10.,
+ }),
+ &others_of(3),
+ area(),
+ )
+ };
+ // It sets out from where it stood, not the bar's height above.
+ let start = zoom(0.0);
+ assert_eq!(start.pieces_of(3).unwrap()[0].clip.min_y(), 240.);
+ let frame = zoom(0.5);
+ let pieces = frame.pieces_of(3).unwrap();
+ // The nav bar half way between, the text below it on its own way,
+ // with none of the nav bar it has under it as painted.
+ assert_eq!(pieces[0].clip, rect(302.5, 125., 487.5, 30.));
+ assert_eq!(pieces[0].shift, (200., 115.));
+ assert_eq!(pieces[2].shift, (200., 105.));
+ assert_eq!(pieces[2].clip.min_y(), 155.);
+ assert_eq!(frame.fills_shift, 115.);
+ let drawn = zooming_drawn(&frame, 3, area());
+ assert!(!any_overlap(&drawn), "{:?}", drawn);
+ assert!((area_of(&drawn) - rect(302.5, 115., 607.5, 385.).area()).abs() < 0.01);
+ }
+
+ #[test]
+ fn the_buttons_at_the_end_of_a_zoomed_panes_nav_bar_keep_to_its_right_edge() {
+ // The pane down the left zooms: it grows to the right, half way to
+ // the tab's right edge at 910.
+ let place = placed(rect(100., 0., 405., 500.), 10.);
+ let frame = SlideFrame::zoom(
+ &zooming(true, 1, [0, 0, 40, 24]),
+ 0.5,
+ place,
+ whole(),
+ nav(rect(100., 10., 810., 30.), 790., place, whole()),
+ &others_of(1),
+ area(),
+ );
+ let pieces = frame.pieces_of(1).unwrap();
+ // Its tab strip up to them, as laid out for the whole tab; they are
+ // drawn back from its end by as much as it has still to grow.
+ assert_eq!(pieces[0].clip, rect(100., 10., 487.5, 30.));
+ assert_eq!(pieces[0].shift, (0., 0.));
+ assert_eq!(pieces[1].clip, rect(587.5, 10., 120., 30.));
+ assert_eq!(pieces[1].shift, (-202.5, 0.));
+ assert_eq!(frame.fills, vec![(1, rect(100., 0., 607.5, 10.))]);
+ // The two on its right go out to the right, together.
+ for (pane_id, stood) in [(2, cells([41, 0, 40, 11])), (3, cells([41, 12, 40, 12]))] {
+ let drawn = frame.pane_at(pane_id, stood).unwrap();
+ assert_eq!(drawn.shift, (202.5, 0.));
+ assert_eq!(drawn.clip, rect(707.5, 0., 202.5, 500.));
+ }
+ assert!(frame.grounds.is_empty());
+ // Let back down, half way: laid out for its place now, the buttons
+ // still keep to its right edge, and the bar between them and its
+ // tabs is filled like its own.
+ let frame = SlideFrame::zoom(
+ &zooming(false, 1, [0, 0, 40, 24]),
+ 0.5,
+ place,
+ whole(),
+ nav(rect(100., 10., 405., 30.), 385., place, whole()),
+ &others_of(1),
+ area(),
+ );
+ let pieces = frame.pieces_of(1).unwrap();
+ assert_eq!(pieces[0].clip, rect(100., 10., 285., 30.));
+ assert_eq!(pieces[1].clip, rect(587.5, 10., 120., 30.));
+ assert_eq!(pieces[1].shift, (202.5, 0.));
+ let fills: Vec<RectF> = frame.fills.iter().map(|(_, rect)| *rect).collect();
+ assert!(fills.contains(&rect(385., 10., 202.5, 30.)), "{:?}", fills);
+ assert_eq!(frame.fills_shift, 0.);
+ }
+
+ #[test]
+ fn a_pane_let_back_down_covers_what_it_does_not_once() {
+ // The pane under the top right one, half way back into its place:
+ // laid out for that, it covers less than it has still to give up.
+ let place = placed(rect(505., 230., 405., 270.), 5.);
+ let frame = SlideFrame::zoom(
+ &zooming(false, 3, [41, 12, 40, 12]),
+ 0.5,
+ place,
+ whole(),
+ nav(rect(505., 240., 405., 30.), 790., place, whole()),
+ &others_of(3),
+ area(),
+ );
+ let now = rect(302.5, 115., 607.5, 385.);
+ // Its nav bar's band is drawn as far up as its text.
+ assert_eq!(frame.fills_shift, -115.);
+ let pieces = frame.pieces_of(3).unwrap();
+ assert_eq!(pieces[1].shift, (0., -115.));
+ // Over it, what each piece draws of the pane and what is filled
+ // like it are the whole of it, once.
+ let drawn = zooming_drawn(&frame, 3, place.rect);
+ assert!(!any_overlap(&drawn), "{:?}", drawn);
+ assert!((area_of(&drawn) - now.area()).abs() < 0.01);
+ // And around it, the others and the room between them.
+ let mut around: Vec<RectF> = vec![now];
+ for other in others_of(3) {
+ let pushed = frame.pane_at(other.pane_id, other.cells).unwrap();
+ around.extend(translated(other.rect, pushed.shift).intersection(&pushed.clip));
+ }
+ around.extend(frame.grounds.iter().map(|(_, rect)| *rect));
+ assert!(!any_overlap(&around), "{:?}", around);
+ assert!((area_of(&around) - area().area()).abs() < 0.01);
+ }
+
+ #[test]
+ fn a_zoom_taken_back_on_its_way_turns_round_where_it_has_got_to() {
+ let start = Instant::now();
+ let frame = Duration::from_millis(16);
+ let mut slides = SplitSlides::<PaneId>::default();
+ slides.advance(Some(three()), &[1, 2, 3], &[], true, start);
+ let mut now = start;
+ let mut last = 0.0;
+ for _ in 0..3 {
+ last = slides
+ .advance(Some(zoomed(3)), &[3], &[], true, now)
+ .zooming
+ .unwrap()
+ .1;
+ slides.shown();
+ now += frame;
+ }
+ let (zooming, back) = slides
+ .advance(Some(three()), &[1, 2, 3], &[], true, now)
+ .zooming
+ .unwrap();
+ assert!(!zooming.zoomed);
+ // About where it was, on its way back rather than starting over
+ // from the whole tab.
+ assert!(back < last && last - back < 0.05, "{} {}", last, back);
+ slides.shown();
+ now += frame;
+ let next = slides
+ .advance(Some(three()), &[1, 2, 3], &[], true, now)
+ .zooming
+ .unwrap()
+ .1;
+ assert!(next < back, "{} {}", back, next);
+ }
+
+ #[test]
+ fn a_tab_that_grows_while_a_zoom_is_let_down_is_all_drawn() {
+ let start = Instant::now();
+ let mut slides = SplitSlides::<PaneId>::default();
+ slides.advance(Some(zoomed(3)), &[3], &[], true, start);
+ assert!(slides
+ .advance(Some(three()), &[1, 2, 3], &[], true, start)
+ .zooming
+ .is_some());
+ let wider = layout(
+ 1,
+ &[(1, [0, 0, 45, 24]), (2, [46, 0, 45, 11]), (3, [46, 12, 45, 12])],
+ );
+ let (zooming, _) = slides
+ .advance(Some(wider), &[1, 2, 3], &[], true, start)
+ .zooming
+ .unwrap();
+ assert_eq!(zooming.whole, cells([0, 0, 91, 24]));
+ assert_eq!(zooming.place, cells([46, 12, 45, 12]));
+ }
+
+ /// `layout`, with `pane` the active one.
+ fn active(mut layout: TabLayout, pane: PaneId) -> TabLayout {
+ layout.active = Some(pane);
+ layout
+ }
+
+ #[test]
+ fn a_pane_carried_elsewhere_is_read_off_the_layout_with_those_making_way() {
+ let two = layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);
+ // 1 dropped under 2, in a stack of its own, 2 across the top.
+ let under = active(
+ shown_in(
+ layout(1, &[(2, [0, 0, 81, 12]), (1, [0, 13, 81, 11])]),
+ 1,
+ 7,
+ ),
+ 1,
+ );
+ let rearranged = under.rearranged(&two).unwrap();
+ // The one carried first, then the one that made way.
+ assert_eq!(
+ rearranged.moved,
+ vec![(1, cells([0, 0, 40, 24])), (2, cells([41, 0, 40, 24]))]
+ );
+ assert!(rearranged.hidden.is_empty());
+ // So too where the move left the other one active.
+ let from_outside = active(under, 2).rearranged(&two).unwrap();
+ assert_eq!(from_outside.moved[0].0, 1);
+ // Moved from outside the window, every stack of one pane named
+ // afresh by the resync that brings it: the one gone furthest.
+ let resynced = shown_in(
+ shown_in(
+ layout(1, &[(2, [0, 0, 81, 12]), (1, [0, 13, 81, 11])]),
+ 1,
+ 7,
+ ),
+ 2,
+ 8,
+ );
+ assert_eq!(resynced.rearranged(&two).unwrap().moved[0].0, 1);
+ // Into 2's stack: 2 out of sight under it, by its place before;
+ // 1 the one carried into another stack.
+ let joined = active(shown_in(layout(1, &[(1, [0, 0, 81, 24])]), 1, 2), 1);
+ let rearranged = joined.rearranged(&two).unwrap();
+ assert_eq!(rearranged.moved, vec![(1, cells([0, 0, 40, 24]))]);
+ assert_eq!(rearranged.hidden, vec![1]);
+ assert_eq!(rearranged.carried, vec![1]);
+ // Back out to the right of it: 2 comes out where the stack stands,
+ // and goes nowhere.
+ let out = active(
+ shown_in(
+ layout(1, &[(2, [0, 0, 40, 24]), (1, [41, 0, 40, 24])]),
+ 1,
+ 7,
+ ),
+ 1,
+ );
+ let rearranged = out.rearranged(&joined).unwrap();
+ assert_eq!(rearranged.moved, vec![(1, cells([0, 0, 81, 24]))]);
+ assert!(rearranged.hidden.is_empty());
+ // Swapped, each into the other's stack: the one carried first,
+ // second as the tab has them.
+ let swapped = active(
+ shown_in(
+ shown_in(
+ layout(1, &[(2, [0, 0, 40, 24]), (1, [41, 0, 40, 24])]),
+ 2,
+ 1,
+ ),
+ 1,
+ 2,
+ ),
+ 1,
+ );
+ let rearranged = swapped.rearranged(&two).unwrap();
+ assert_eq!(
+ rearranged.moved,
+ vec![(1, cells([0, 0, 40, 24])), (2, cells([41, 0, 40, 24]))]
+ );
+ assert_eq!(rearranged.carried, vec![1, 2]);
+ }
+
+ #[test]
+ fn panes_resized_opened_closed_or_shown_in_turn_are_not_carried() {
+ let two = layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);
+ // A divider dragged: each in the stack it was in.
+ let dragged = layout(1, &[(1, [0, 0, 50, 24]), (2, [51, 0, 30, 24])]);
+ assert_eq!(dragged.rearranged(&two), None);
+ // A split, a pane closed.
+ let split = layout(
+ 1,
+ &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 12]), (3, [41, 13, 40, 11])],
+ );
+ assert_eq!(split.rearranged(&two), None);
+ assert_eq!(layout(1, &[(1, [0, 0, 81, 24])]).rearranged(&two), None);
+ // A zoom, another tab.
+ assert_eq!(zoomed(1).rearranged(&two), None);
+ let other = shown_in(
+ layout(2, &[(2, [0, 0, 40, 24]), (1, [41, 0, 40, 24])]),
+ 1,
+ 2,
+ );
+ assert_eq!(other.rearranged(&two), None);
+ // Another of a stack's panes shown in its place.
+ let turn = shown_in(
+ layout(1, &[(3, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]),
+ 3,
+ 1,
+ );
+ assert_eq!(turn.rearranged(&two), None);
+ // A client's resync names every stack of one pane afresh: with
+ // nothing moved, and with a divider dragged at the same time.
+ let afresh = |left: usize| {
+ shown_in(
+ shown_in(
+ layout(1, &[(1, [0, 0, left, 24]), (2, [left + 1, 0, 80 - left, 24])]),
+ 1,
+ 8,
+ ),
+ 2,
+ 9,
+ )
+ };
+ assert_eq!(afresh(40).rearranged(&two), None);
+ assert_eq!(afresh(50).rearranged(&two), None);
+ }
+
+ #[test]
+ fn a_carried_panes_tabs_go_from_those_it_showed_to_its_new_stacks() {
+ let morph = |from: &[PaneId], along| NavMorph {
+ pane_id: 1,
+ from: from.to_vec(),
+ from_lead: Some(10.),
+ along,
+ };
+ let place = |pane_id, x, opacity, kept| TabPlace {
+ pane_id,
+ x,
+ opacity,
+ kept,
+ };
+ // Dropped into 2's stack: its own tab makes way for 2's, which
+ // comes up where it goes; at the end they stand as the stack's.
+ assert_eq!(
+ morph(&[1], 0.).places(&[2, 1], 100., 100., 10.),
+ vec![place(2, 10., 0., true), place(1, 10., 1., true)]
+ );
+ assert_eq!(
+ morph(&[1], 0.5).places(&[2, 1], 100., 100., 10.),
+ vec![place(2, 10., 0.5, true), place(1, 60., 1., true)]
+ );
+ assert_eq!(
+ morph(&[1], 1.).places(&[2, 1], 100., 100., 10.),
+ vec![place(2, 10., 1., true), place(1, 110., 1., true)]
+ );
+ // Dragged back out: 2's tab stays behind, fading where it was, and
+ // takes no clicks.
+ assert_eq!(
+ morph(&[2, 1], 0.25).places(&[1], 80., 100., 10.),
+ vec![place(1, 70., 1., true), place(2, 10., 0.75, false)]
+ );
+ // Its old bar scrolled, or along another edge of the window: it
+ // goes on from where its tabs stood there, not from the new bar's.
+ let scrolled = NavMorph {
+ from_lead: Some(-200.),
+ ..morph(&[2, 1], 0.)
+ };
+ assert_eq!(scrolled.places(&[1], 80., 100., 16.)[0].x, -120.);
+ }
+
+ #[test]
+ fn a_carried_pane_goes_on_from_the_tabs_its_nav_bar_showed() {
+ let start = Instant::now();
+ let two = || layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);
+ let joined = || active(shown_in(layout(1, &[(1, [0, 0, 81, 24])]), 1, 2), 1);
+ let mut slides = SplitSlides::<PaneId>::default();
+ slides.advance(Some(two()), &[1, 2], &[], true, start);
+ slides.nav(1, 16., [1]);
+ slides.nav(2, 10., [2]);
+ let (rearranging, _) = slides
+ .advance(Some(joined()), &[1], &[], true, start)
+ .rearranging
+ .unwrap();
+ assert_eq!(rearranging.tabs_before(1), Some((Some(16.), &[1][..])));
+ // 2 is not carried: it goes out of sight where it stood.
+ assert_eq!(rearranging.tabs_before(2), None);
+ // A nav bar not painted last frame: the pane showed itself.
+ let mut slides = SplitSlides::<PaneId>::default();
+ slides.advance(Some(two()), &[1, 2], &[], true, start);
+ let (rearranging, _) = slides
+ .advance(Some(joined()), &[1], &[], true, start)
+ .rearranging
+ .unwrap();
+ assert_eq!(rearranging.tabs_before(1), Some((None, &[1][..])));
+ }
+
+ #[test]
+ fn panes_rearranged_go_from_where_they_stood_until_they_get_there() {
+ let start = Instant::now();
+ let frame = Duration::from_micros(16_667);
+ let two = || layout(1, &[(1, [0, 0, 40, 24]), (2, [41, 0, 40, 24])]);
+ let joined = || active(shown_in(layout(1, &[(1, [0, 0, 81, 24])]), 1, 2), 1);
+ let mut slides = SplitSlides::<PaneId>::default();
+ slides.advance(Some(two()), &[1, 2], &[], true, start);
+ let (rearranging, first) = slides
+ .advance(Some(joined()), &[1], &[], true, start)
+ .rearranging
+ .unwrap();
+ assert_eq!(rearranging.moving().collect::<Vec<_>>(), vec![1]);
+ // 2, out of sight in the stack now, as last painted.
+ assert_eq!(rearranging.hidden, vec![2]);
+ assert!(first > 0. && first < 0.5, "{}", first);
+ let mut steps = vec![first];
+ let mut now = start;
+ loop {
+ slides.shown();
+ now += frame;
+ match slides.advance(Some(joined()), &[1], &[], true, now).rearranging {
+ Some((_, along)) => steps.push(along),
+ None => break,
+ }
+ }
+ assert!(steps.windows(2).all(|w| w[1] > w[0]), "{:?}", steps);
+ assert!(steps.len() as u32 >= MIN_FRAMES - 1, "{:?}", steps);
+ // With the setting off, they are where they go at once.
+ let mut slides = SplitSlides::<PaneId>::default();
+ slides.advance(Some(two()), &[1, 2], &[], false, start);
+ assert!(slides
+ .advance(Some(joined()), &[1], &[], false, start)
+ .rearranging
+ .is_none());
+ }
+
+ /// `pane_id` on its way from `from` to `to`, its text starting 10 in
+ /// from its corner, without a nav bar.
+ fn moving_pane(pane_id: PaneId, from: RectF, to: RectF) -> MovingPane {
+ MovingPane {
+ pane_id,
+ from: placed(from, 10.),
+ to: placed(to, 10.),
+ nav: None,
+ }
+ }
+
+ /// What `frame` draws of the panes, each painted standing where
+ /// `stood` has it, and fills: each spot of the tab once.
+ fn rearranged_drawn(frame: &SlideFrame, stood: &[(PaneId, RectF)]) -> Vec<RectF> {
+ let mut drawn: Vec<RectF> = stood
+ .iter()
+ .flat_map(|(pane_id, stood)| {
+ frame.pieces_of(*pane_id).unwrap_or(&[]).iter().filter_map(move |piece| {
+ piece
+ .clip
+ .intersection(&translated(*stood, piece.shift))
+ })
+ })
+ .collect();
+ drawn.extend(frame.rooms.iter().map(|(_, rect, _)| *rect));
+ drawn.extend(frame.backdrop.iter().copied());
+ drawn
+ }
+
+ #[test]
+ fn a_carried_pane_goes_over_the_others_and_each_spot_is_drawn_once() {
+ // 3, at the bottom right of `three`, dropped under 1: 1 gives it
+ // its lower half, and 2 takes the right side all the way down.
+ let [(_, left), (_, top_right), (_, bottom_right)] = three_places();
+ let moving = [
+ moving_pane(
+ 3,
+ bottom_right,
+ rect(100., 230., 405., 270.),
+ ),
+ moving_pane(
+ 1,
+ left,
+ rect(100., 0., 405., 230.),
+ ),
+ moving_pane(
+ 2,
+ top_right,
+ rect(505., 0., 405., 500.),
+ ),
+ ];
+ let stood = [
+ (3, rect(100., 230., 405., 270.)),
+ (1, rect(100., 0., 405., 230.)),
+ (2, rect(505., 0., 405., 500.)),
+ ];
+ for t in [0., 0.25, 0.5, 0.75, 0.99] {
+ let frame = SlideFrame::rearrange(&moving, &[], &[], t, 1., area());
+ let drawn = rearranged_drawn(&frame, &stood);
+ assert!(!any_overlap(&drawn), "{} {:?}", t, drawn);
+ assert!((area_of(&drawn) - area().area()).abs() < 1., "{} {:?}", t, drawn);
+ // The one carried is all there, over the others.
+ let now = between(bottom_right, rect(100., 230., 405., 270.), t);
+ let carried = frame.pieces_of(3).unwrap();
+ assert_eq!(area_of(&carried.iter().map(|d| d.clip).collect::<Vec<_>>()), now.area());
+ }
+ // Where it stood, painted where it goes.
+ let start = SlideFrame::rearrange(&moving, &[], &[], 0., 1., area());
+ assert_eq!(
+ start.pieces_of(3).unwrap(),
+ &[Drawn {
+ shift: (405., 0.),
+ clip: bottom_right,
+ }]
+ );
+ assert!(start.backdrop.is_empty());
+ // On its way, room none of them covers is the darker ground.
+ let half = SlideFrame::rearrange(&moving, &[], &[], 0.5, 1., area());
+ assert!(!half.backdrop.is_empty());
+ }
+
+ #[test]
+ fn panes_under_a_carried_one_are_cut_short_of_it() {
+ let [(_, left), (_, top_right), (_, bottom_right)] = three_places();
+ // 1 and 3 swapped: 2 stays, and 3 crosses it on the way over.
+ let moving = [
+ moving_pane(3, bottom_right, left),
+ moving_pane(1, left, bottom_right),
+ ];
+ let still = [(2, top_right)];
+ let frame = SlideFrame::rearrange(&moving, &still, &[], 0.5, 1., area());
+ let crossed: Vec<RectF> = frame.pieces_of(2).unwrap().iter().map(|d| d.clip).collect();
+ let carried = between(bottom_right, left, 0.5);
+ assert!(!any_overlap(&[crossed.as_slice(), &[carried]].concat()));
+ let drawn = rearranged_drawn(&frame, &[(3, left), (1, bottom_right), (2, top_right)]);
+ assert!(!any_overlap(&drawn), "{:?}", drawn);
+ assert!((area_of(&drawn) - area().area()).abs() < 1., "{:?}", drawn);
+ // One nobody crosses is drawn as it stands.
+ let start = SlideFrame::rearrange(&moving, &still, &[], 0., 1., area());
+ assert!(start.pieces_of(2).is_none());
+ // Out of sight in a stack now, where it stood under them all.
+ let joined = [moving_pane(1, left, area())];
+ let hidden = [(2, rect(505., 0., 405., 500.))];
+ let frame = SlideFrame::rearrange(&joined, &[], &hidden, 0.5, 1., area());
+ assert_eq!(
+ frame.pieces_of(2).unwrap(),
+ &[Drawn {
+ shift: (0., 0.),
+ clip: rect(707.5, 0., 202.5, 500.),
+ }]
+ );
+ assert!(frame.backdrop.is_empty());
+ }
+
+ #[test]
+ fn panes_on_their_way_are_edged_where_they_meet_the_others() {
+ let [(_, left), (_, top_right), (_, bottom_right)] = three_places();
+ let under_left = rect(100., 230., 405., 270.);
+ let (top_left, right) = (rect(100., 0., 405., 230.), rect(505., 0., 405., 500.));
+ let moving = [
+ moving_pane(3, bottom_right, under_left),
+ moving_pane(1, left, top_left),
+ moving_pane(2, top_right, right),
+ ];
+ let frame = SlideFrame::rearrange(&moving, &[], &[], 0.5, 1., area());
+ let carried = between(bottom_right, under_left, 0.5);
+ // The one carried is edged all round but along the window's
+ // bottom, each line just right of or under where it meets another,
+ // where a divider runs; the others' edges stop short of it.
+ let own: Vec<&RectF> = frame
+ .edges
+ .iter()
+ .filter(|edge| carried.inflate(1., 1.).contains_rect(edge))
+ .collect();
+ assert_eq!(
+ own,
+ vec![
+ &rect(carried.min_x(), carried.min_y(), 1., carried.height()),
+ &rect(carried.max_x(), carried.min_y(), 1., carried.height()),
+ &rect(carried.min_x(), carried.min_y(), carried.width(), 1.),
+ ]
+ );
+ let inside = carried.inflate(-1., -1.);
+ assert!(frame.edges.iter().all(|edge| {
+ own.contains(&edge)
+ || edge
+ .intersection(&inside)
+ .map_or(true, |both| both.area() < 0.01)
+ }));
+ // None runs along the window's own edges.
+ let area = area();
+ assert!(frame.edges.iter().all(|edge| {
+ let upright = edge.width() <= 1.;
+ let flat = edge.height() <= 1.;
+ let along_side = edge.min_x() <= area.min_x() || edge.max_x() >= area.max_x();
+ let along_end = edge.min_y() <= area.min_y() || edge.max_y() >= area.max_y();
+ !(upright && along_side) && !(flat && along_end)
+ }));
+ }
+
+ #[test]
+ fn dividers_beside_a_carried_pane_wait_for_it_the_rest_stay() {
+ let [(_, left), (_, top_right), (_, bottom_right)] = three_places();
+ let under_left = rect(100., 230., 405., 270.);
+ let moving = [moving_pane(3, bottom_right, under_left)];
+ let still = [(1, left), (2, top_right)];
+ let frame = SlideFrame::rearrange(&moving, &still, &[], 0.5, 1., area());
+ let clips = frame.divider_clips().unwrap();
+ // Not where it is, stood or goes, a line's width round them.
+ let carried = between(bottom_right, under_left, 0.5);
+ for gone in [carried, bottom_right.inflate(1., 1.), under_left.inflate(1., 1.)] {
+ assert!(!any_overlap(&[clips, &[gone]].concat()), "{:?}", clips);
+ }
+ // Between two panes standing still, above them all, it stays: down
+ // between 1 and 2 where neither of the others comes.
+ let between_still = rect(504., 0., 2., 200.);
+ let kept: f32 = clips
+ .iter()
+ .filter_map(|clip| clip.intersection(&between_still))
+ .map(|both| both.area())
+ .sum();
+ assert_eq!(kept, between_still.area());
+ // Nothing rearranged, none of that.
+ assert_eq!(SlideFrame::default().divider_clips(), None);
+ }
+
+ #[test]
+ fn a_divider_dragged_in_a_grid_carries_nothing() {
+ let grid = layout(
+ 1,
+ &[
+ (1, [0, 0, 40, 12]),
+ (2, [0, 13, 40, 11]),
+ (3, [41, 0, 40, 12]),
+ (4, [41, 13, 40, 11]),
+ ],
+ );
+ // The right column's divider dragged up past the left's: 1 now
+ // ends under where 4 starts, yet still lies left of it.
+ let dragged = layout(
+ 1,
+ &[
+ (1, [0, 0, 40, 12]),
+ (2, [0, 13, 40, 11]),
+ (3, [41, 0, 40, 9]),
+ (4, [41, 10, 40, 14]),
+ ],
+ );
+ assert_eq!(dragged.rearranged(&grid), None);
+ // A stack collapsed to a strip shown in turn as it expands: its
+ // neighbour gives way, one of its tabs is out of sight, another in.
+ let column = layout(1, &[(1, [0, 0, 81, 22]), (2, [0, 23, 81, 1])]);
+ let expanded = shown_in(
+ layout(1, &[(1, [0, 0, 81, 12]), (9, [0, 13, 81, 11])]),
+ 9,
+ 2,
+ );
+ assert_eq!(expanded.rearranged(&column), None);
+ }
}