fix: align compact tabs and scroll overflow continuously
Verify Tessera GUI / verify (push) Failing after 1m52s
Verify Tessera GUI / verify (push) Failing after 1m52s
This commit is contained in:
@@ -4,12 +4,12 @@ This audit follows the full conversation, including later corrections. Implement
|
||||
|
||||
| Requirement | Implementation | Evidence / limits |
|
||||
| --- | --- | --- |
|
||||
| One top row with native macOS controls | Transparent/full-size native title bar; reserved control space; 40 px tab strip | Actual Retina macOS windows viewed; native close/minimize/fullscreen controls retained |
|
||||
| One top row with native macOS controls | Transparent/full-size native title bar; reserved control space; 28 px tab strip centered with AppKit traffic lights | Actual Retina macOS windows viewed; native close/minimize/fullscreen controls retained |
|
||||
| Continuous left/top chrome | One neutral background; 56 px left rail; inset content panel | Actual main and detached windows viewed; no Tools label or rail launchers |
|
||||
| Compact symmetric round tabs, softer active state | 208 px maximum width; equal 4 px vertical insets; matching icon/close slots; no hard active stroke | Native settled UI viewed; hover and selected use the same bounds |
|
||||
| Compact symmetric round tabs, softer active state | 88–208 px width; 24 px pill with equal 2 px vertical insets; 13 px labels and matching 18 px icon/close slots; no hard active stroke | Native settled UI viewed; hover and selected use the same bounds |
|
||||
| + and startup default page | One startup request guarded against duplicate resume; + release-inside; Cmd/Ctrl+T | Immediately after restart: pages().count = 1. Two native Cmd+T actions produced three tabs |
|
||||
| New-tab motion, filled and unfilled | 200 ms cubic ease; new width grows from zero; existing bounds and + interpolate; scalar-only animation data | Real native new/close/fill operations completed; settled compression/overflow viewed. No frame-by-frame recording or Chrome timing comparison |
|
||||
| Overflow and scrolling | Separate + reservation; arrows, edge dwell and hit bounds share tab viewport | Native overflow reached; + in overflow increased VM count 7 → 8. Dragging out of + kept count at 7 |
|
||||
| New-tab motion, filled and unfilled | 220 ms cubic ease; insertion grows from the previous trailing edge; full-strip geometry and + interpolate; removed tabs shrink without remaining interactive | Real native new/close/fill operations completed; settled compression/overflow viewed. No frame-by-frame recording or Chrome timing comparison |
|
||||
| Overflow and scrolling | Separate + reservation; no arrow buttons; logical-pixel wheel/trackpad scrolling and clipped offscreen tabs; invisible drag edge dwell retained | Native overflow reached; + in overflow increased VM count 7 → 8. Dragging out of + kept count at 7 |
|
||||
| Close/activate/reorder/migrate/detach | Ordinary managed Page methods retained; animated hit bounds and drag anchors use current visual bounds | Native close and drag-out to Endor Window 2 succeeded. API detach/move-back preserved Page 1:135:0. Native cross-window drop, dwell and mixed-DPI were not re-run in this final build |
|
||||
| Four developer tools separated | Independent Page instances; Console/Sources/Network/Settings modules and separate per-view state | Earlier native top-level Sources/Console activation and read-only copy/paste verified; no nested navigation remains |
|
||||
| Four tools not default or permanently placed | No Tools menu, rail buttons or new-page tool directory; existing API/shortcut retained | Final default surfaces viewed without tool entries |
|
||||
@@ -107,3 +107,42 @@ outline. Startup displayed one default Page. Formatting, all-target offline Clip
|
||||
release bundling and diff whitespace checks passed. No automated test suite was run.
|
||||
The design skill was read from a temporary download only; no global skill, hooks
|
||||
or new application dependency was installed.
|
||||
|
||||
|
||||
## Tab motion, density and macOS alignment correction — 2026-10-25
|
||||
|
||||
Reviewed the user-provided 60 fps reference recording by extracting insertion,
|
||||
full-strip and closing frames. The reference's unfilled strip expands the new tab
|
||||
from the previous trailing edge and moves + with it; overflow scrolls the strip
|
||||
and permits a partial tab at the edge. This is analysis of the supplied recording,
|
||||
not an independently measured live Chrome/Codex session.
|
||||
|
||||
The strip now retains geometry for every tab ID, including offscreen tabs. Moving
|
||||
an existing tab into the viewport no longer treats it as a new zero-width tab.
|
||||
Geometry retargets from its sampled position during repeated operations; closed
|
||||
tabs shrink visually and are excluded from hit testing. New selection reveals only
|
||||
the required portion of the strip rather than centering the selected tab.
|
||||
|
||||
The former 160 px minimum is reduced to 88 px, and arrow controls plus their
|
||||
reserved margins are removed. Horizontal trackpad deltas and vertical mouse-wheel
|
||||
deltas over the strip both change a clamped floating-point scroll offset. Gesture
|
||||
scrolling follows input directly, while insertion, closure and automatic reveal
|
||||
use the 220 ms transition. OS momentum remains ordinary subsequent wheel input.
|
||||
No touchscreen hardware verification is claimed.
|
||||
|
||||
The 28 px row centers tabs at y=14, matching the retained AppKit controls in the
|
||||
native macOS window. Pills are 24 px high, with 2 px top/bottom margins and 13 px
|
||||
labels. A 1 × 12 px divider separates adjacent inactive tabs; it is hidden beside
|
||||
an active or hovered tab. Hover and selection retain the same pill geometry.
|
||||
|
||||
Manual native checks covered startup, + and repeated Cmd+T, dense overflow,
|
||||
vertical wheel movement to either end, hover divider suppression, tab selection
|
||||
and Cmd+W closure. Native screenshots confirmed alignment, density and absence
|
||||
of arrow controls. Physical trackpad feel, mixed-DPI cross-window drag and an
|
||||
exact frame-timing match remain unverified. A capture attempt around an insertion
|
||||
returned only one usable frame, so it is not presented as animation timing proof.
|
||||
|
||||
Formatting, all-target offline Clippy with warnings denied, release app bundling
|
||||
and whitespace checks passed. Existing geometry test fixtures were updated for
|
||||
pixel offsets and the denser layout; they were type-checked by Clippy but no
|
||||
cargo test, automated smoke script or Docker task was run.
|
||||
|
||||
+39
-17
@@ -65,7 +65,7 @@ pub struct TesseraApp {
|
||||
tab_drag_origin: Option<Point>,
|
||||
tab_drag_grab: Option<Point>,
|
||||
tab_drop_index: Option<usize>,
|
||||
tab_first: Option<usize>,
|
||||
tab_offset: Option<f32>,
|
||||
tab_motion: crate::tabs::Motion,
|
||||
tab_visual: crate::tabs::Visual,
|
||||
tab_scroll_hover: Option<TabScrollHover>,
|
||||
@@ -109,7 +109,7 @@ impl TesseraApp {
|
||||
tab_drag_origin: None,
|
||||
tab_drag_grab: None,
|
||||
tab_drop_index: None,
|
||||
tab_first: None,
|
||||
tab_offset: None,
|
||||
tab_motion: crate::tabs::Motion::default(),
|
||||
tab_visual: crate::tabs::Visual::default(),
|
||||
tab_scroll_hover: None,
|
||||
@@ -338,7 +338,7 @@ impl TesseraApp {
|
||||
self.tab_drag_origin = None;
|
||||
self.tab_drag_grab = None;
|
||||
self.tab_drop_index = None;
|
||||
self.tab_first = None;
|
||||
self.tab_offset = None;
|
||||
self.tab_scroll_hover = None;
|
||||
}
|
||||
self.guest_focus =
|
||||
@@ -550,7 +550,7 @@ impl TesseraApp {
|
||||
self.tab_visual.plus
|
||||
} else {
|
||||
crate::tabs::plus_rect(
|
||||
self.tab_first,
|
||||
self.tab_offset,
|
||||
&n.document.frame.tabs,
|
||||
window.inner_size().width as f32 / window.scale_factor() as f32,
|
||||
)
|
||||
@@ -571,11 +571,9 @@ impl TesseraApp {
|
||||
}
|
||||
let width = window.inner_size().width as f32 / window.scale_factor() as f32;
|
||||
let (id, close) = if self.tab_visual.rects.is_empty() {
|
||||
crate::tabs::hit(self.tab_first, &frame.tabs, width, self.pointer)
|
||||
crate::tabs::hit(self.tab_offset, &frame.tabs, width, self.pointer)
|
||||
} else {
|
||||
self.tab_visual.hit(self.pointer).or_else(|| {
|
||||
crate::tabs::navigation_hit(self.tab_first, &frame.tabs, width, self.pointer)
|
||||
})
|
||||
self.tab_visual.hit(self.pointer)
|
||||
}?;
|
||||
if !frame.tabs.iter().any(|tab| tab.id == id) {
|
||||
return None;
|
||||
@@ -686,7 +684,7 @@ impl TesseraApp {
|
||||
return Some(Point::new(self.pointer.x - rect.x, self.pointer.y));
|
||||
}
|
||||
crate::tabs::drag_anchor(
|
||||
self.tab_first,
|
||||
self.tab_offset,
|
||||
¤t.document.frame.tabs,
|
||||
window.inner_size().width as f32 / window.scale_factor() as f32,
|
||||
input.mount,
|
||||
@@ -709,7 +707,7 @@ impl TesseraApp {
|
||||
|
||||
fn clear_tab_scroll(&mut self) {
|
||||
self.tab_scroll_hover = None;
|
||||
if self.tab_first.take().is_some() {
|
||||
if self.tab_offset.take().is_some() {
|
||||
self.request_redraw();
|
||||
}
|
||||
for child in self.children.values_mut() {
|
||||
@@ -760,14 +758,15 @@ impl TesseraApp {
|
||||
return None;
|
||||
}
|
||||
let direction =
|
||||
crate::tabs::edge_direction(&frame.tabs, width, target.tab_first, hover.point);
|
||||
crate::tabs::edge_direction(&frame.tabs, width, target.tab_offset, hover.point);
|
||||
if direction != hover.direction {
|
||||
return None;
|
||||
}
|
||||
let first = crate::tabs::scroll_start(&frame.tabs, width, target.tab_first, direction)?;
|
||||
let first =
|
||||
crate::tabs::scroll_start(&frame.tabs, width, target.tab_offset, direction)?;
|
||||
let index = crate::tabs::insertion_index(Some(first), &frame.tabs, width, hover.point)?;
|
||||
drop(current);
|
||||
target.tab_first = Some(first);
|
||||
target.tab_offset = Some(first);
|
||||
target.request_redraw();
|
||||
Some((hover.window, index))
|
||||
});
|
||||
@@ -971,10 +970,10 @@ impl TesseraApp {
|
||||
let index = if frame.tabs.is_empty() {
|
||||
0
|
||||
} else {
|
||||
crate::tabs::insertion_index(app.tab_first, &frame.tabs, size.width, relative)?
|
||||
crate::tabs::insertion_index(app.tab_offset, &frame.tabs, size.width, relative)?
|
||||
};
|
||||
let direction =
|
||||
crate::tabs::edge_direction(&frame.tabs, size.width, app.tab_first, relative);
|
||||
crate::tabs::edge_direction(&frame.tabs, size.width, app.tab_offset, relative);
|
||||
if direction != 0 {
|
||||
scroll = Some((app.resource, frame.session, relative, direction));
|
||||
}
|
||||
@@ -1147,9 +1146,10 @@ impl TesseraApp {
|
||||
};
|
||||
self.tab_visual = self.tab_motion.sample(
|
||||
&namespace.document.frame.tabs,
|
||||
self.tab_first,
|
||||
self.tab_offset,
|
||||
size.width as f32 / window.scale_factor() as f32,
|
||||
);
|
||||
self.tab_offset = self.tab_motion.offset;
|
||||
let scene = scene::build_scene(
|
||||
size.width,
|
||||
size.height,
|
||||
@@ -1158,7 +1158,7 @@ impl TesseraApp {
|
||||
&mut self.developer_tools,
|
||||
&self.activity,
|
||||
crate::tabs::Chrome {
|
||||
first: self.tab_first,
|
||||
offset: self.tab_offset,
|
||||
insertion: self.tab_drop_index,
|
||||
pointer,
|
||||
visual: self.tab_visual.clone(),
|
||||
@@ -1478,6 +1478,28 @@ impl ApplicationHandler<AppEvent> for TesseraApp {
|
||||
dx = dy;
|
||||
dy = 0.0;
|
||||
}
|
||||
let width = window.inner_size().width as f32 / window.scale_factor() as f32;
|
||||
if self.pointer.y >= 0.0
|
||||
&& self.pointer.y < crate::tabs::HEIGHT
|
||||
&& self.pointer.x >= crate::tabs::LEADING
|
||||
&& self.pointer.x < width - 44.0
|
||||
{
|
||||
// Trackpad horizontal deltas and ordinary vertical mouse wheels both
|
||||
// browse the strip. OS momentum arrives as further pixel deltas.
|
||||
if let Ok(namespace) = self.namespace.read() {
|
||||
let delta = if dx.abs() > dy.abs() { dx } else { dy };
|
||||
let offset = crate::tabs::wheel_offset(
|
||||
&namespace.document.frame.tabs,
|
||||
width,
|
||||
self.tab_offset,
|
||||
-delta,
|
||||
);
|
||||
self.tab_offset = Some(offset);
|
||||
self.tab_motion.scroll_to(offset);
|
||||
}
|
||||
window.request_redraw();
|
||||
return;
|
||||
}
|
||||
if !self.guest_covered(self.pointer) {
|
||||
let input = self.namespace.read().ok().and_then(|namespace| {
|
||||
let frame = &namespace.document.frame;
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ pub fn build_scene(
|
||||
framed.push(DrawCommand::PopClip);
|
||||
let mut display_list = framed;
|
||||
crate::tabs::draw(
|
||||
tab_chrome.first,
|
||||
tab_chrome.offset,
|
||||
&mut display_list,
|
||||
&document.frame.tabs,
|
||||
width as f32 / scale,
|
||||
@@ -70,7 +70,7 @@ pub fn build_scene(
|
||||
);
|
||||
if let Some(index) = tab_chrome.insertion {
|
||||
crate::tabs::draw_insertion(
|
||||
tab_chrome.first,
|
||||
tab_chrome.offset,
|
||||
&mut display_list,
|
||||
&document.frame.tabs,
|
||||
width as f32 / scale,
|
||||
|
||||
+197
-181
@@ -9,15 +9,17 @@ use serde::{Deserialize, Serialize};
|
||||
mod motion;
|
||||
pub use motion::{Motion, Visual};
|
||||
|
||||
pub const HEIGHT: f32 = 40.0;
|
||||
// AppKit traffic lights are centered 14 logical pixels below the top edge.
|
||||
pub const HEIGHT: f32 = 28.0;
|
||||
pub const INSET: f32 = 8.0;
|
||||
const NEW_TAB_SPACE: f32 = 44.0;
|
||||
const MIN_WIDTH: f32 = 88.0;
|
||||
pub const RAIL: f32 = 56.0;
|
||||
pub const CONTROLS: f32 = if cfg!(target_os = "macos") { 86.0 } else { 0.0 };
|
||||
pub const LEADING: f32 = CONTROLS + 12.0;
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Chrome {
|
||||
pub first: Option<usize>,
|
||||
pub offset: Option<f32>,
|
||||
pub insertion: Option<usize>,
|
||||
pub pointer: Option<Point>,
|
||||
pub visual: Visual,
|
||||
@@ -36,110 +38,109 @@ pub fn height(tabs: &[Tab]) -> f32 {
|
||||
HEIGHT
|
||||
}
|
||||
|
||||
/// A drag viewport is presentation state only: it never activates a Page.
|
||||
fn visible_range(tabs: &[Tab], width: f32, start: Option<usize>) -> std::ops::Range<usize> {
|
||||
let count = (((width - LEADING - NEW_TAB_SPACE - 64.0) / 160.0)
|
||||
.floor()
|
||||
.max(1.0) as usize)
|
||||
.min(tabs.len());
|
||||
if tabs.len() <= count {
|
||||
return 0..tabs.len();
|
||||
}
|
||||
/// Scroll offsets are logical pixels, never a discrete page index.
|
||||
fn viewport(width: f32) -> Rect {
|
||||
Rect::new(
|
||||
LEADING,
|
||||
0.0,
|
||||
(width - NEW_TAB_SPACE - LEADING).max(0.0),
|
||||
HEIGHT,
|
||||
)
|
||||
}
|
||||
fn tab_width(tabs: &[Tab], width: f32) -> f32 {
|
||||
(viewport(width).width / tabs.len().max(1) as f32)
|
||||
.clamp(MIN_WIDTH, 208.0)
|
||||
.min(viewport(width).width)
|
||||
}
|
||||
fn scroll_offset(tabs: &[Tab], width: f32, start: Option<f32>) -> f32 {
|
||||
let tab_width = tab_width(tabs, width);
|
||||
let available = viewport(width).width;
|
||||
let maximum = (tabs.len() as f32 * tab_width - available).max(0.0);
|
||||
let active = tabs.iter().position(|tab| tab.active).unwrap_or(0);
|
||||
let first = start
|
||||
.unwrap_or_else(|| active.saturating_sub(count / 2))
|
||||
.min(tabs.len() - count);
|
||||
first..first + count
|
||||
start
|
||||
.unwrap_or(((active + 1) as f32 * tab_width - available).max(0.0))
|
||||
.clamp(0.0, maximum)
|
||||
}
|
||||
#[cfg(test)]
|
||||
fn visible_range(tabs: &[Tab], width: f32, start: Option<f32>) -> std::ops::Range<usize> {
|
||||
let tab_width = tab_width(tabs, width);
|
||||
if tab_width <= 0.0 {
|
||||
return 0..0;
|
||||
}
|
||||
let offset = scroll_offset(tabs, width, start);
|
||||
(offset / tab_width).floor() as usize
|
||||
..(((offset + viewport(width).width) / tab_width).ceil() as usize).min(tabs.len())
|
||||
}
|
||||
|
||||
pub fn edge_direction(tabs: &[Tab], width: f32, start: Option<usize>, point: Point) -> i8 {
|
||||
if point.x < LEADING || point.x >= width - NEW_TAB_SPACE || point.y < 0.0 || point.y >= HEIGHT {
|
||||
/// Invisible drag edge zones only; ordinary clicks never scroll or activate another tab.
|
||||
pub fn edge_direction(tabs: &[Tab], width: f32, start: Option<f32>, point: Point) -> i8 {
|
||||
if !viewport(width).contains(point) || point.y >= HEIGHT {
|
||||
return 0;
|
||||
}
|
||||
let visible = visible_range(tabs, width, start);
|
||||
if point.x >= LEADING && point.x < LEADING + 32.0 && visible.start > 0 {
|
||||
let offset = scroll_offset(tabs, width, start);
|
||||
let maximum = (tabs.len() as f32 * tab_width(tabs, width) - viewport(width).width).max(0.0);
|
||||
if point.x < LEADING + 24.0 && offset > 0.0 {
|
||||
-1
|
||||
} else if point.x >= width - NEW_TAB_SPACE - 32.0 && visible.end < tabs.len() {
|
||||
} else if point.x > width - NEW_TAB_SPACE - 24.0 && offset < maximum {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scroll_start(
|
||||
tabs: &[Tab],
|
||||
width: f32,
|
||||
start: Option<usize>,
|
||||
direction: i8,
|
||||
) -> Option<usize> {
|
||||
let visible = visible_range(tabs, width, start);
|
||||
if direction < 0 && visible.start > 0 {
|
||||
Some(visible.start - 1)
|
||||
} else if direction > 0 && visible.end < tabs.len() {
|
||||
Some(visible.start + 1)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
pub fn wheel_offset(tabs: &[Tab], width: f32, start: Option<f32>, delta: f32) -> f32 {
|
||||
scroll_offset(tabs, width, Some(scroll_offset(tabs, width, start) + delta))
|
||||
}
|
||||
pub fn scroll_start(tabs: &[Tab], width: f32, start: Option<f32>, direction: i8) -> Option<f32> {
|
||||
let current = scroll_offset(tabs, width, start);
|
||||
let next = wheel_offset(tabs, width, Some(current), direction as f32 * MIN_WIDTH);
|
||||
(next != current).then_some(next)
|
||||
}
|
||||
|
||||
struct Item<'a> {
|
||||
tab: &'a Tab,
|
||||
rect: Rect,
|
||||
navigation: Option<&'static str>,
|
||||
}
|
||||
fn items(start: Option<usize>, tabs: &[Tab], width: f32) -> Vec<Item<'_>> {
|
||||
if tabs.is_empty() || width <= 0.0 {
|
||||
return Vec::new();
|
||||
}
|
||||
let visible = visible_range(tabs, width, start);
|
||||
let start = visible.start;
|
||||
let count = visible.len();
|
||||
let overflow = count < tabs.len();
|
||||
let margin = if overflow { 32.0 } else { 0.0 };
|
||||
let width = width - NEW_TAB_SPACE;
|
||||
let tab_width = ((width - LEADING - margin * 2.0) / count as f32).min(208.0);
|
||||
let mut result = Vec::new();
|
||||
if overflow && start > 0 {
|
||||
result.push(Item {
|
||||
tab: &tabs[start - 1],
|
||||
rect: Rect::new(LEADING, 0.0, 32.0, HEIGHT),
|
||||
navigation: Some("‹"),
|
||||
});
|
||||
}
|
||||
for (index, tab) in tabs[start..start + count].iter().enumerate() {
|
||||
result.push(Item {
|
||||
tab,
|
||||
rect: Rect::new(
|
||||
LEADING + margin + index as f32 * tab_width,
|
||||
0.0,
|
||||
tab_width,
|
||||
HEIGHT,
|
||||
),
|
||||
navigation: None,
|
||||
});
|
||||
}
|
||||
if overflow && start + count < tabs.len() {
|
||||
result.push(Item {
|
||||
tab: &tabs[start + count],
|
||||
rect: Rect::new(width - 32.0, 0.0, 32.0, HEIGHT),
|
||||
navigation: Some("›"),
|
||||
});
|
||||
}
|
||||
result
|
||||
/// Retain all IDs, including clipped tabs, for continuous movement through the viewport.
|
||||
fn tab_rects(start: Option<f32>, tabs: &[Tab], width: f32) -> Vec<(u64, Rect)> {
|
||||
let tab_width = tab_width(tabs, width);
|
||||
let offset = scroll_offset(tabs, width, start);
|
||||
tabs.iter()
|
||||
.enumerate()
|
||||
.map(|(index, tab)| {
|
||||
(
|
||||
tab.id,
|
||||
Rect::new(
|
||||
LEADING + index as f32 * tab_width - offset,
|
||||
0.0,
|
||||
tab_width,
|
||||
HEIGHT,
|
||||
),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
fn items(start: Option<f32>, tabs: &[Tab], width: f32) -> Vec<Item<'_>> {
|
||||
let viewport = viewport(width);
|
||||
tabs.iter()
|
||||
.zip(tab_rects(start, tabs, width))
|
||||
.filter(|(_, (_, rect))| {
|
||||
rect.x + rect.width > viewport.x && rect.x < viewport.x + viewport.width
|
||||
})
|
||||
.map(|(tab, (_, rect))| Item { tab, rect })
|
||||
.collect()
|
||||
}
|
||||
fn pill_rect(rect: Rect) -> Rect {
|
||||
Rect::new(rect.x + 2.0, 4.0, (rect.width - 4.0).max(0.0), HEIGHT - 8.0)
|
||||
Rect::new(rect.x + 2.0, 2.0, (rect.width - 4.0).max(0.0), HEIGHT - 4.0)
|
||||
}
|
||||
fn close_rect(rect: Rect) -> Rect {
|
||||
Rect::new(
|
||||
rect.x + rect.width - 28.0,
|
||||
(HEIGHT - 20.0) / 2.0,
|
||||
20.0,
|
||||
20.0,
|
||||
rect.x + rect.width - 25.0,
|
||||
(HEIGHT - 18.0) / 2.0,
|
||||
18.0,
|
||||
18.0,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn hit(start: Option<usize>, tabs: &[Tab], width: f32, point: Point) -> Option<(u64, bool)> {
|
||||
pub fn hit(start: Option<f32>, tabs: &[Tab], width: f32, point: Point) -> Option<(u64, bool)> {
|
||||
if point.x < LEADING
|
||||
|| point.x >= width - NEW_TAB_SPACE
|
||||
|| point.y < 0.0
|
||||
@@ -150,29 +151,12 @@ pub fn hit(start: Option<usize>, tabs: &[Tab], width: f32, point: Point) -> Opti
|
||||
items(start, tabs, width)
|
||||
.into_iter()
|
||||
.find(|item| pill_rect(item.rect).contains(point))
|
||||
.map(|item| {
|
||||
(
|
||||
item.tab.id,
|
||||
item.navigation.is_none() && close_rect(item.rect).contains(point),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn navigation_hit(
|
||||
start: Option<usize>,
|
||||
tabs: &[Tab],
|
||||
width: f32,
|
||||
point: Point,
|
||||
) -> Option<(u64, bool)> {
|
||||
items(start, tabs, width)
|
||||
.iter()
|
||||
.find(|item| item.navigation.is_some() && pill_rect(item.rect).contains(point))
|
||||
.map(|item| (item.tab.id, false))
|
||||
.map(|item| (item.tab.id, close_rect(item.rect).contains(point)))
|
||||
}
|
||||
|
||||
/// Gap index in the complete published order, including overflow-hidden tabs.
|
||||
pub fn insertion_index(
|
||||
start: Option<usize>,
|
||||
start: Option<f32>,
|
||||
tabs: &[Tab],
|
||||
width: f32,
|
||||
point: Point,
|
||||
@@ -183,10 +167,7 @@ pub fn insertion_index(
|
||||
if tabs.is_empty() {
|
||||
return Some(0);
|
||||
}
|
||||
let visible: Vec<_> = items(start, tabs, width)
|
||||
.into_iter()
|
||||
.filter(|item| item.navigation.is_none())
|
||||
.collect();
|
||||
let visible: Vec<_> = items(start, tabs, width).into_iter().collect();
|
||||
for item in &visible {
|
||||
if point.x < item.rect.x + item.rect.width / 2.0 {
|
||||
return tabs.iter().position(|tab| tab.id == item.tab.id);
|
||||
@@ -199,30 +180,30 @@ pub fn insertion_index(
|
||||
}
|
||||
|
||||
pub fn drag_anchor(
|
||||
start: Option<usize>,
|
||||
start: Option<f32>,
|
||||
tabs: &[Tab],
|
||||
width: f32,
|
||||
id: u64,
|
||||
point: Point,
|
||||
) -> Option<Point> {
|
||||
let item = items(start, tabs, width).into_iter().find(|item| {
|
||||
item.tab.id == id && item.navigation.is_none() && pill_rect(item.rect).contains(point)
|
||||
})?;
|
||||
if !viewport(width).contains(point) {
|
||||
return None;
|
||||
}
|
||||
let item = items(start, tabs, width)
|
||||
.into_iter()
|
||||
.find(|item| item.tab.id == id && pill_rect(item.rect).contains(point))?;
|
||||
(!close_rect(item.rect).contains(point)).then(|| Point::new(point.x - item.rect.x, point.y))
|
||||
}
|
||||
|
||||
pub fn draw_insertion(
|
||||
start: Option<usize>,
|
||||
start: Option<f32>,
|
||||
list: &mut DisplayList,
|
||||
tabs: &[Tab],
|
||||
width: f32,
|
||||
index: usize,
|
||||
scale: f32,
|
||||
) {
|
||||
let visible: Vec<_> = items(start, tabs, width)
|
||||
.into_iter()
|
||||
.filter(|item| item.navigation.is_none())
|
||||
.collect();
|
||||
let visible: Vec<_> = items(start, tabs, width).into_iter().collect();
|
||||
let x = if tabs.is_empty() {
|
||||
Some(LEADING + 8.0)
|
||||
} else {
|
||||
@@ -253,16 +234,27 @@ pub fn draw_insertion(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plus_rect(start: Option<usize>, tabs: &[Tab], width: f32) -> Rect {
|
||||
pub fn plus_rect(start: Option<f32>, tabs: &[Tab], width: f32) -> Rect {
|
||||
if tabs.len() as f32 * tab_width(tabs, width) > viewport(width).width {
|
||||
return Rect::new(width - 34.0, 2.0, 24.0, HEIGHT - 4.0);
|
||||
}
|
||||
let end = items(start, tabs, width)
|
||||
.iter()
|
||||
.map(|item| item.rect.x + item.rect.width)
|
||||
.fold(LEADING, f32::max);
|
||||
Rect::new((end + 4.0).min(width - 38.0), 4.0, 32.0, HEIGHT - 8.0)
|
||||
Rect::new((end + 4.0).min(width - 34.0), 2.0, 24.0, HEIGHT - 4.0)
|
||||
}
|
||||
|
||||
fn tab_style() -> TextStyle {
|
||||
TextStyle {
|
||||
font_size: 13.0,
|
||||
line_height: 18.0,
|
||||
..TextStyle::ui(1)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(
|
||||
start: Option<usize>,
|
||||
_start: Option<f32>,
|
||||
list: &mut DisplayList,
|
||||
tabs: &[Tab],
|
||||
width: f32,
|
||||
@@ -287,7 +279,7 @@ pub fn draw(
|
||||
if pointer.is_some_and(|point| plus.contains(point)) {
|
||||
list.push(DrawCommand::FillRoundedRect {
|
||||
rect: scaled(plus),
|
||||
radius: 8.0 * scale,
|
||||
radius: 6.0 * scale,
|
||||
color: crate::system_ui::theme::mix(
|
||||
crate::system_ui::theme::BAR,
|
||||
crate::system_ui::theme::TEXT,
|
||||
@@ -297,24 +289,43 @@ pub fn draw(
|
||||
}
|
||||
list.push(DrawCommand::Text {
|
||||
origin: Point::new(
|
||||
(plus.x + (plus.width - crate::text::measure("+", TextStyle::ui(1)).width) / 2.0)
|
||||
* scale,
|
||||
((HEIGHT - TextStyle::ui(1).line_height) / 2.0) * scale,
|
||||
(plus.x + (plus.width - crate::text::measure("+", tab_style()).width) / 2.0) * scale,
|
||||
((HEIGHT - tab_style().line_height) / 2.0) * scale,
|
||||
),
|
||||
value: "+".into(),
|
||||
style: TextStyle::ui(1).scaled(scale),
|
||||
style: tab_style().scaled(scale),
|
||||
color: crate::system_ui::theme::MUTED,
|
||||
});
|
||||
for mut item in items(start, tabs, width) {
|
||||
if item.navigation.is_none() {
|
||||
item.rect = visual.rect(item.tab.id, item.rect);
|
||||
let mut paint_items: Vec<_> = tabs
|
||||
.iter()
|
||||
.map(|tab| Item {
|
||||
tab,
|
||||
rect: visual.rect(tab.id, Rect::default()),
|
||||
})
|
||||
.collect();
|
||||
paint_items.extend(
|
||||
visual
|
||||
.exiting
|
||||
.iter()
|
||||
.map(|(tab, rect)| Item { tab, rect: *rect }),
|
||||
);
|
||||
for item in paint_items {
|
||||
{
|
||||
if item.rect.width <= 0.0
|
||||
|| item.rect.x + item.rect.width <= visual.viewport.x
|
||||
|| item.rect.x >= visual.viewport.x + visual.viewport.width
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.push(DrawCommand::PushClip(scaled(visual.viewport)));
|
||||
list.push(DrawCommand::PushClip(scaled(pill_rect(item.rect))));
|
||||
}
|
||||
let pill = scaled(pill_rect(item.rect));
|
||||
let active = item.tab.active && item.navigation.is_none();
|
||||
let active = item.tab.active;
|
||||
if active || pointer.is_some_and(|point| pill_rect(item.rect).contains(point)) {
|
||||
list.push(DrawCommand::FillRoundedRect {
|
||||
rect: pill,
|
||||
radius: 8.0 * scale,
|
||||
radius: 6.0 * scale,
|
||||
color: if active {
|
||||
crate::system_ui::theme::BG
|
||||
} else {
|
||||
@@ -326,54 +337,37 @@ pub fn draw(
|
||||
},
|
||||
});
|
||||
}
|
||||
if item.navigation.is_none() && item.rect.width >= 66.0 {
|
||||
// Same 20px slot and 8px edge inset as the close button.
|
||||
{
|
||||
// Match the close button with an 18px slot and 7px edge inset.
|
||||
let icon = "◇";
|
||||
list.push(DrawCommand::Text {
|
||||
origin: Point::new(
|
||||
(item.rect.x
|
||||
+ 8.0
|
||||
+ (20.0 - crate::text::measure(icon, TextStyle::ui(1)).width) / 2.0)
|
||||
+ 7.0
|
||||
+ (18.0 - crate::text::measure(icon, tab_style()).width) / 2.0)
|
||||
* scale,
|
||||
((HEIGHT - TextStyle::ui(1).line_height) / 2.0) * scale,
|
||||
((HEIGHT - tab_style().line_height) / 2.0) * scale,
|
||||
),
|
||||
value: icon.into(),
|
||||
style: TextStyle::ui(1).scaled(scale),
|
||||
style: tab_style().scaled(scale),
|
||||
color: crate::system_ui::theme::MUTED,
|
||||
});
|
||||
}
|
||||
let title = item.navigation.unwrap_or(&item.tab.title);
|
||||
let title = &item.tab.title;
|
||||
let text_rect = Rect::new(
|
||||
item.rect.x
|
||||
+ if item.navigation.is_some() {
|
||||
10.0
|
||||
} else {
|
||||
34.0
|
||||
},
|
||||
(HEIGHT - TextStyle::ui(1).line_height) / 2.0,
|
||||
(item.rect.width
|
||||
- if item.navigation.is_some() {
|
||||
12.0
|
||||
} else {
|
||||
66.0
|
||||
})
|
||||
.max(0.0),
|
||||
TextStyle::ui(1).line_height,
|
||||
item.rect.x + 30.0,
|
||||
(HEIGHT - tab_style().line_height) / 2.0,
|
||||
(item.rect.width - 58.0).max(0.0),
|
||||
tab_style().line_height,
|
||||
);
|
||||
list.push(DrawCommand::PushClip(scaled(text_rect)));
|
||||
list.push(DrawCommand::Text {
|
||||
origin: Point::new(
|
||||
(item.rect.x
|
||||
+ if item.navigation.is_some() {
|
||||
10.0
|
||||
} else {
|
||||
34.0
|
||||
})
|
||||
* scale,
|
||||
((HEIGHT - TextStyle::ui(1).line_height) / 2.0) * scale,
|
||||
(item.rect.x + 30.0) * scale,
|
||||
((HEIGHT - tab_style().line_height) / 2.0) * scale,
|
||||
),
|
||||
value: title.into(),
|
||||
style: TextStyle::ui(1).scaled(scale),
|
||||
style: tab_style().scaled(scale),
|
||||
color: if active {
|
||||
crate::system_ui::theme::TEXT
|
||||
} else {
|
||||
@@ -381,7 +375,7 @@ pub fn draw(
|
||||
},
|
||||
});
|
||||
list.push(DrawCommand::PopClip);
|
||||
if item.navigation.is_none() && item.rect.width >= 44.0 {
|
||||
if item.rect.width >= 44.0 {
|
||||
if pointer.is_some_and(|point| close_rect(item.rect).contains(point)) {
|
||||
list.push(DrawCommand::FillRoundedRect {
|
||||
rect: scaled(close_rect(item.rect)),
|
||||
@@ -397,24 +391,54 @@ pub fn draw(
|
||||
origin: Point::new(
|
||||
(close_rect(item.rect).x
|
||||
+ (close_rect(item.rect).width
|
||||
- crate::text::measure("×", TextStyle::ui(1)).width)
|
||||
- crate::text::measure("×", tab_style()).width)
|
||||
/ 2.0)
|
||||
* scale,
|
||||
((HEIGHT - TextStyle::ui(1).line_height) / 2.0) * scale,
|
||||
((HEIGHT - tab_style().line_height) / 2.0) * scale,
|
||||
),
|
||||
value: "×".into(),
|
||||
style: TextStyle::ui(1).scaled(scale),
|
||||
style: tab_style().scaled(scale),
|
||||
color: crate::system_ui::theme::MUTED,
|
||||
});
|
||||
}
|
||||
{
|
||||
list.push(DrawCommand::PopClip);
|
||||
list.push(DrawCommand::PopClip);
|
||||
}
|
||||
}
|
||||
// Quiet boundaries only between two idle tabs; the active/hovered pill owns its edges.
|
||||
list.push(DrawCommand::PushClip(scaled(visual.viewport)));
|
||||
for pair in tabs.windows(2) {
|
||||
let left = visual.rect(pair[0].id, Rect::default());
|
||||
let right = visual.rect(pair[1].id, Rect::default());
|
||||
let hovered = pointer.is_some_and(|point| {
|
||||
pill_rect(left).contains(point) || pill_rect(right).contains(point)
|
||||
});
|
||||
if !pair[0].active && !pair[1].active && !hovered {
|
||||
list.push(DrawCommand::FillRoundedRect {
|
||||
rect: scaled(Rect::new(
|
||||
left.x + left.width - 0.5,
|
||||
(HEIGHT - 12.0) / 2.0,
|
||||
1.0,
|
||||
12.0,
|
||||
)),
|
||||
radius: 0.5 * scale,
|
||||
color: crate::system_ui::theme::mix(
|
||||
crate::system_ui::theme::BAR,
|
||||
crate::system_ui::theme::TEXT,
|
||||
0.18,
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
list.push(DrawCommand::PopClip);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn insertion_gaps_share_visible_tab_geometry_and_exclude_close_and_arrow_drags() {
|
||||
fn insertion_gaps_share_visible_tab_geometry_and_exclude_close_drags() {
|
||||
let tabs: Vec<_> = (1..=4)
|
||||
.map(|id| Tab {
|
||||
id,
|
||||
@@ -501,7 +525,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overflow_keeps_active_page_visible_and_navigation_reaches_other_pages() {
|
||||
fn overflow_keeps_active_page_visible_without_navigation_buttons() {
|
||||
let tabs: Vec<_> = (1..=64)
|
||||
.map(|id| Tab {
|
||||
id,
|
||||
@@ -511,16 +535,12 @@ mod tests {
|
||||
})
|
||||
.collect();
|
||||
let visible = items(None, &tabs, LEADING + NEW_TAB_SPACE + 720.0);
|
||||
assert!(
|
||||
visible
|
||||
.iter()
|
||||
.any(|item| item.tab.active && item.navigation.is_none())
|
||||
);
|
||||
assert!(visible.iter().any(|item| item.tab.active));
|
||||
for item in &visible {
|
||||
let point = Point::new(item.rect.x + 12.0, 18.0);
|
||||
let point = Point::new((item.rect.x + 12.0).max(LEADING + 3.0), 18.0);
|
||||
assert_eq!(
|
||||
hit(None, &tabs, LEADING + NEW_TAB_SPACE + 720.0, point),
|
||||
Some((item.tab.id, false))
|
||||
Some((item.tab.id, close_rect(item.rect).contains(point)))
|
||||
);
|
||||
}
|
||||
let tab = visible.iter().find(|item| item.tab.active).unwrap();
|
||||
@@ -559,7 +579,7 @@ mod tests {
|
||||
while let Some(next) = scroll_start(&tabs, width, start, 1) {
|
||||
start = Some(next);
|
||||
}
|
||||
assert_eq!(visible_range(&tabs, width, start), 60..64);
|
||||
assert_eq!(visible_range(&tabs, width, start), 55..64);
|
||||
assert_eq!(
|
||||
edge_direction(&tabs, width, start, Point::new(LEADING + 710.0, 18.0)),
|
||||
0
|
||||
@@ -571,7 +591,7 @@ mod tests {
|
||||
while let Some(next) = scroll_start(&tabs, width, start, -1) {
|
||||
start = Some(next);
|
||||
}
|
||||
assert_eq!(visible_range(&tabs, width, start), 0..4);
|
||||
assert_eq!(visible_range(&tabs, width, start), 0..9);
|
||||
assert_eq!(
|
||||
edge_direction(&tabs, width, start, Point::new(LEADING + 10.0, 18.0)),
|
||||
0
|
||||
@@ -587,16 +607,12 @@ mod tests {
|
||||
.collect::<Vec<_>>(),
|
||||
vec![32]
|
||||
);
|
||||
assert!(
|
||||
items(None, &tabs, width)
|
||||
.iter()
|
||||
.any(|item| item.tab.active && item.navigation.is_none())
|
||||
);
|
||||
assert!(items(None, &tabs, width).iter().any(|item| item.tab.active));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scrolled_hit_and_gap_geometry_survive_resize_and_list_shrink() {
|
||||
let tabs: Vec<_> = (1..=8)
|
||||
let tabs: Vec<_> = (1..=16)
|
||||
.map(|id| Tab {
|
||||
id,
|
||||
title: id.to_string(),
|
||||
@@ -604,7 +620,7 @@ mod tests {
|
||||
active: id == 1,
|
||||
})
|
||||
.collect();
|
||||
let start = Some(4);
|
||||
let start = Some(4.0 * MIN_WIDTH);
|
||||
assert_eq!(
|
||||
hit(
|
||||
start,
|
||||
@@ -629,7 +645,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
visible_range(&tabs, LEADING + NEW_TAB_SPACE + 1920.0, start),
|
||||
0..8
|
||||
0..16
|
||||
);
|
||||
assert_eq!(
|
||||
edge_direction(
|
||||
|
||||
+133
-31
@@ -5,6 +5,8 @@ use std::time::{Duration, Instant};
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Visual {
|
||||
pub rects: Vec<(u64, Rect)>,
|
||||
pub exiting: Vec<(Tab, Rect)>,
|
||||
pub viewport: Rect,
|
||||
pub plus: Rect,
|
||||
}
|
||||
impl Visual {
|
||||
@@ -15,6 +17,9 @@ impl Visual {
|
||||
.map_or(fallback, |(_, rect)| *rect)
|
||||
}
|
||||
pub fn hit(&self, point: Point) -> Option<(u64, bool)> {
|
||||
if !self.viewport.contains(point) {
|
||||
return None;
|
||||
}
|
||||
self.rects
|
||||
.iter()
|
||||
.rev()
|
||||
@@ -27,7 +32,11 @@ pub struct Motion {
|
||||
target: Visual,
|
||||
from: Visual,
|
||||
current: Visual,
|
||||
published: Vec<Tab>,
|
||||
initialized: bool,
|
||||
direct_scroll: bool,
|
||||
started: Option<Instant>,
|
||||
pub offset: Option<f32>,
|
||||
pub next_frame: Option<Instant>,
|
||||
}
|
||||
fn blend(a: Rect, b: Rect, t: f32) -> Rect {
|
||||
@@ -39,44 +48,137 @@ fn blend(a: Rect, b: Rect, t: f32) -> Rect {
|
||||
)
|
||||
}
|
||||
impl Motion {
|
||||
pub fn sample(&mut self, tabs: &[Tab], first: Option<usize>, width: f32) -> Visual {
|
||||
let now = Instant::now();
|
||||
let target = Visual {
|
||||
rects: items(first, tabs, width)
|
||||
pub fn scroll_to(&mut self, offset: f32) {
|
||||
self.offset = Some(offset);
|
||||
self.direct_scroll = true;
|
||||
}
|
||||
|
||||
fn advance(&mut self, now: Instant) {
|
||||
let t = self.started.map_or(1.0, |start| {
|
||||
(now.duration_since(start).as_secs_f32() / 0.22).min(1.0)
|
||||
});
|
||||
let eased = 1.0 - (1.0 - t).powi(3);
|
||||
self.current = Visual {
|
||||
rects: self
|
||||
.target
|
||||
.rects
|
||||
.iter()
|
||||
.filter(|item| item.navigation.is_none())
|
||||
.map(|item| (item.tab.id, item.rect))
|
||||
.map(|(id, target)| (*id, blend(self.from.rect(*id, *target), *target, eased)))
|
||||
.collect(),
|
||||
plus: plus_rect(first, tabs, width),
|
||||
exiting: self
|
||||
.target
|
||||
.exiting
|
||||
.iter()
|
||||
.filter(|_| t < 1.0)
|
||||
.map(|(tab, target)| {
|
||||
let from = self
|
||||
.from
|
||||
.exiting
|
||||
.iter()
|
||||
.find(|(old, _)| old.id == tab.id)
|
||||
.map_or(*target, |(_, rect)| *rect);
|
||||
(tab.clone(), blend(from, *target, eased))
|
||||
})
|
||||
.collect(),
|
||||
viewport: blend(self.from.viewport, self.target.viewport, eased),
|
||||
plus: blend(self.from.plus, self.target.plus, eased),
|
||||
};
|
||||
if self.target.rects != target.rects || self.target.plus != target.plus {
|
||||
self.next_frame = (t < 1.0).then(|| now + Duration::from_millis(16));
|
||||
}
|
||||
|
||||
pub fn sample(&mut self, tabs: &[Tab], offset: Option<f32>, width: f32) -> Visual {
|
||||
let now = Instant::now();
|
||||
// Retarget from the geometry at this instant, even during rapid repeated clicks.
|
||||
self.advance(now);
|
||||
let mut offset = scroll_offset(tabs, width, offset.or(self.offset));
|
||||
let selection_changed = self
|
||||
.published
|
||||
.iter()
|
||||
.find(|tab| tab.active)
|
||||
.map(|tab| tab.id)
|
||||
!= tabs.iter().find(|tab| tab.active).map(|tab| tab.id);
|
||||
if selection_changed {
|
||||
let active = tabs.iter().position(|tab| tab.active).unwrap_or(0) as f32;
|
||||
let tab_width = tab_width(tabs, width);
|
||||
let left = active * tab_width;
|
||||
let right = left + tab_width;
|
||||
offset = offset.min(left).max(right - viewport(width).width).max(0.0);
|
||||
}
|
||||
self.offset = Some(offset);
|
||||
let mut target = Visual {
|
||||
rects: tab_rects(Some(offset), tabs, width),
|
||||
viewport: viewport(width),
|
||||
plus: plus_rect(Some(offset), tabs, width),
|
||||
..Visual::default()
|
||||
};
|
||||
if !self.initialized || self.direct_scroll {
|
||||
self.direct_scroll = false;
|
||||
self.started = None;
|
||||
self.next_frame = None;
|
||||
// Startup is already laid out; it is not an insertion of every restored tab.
|
||||
self.initialized = true;
|
||||
self.current = target.clone();
|
||||
self.from = target.clone();
|
||||
self.target = target;
|
||||
self.published = tabs.to_vec();
|
||||
return self.current.clone();
|
||||
}
|
||||
if self.target.rects != target.rects
|
||||
|| self.target.plus != target.plus
|
||||
|| self.target.viewport != target.viewport
|
||||
{
|
||||
self.from = self.current.clone();
|
||||
for (index, (id, rect)) in target.rects.iter().enumerate() {
|
||||
if !self.from.rects.iter().any(|(old, _)| old == id) {
|
||||
// Grow out of the previous trailing edge, not the final compressed x.
|
||||
let x = target.rects[..index]
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|(previous, _)| {
|
||||
self.from
|
||||
.rects
|
||||
.iter()
|
||||
.find(|(old, _)| old == previous)
|
||||
.map(|(_, previous)| previous.x + previous.width)
|
||||
})
|
||||
.unwrap_or(rect.x);
|
||||
self.from
|
||||
.rects
|
||||
.push((*id, Rect::new(x, rect.y, 0.0, rect.height)));
|
||||
}
|
||||
}
|
||||
for tab in &self.published {
|
||||
if !tabs.iter().any(|live| live.id == tab.id) {
|
||||
self.from
|
||||
.exiting
|
||||
.push((tab.clone(), self.current.rect(tab.id, Rect::default())));
|
||||
}
|
||||
}
|
||||
// A closed tab shrinks with the gap; it never remains an interactive target.
|
||||
target.exiting = self
|
||||
.from
|
||||
.exiting
|
||||
.iter()
|
||||
.filter(|(tab, _)| !tabs.iter().any(|live| live.id == tab.id))
|
||||
.map(|(tab, rect)| {
|
||||
let next = self
|
||||
.published
|
||||
.iter()
|
||||
.position(|old| old.id == tab.id)
|
||||
.and_then(|index| {
|
||||
self.published[index + 1..]
|
||||
.iter()
|
||||
.find(|old| tabs.iter().any(|live| live.id == old.id))
|
||||
});
|
||||
let x = next.map_or(target.plus.x - 4.0, |next| target.rect(next.id, *rect).x);
|
||||
(tab.clone(), Rect::new(x, rect.y, 0.0, rect.height))
|
||||
})
|
||||
.collect();
|
||||
self.target = target;
|
||||
self.started = Some(now);
|
||||
}
|
||||
let t = self.started.map_or(1.0, |start| {
|
||||
(now.duration_since(start).as_secs_f32() / 0.20).min(1.0)
|
||||
});
|
||||
let eased = 1.0 - (1.0 - t).powi(3);
|
||||
let rects = self
|
||||
.target
|
||||
.rects
|
||||
.iter()
|
||||
.map(|(id, target)| {
|
||||
let from = self.from.rects.iter().find(|(key, _)| key == id).map_or(
|
||||
Rect::new(target.x, target.y, 0.0, target.height),
|
||||
|(_, rect)| *rect,
|
||||
);
|
||||
(*id, blend(from, *target, eased))
|
||||
})
|
||||
.collect();
|
||||
let plus = if self.from.plus.width > 0.0 {
|
||||
blend(self.from.plus, self.target.plus, eased)
|
||||
} else {
|
||||
self.target.plus
|
||||
};
|
||||
self.current = Visual { rects, plus };
|
||||
self.next_frame = (t < 1.0).then(|| now + Duration::from_millis(16));
|
||||
self.published = tabs.to_vec();
|
||||
self.advance(now);
|
||||
self.current.clone()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user