Support stable insertion and managed tab placement
Verify Tessera GUI / verify (push) Failing after 7m40s
Verify Tessera GUI / verify (push) Failing after 7m40s
This commit is contained in:
+96
@@ -81,6 +81,71 @@ pub fn hit(tabs: &[Tab], width: f32, point: Point) -> Option<(u64, bool)> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Gap index in the complete published order, including overflow-hidden tabs.
|
||||
pub fn insertion_index(tabs: &[Tab], width: f32, point: Point) -> Option<usize> {
|
||||
if point.x < 0.0 || point.x >= width || point.y < 0.0 || point.y >= HEIGHT {
|
||||
return None;
|
||||
}
|
||||
if tabs.is_empty() {
|
||||
return Some(0);
|
||||
}
|
||||
let visible: Vec<_> = items(tabs, width)
|
||||
.into_iter()
|
||||
.filter(|item| item.navigation.is_none())
|
||||
.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);
|
||||
}
|
||||
}
|
||||
visible
|
||||
.last()
|
||||
.and_then(|last| tabs.iter().position(|tab| tab.id == last.tab.id))
|
||||
.map(|index| index + 1)
|
||||
}
|
||||
|
||||
pub fn drag_anchor(tabs: &[Tab], width: f32, id: u64, point: Point) -> Option<Point> {
|
||||
let item = items(tabs, width)
|
||||
.into_iter()
|
||||
.find(|item| item.tab.id == id && item.navigation.is_none() && item.rect.contains(point))?;
|
||||
(!close_rect(item.rect).contains(point)).then(|| Point::new(point.x - item.rect.x, point.y))
|
||||
}
|
||||
|
||||
pub fn draw_insertion(list: &mut DisplayList, tabs: &[Tab], width: f32, index: usize, scale: f32) {
|
||||
let visible: Vec<_> = items(tabs, width)
|
||||
.into_iter()
|
||||
.filter(|item| item.navigation.is_none())
|
||||
.collect();
|
||||
let x = if tabs.is_empty() {
|
||||
Some(8.0)
|
||||
} else {
|
||||
visible
|
||||
.iter()
|
||||
.find(|item| tabs.get(index).is_some_and(|tab| tab.id == item.tab.id))
|
||||
.map(|item| item.rect.x)
|
||||
.or_else(|| {
|
||||
visible
|
||||
.last()
|
||||
.filter(|item| {
|
||||
tabs.iter().position(|tab| tab.id == item.tab.id) == index.checked_sub(1)
|
||||
})
|
||||
.map(|item| item.rect.x + item.rect.width)
|
||||
})
|
||||
};
|
||||
if let Some(x) = x {
|
||||
list.push(DrawCommand::FillRoundedRect {
|
||||
rect: Rect::new(
|
||||
x.clamp(1.5, (width - 1.5).max(1.5)) * scale - 1.5 * scale,
|
||||
3.0 * scale,
|
||||
3.0 * scale,
|
||||
(HEIGHT - 6.0) * scale,
|
||||
),
|
||||
radius: scale,
|
||||
color: Color::rgb(56, 95, 220),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(list: &mut DisplayList, tabs: &[Tab], width: f32, scale: f32) {
|
||||
if tabs.is_empty() {
|
||||
return;
|
||||
@@ -146,6 +211,37 @@ pub fn draw(list: &mut DisplayList, tabs: &[Tab], width: f32, scale: f32) {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn insertion_gaps_share_visible_tab_geometry_and_exclude_close_and_arrow_drags() {
|
||||
let tabs: Vec<_> = (1..=4)
|
||||
.map(|id| Tab {
|
||||
id,
|
||||
title: id.to_string(),
|
||||
active: id == 1,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
insertion_index(&tabs, 1000.0, Point::new(10.0, 18.0)),
|
||||
Some(0)
|
||||
);
|
||||
assert_eq!(
|
||||
insertion_index(&tabs, 1000.0, Point::new(215.0, 18.0)),
|
||||
Some(1)
|
||||
);
|
||||
assert_eq!(
|
||||
insertion_index(&tabs, 1000.0, Point::new(990.0, 18.0)),
|
||||
Some(4)
|
||||
);
|
||||
assert!(drag_anchor(&tabs, 1000.0, 1, Point::new(200.0, 18.0)).is_none());
|
||||
assert!(drag_anchor(&tabs, 1000.0, 1, Point::new(25.0, 18.0)).is_some());
|
||||
assert_eq!(
|
||||
insertion_index(&tabs, 1000.0, Point::new(20.0, HEIGHT)),
|
||||
None
|
||||
);
|
||||
assert!(drag_anchor(&tabs, 400.0, 3, Point::new(390.0, 18.0)).is_none());
|
||||
assert_eq!(insertion_index(&[], 720.0, Point::new(20.0, 18.0)), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overflow_keeps_active_page_visible_and_navigation_reaches_other_pages() {
|
||||
let tabs: Vec<_> = (1..=64)
|
||||
|
||||
Reference in New Issue
Block a user