@@ -89,6 +89,12 @@ impl Default for Node { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | impl Node { |
| 92 | + fn stack_reveal_direction(windows_len: usize, active: usize) -> f64 { |
| 93 | + let left_count = active; |
| 94 | + let right_count = windows_len.saturating_sub(active + 1); |
| 95 | + if left_count > right_count { -1.0 } else { 1.0 } |
| 96 | + } |
| 97 | + |
| 92 | 98 | pub fn empty() -> Self { |
| 93 | 99 | Node::Leaf { window: None } |
| 94 | 100 | } |
@@ -312,6 +318,7 @@ impl Node { |
| 312 | 318 | windows, active, .. |
| 313 | 319 | } => { |
| 314 | 320 | let active_window = windows.get(*active).copied(); |
| 321 | + let x_direction = Self::stack_reveal_direction(windows.len(), *active); |
| 315 | 322 | let mut geoms = Vec::with_capacity(windows.len()); |
| 316 | 323 | let mut depth = 0usize; |
| 317 | 324 | for (idx, wid) in windows.iter().enumerate() { |
@@ -322,7 +329,7 @@ impl Node { |
| 322 | 329 | geoms.push(( |
| 323 | 330 | *wid, |
| 324 | 331 | Rect::new( |
| 325 | | - padded.x + STACK_REVEAL_OFFSET_X * depth as f64, |
| 332 | + padded.x + x_direction * STACK_REVEAL_OFFSET_X * depth as f64, |
| 326 | 333 | padded.y + STACK_REVEAL_OFFSET_Y * depth as f64, |
| 327 | 334 | padded.width, |
| 328 | 335 | padded.height, |
@@ -1414,18 +1421,34 @@ mod tests { |
| 1414 | 1421 | } |
| 1415 | 1422 | |
| 1416 | 1423 | #[test] |
| 1417 | | - fn stacked_render_geometries_reveal_background_windows() { |
| 1418 | | - let mut tree = Node::empty(); |
| 1419 | | - tree.insert_with_rect(1, None, SCREEN); |
| 1420 | | - tree.insert_with_rect(2, Some(1), SCREEN); |
| 1421 | | - tree.insert_with_rect(3, Some(2), SCREEN); |
| 1422 | | - assert!(tree.make_stack_for_window(3)); |
| 1424 | + fn stacked_render_geometries_reveal_background_windows_to_the_right_when_right_biased() { |
| 1425 | + let tree = Node::Stack { |
| 1426 | + windows: vec![1, 2, 3], |
| 1427 | + active: 0, |
| 1428 | + previous: Box::new(Node::Leaf { window: Some(1) }), |
| 1429 | + }; |
| 1430 | + let geoms = tree.calculate_geometries(SCREEN); |
| 1431 | + let g1 = geoms.iter().find(|(wid, _)| *wid == 1).unwrap().1; |
| 1432 | + let g2 = geoms.iter().find(|(wid, _)| *wid == 2).unwrap().1; |
| 1423 | 1433 | |
| 1434 | + assert!(g2.x > g1.x); |
| 1435 | + assert!(g2.y > g1.y); |
| 1436 | + assert_eq!(g2.width, g1.width); |
| 1437 | + assert_eq!(g2.height, g1.height); |
| 1438 | + } |
| 1439 | + |
| 1440 | + #[test] |
| 1441 | + fn stacked_render_geometries_reveal_background_windows_to_the_left_when_left_biased() { |
| 1442 | + let tree = Node::Stack { |
| 1443 | + windows: vec![1, 2, 3], |
| 1444 | + active: 2, |
| 1445 | + previous: Box::new(Node::Leaf { window: Some(3) }), |
| 1446 | + }; |
| 1424 | 1447 | let geoms = tree.calculate_geometries(SCREEN); |
| 1425 | 1448 | let g2 = geoms.iter().find(|(wid, _)| *wid == 2).unwrap().1; |
| 1426 | 1449 | let g3 = geoms.iter().find(|(wid, _)| *wid == 3).unwrap().1; |
| 1427 | 1450 | |
| 1428 | | - assert!(g2.x > g3.x); |
| 1451 | + assert!(g2.x < g3.x); |
| 1429 | 1452 | assert!(g2.y > g3.y); |
| 1430 | 1453 | assert_eq!(g2.width, g3.width); |
| 1431 | 1454 | assert_eq!(g2.height, g3.height); |