adjust horizontal view movement gestures snap points for center-focused-column "on-overflow" (#1052)
Browse files at this commit1 changed file +70 -20
- src/layout/scrolling.rs +70 -20
src/layout/scrolling.rsmodified+70 -20
| @@ -2536,42 +2536,85 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2536 | col_x += col_w + self.options.gaps; | 2536 | col_x += col_w + self.options.gaps; |
| 2537 | } | 2537 | } |
| 2538 | } else { | 2538 | } else { |
| 2539 | + let center_on_overflow = matches!( | ||
| 2540 | + self.options.center_focused_column, | ||
| 2541 | + CenterFocusedColumn::OnOverflow | ||
| 2542 | + ); | ||
| 2543 | + | ||
| 2539 | let view_width = self.view_size.w; | 2544 | let view_width = self.view_size.w; |
| 2540 | let working_area_width = self.working_area.size.w; | 2545 | let working_area_width = self.working_area.size.w; |
| 2541 | let gaps = self.options.gaps; | 2546 | let gaps = self.options.gaps; |
| 2542 | 2547 | ||
| 2543 | - let snap_points = |col_x, col: &Column<W>| { | 2548 | + let snap_points = |
| 2544 | - let col_w = col.width(); | 2549 | + |col_x, col: &Column<W>, prev_col_w: Option<f64>, next_col_w: Option<f64>| { |
| 2550 | + let col_w = col.width(); | ||
| 2545 | 2551 | ||
| 2546 | - // Normal columns align with the working area, but fullscreen columns align with the | 2552 | + // Normal columns align with the working area, but fullscreen columns align with |
| 2547 | - // view size. | 2553 | + // the view size. |
| 2548 | - if col.is_fullscreen { | 2554 | + if col.is_fullscreen { |
| 2549 | - let left = col_x; | 2555 | + let left = col_x; |
| 2550 | - let right = col_x + col_w; | 2556 | + let right = col_x + col_w; |
| 2551 | - (left, right) | 2557 | + (left, right) |
| 2552 | - } else { | 2558 | + } else { |
| 2553 | - // Logic from compute_new_view_offset. | 2559 | + // Logic from compute_new_view_offset. |
| 2554 | - let padding = ((working_area_width - col_w) / 2.).clamp(0., gaps); | 2560 | + let padding = ((working_area_width - col_w) / 2.).clamp(0., gaps); |
| 2555 | - let left = col_x - padding - left_strut; | 2561 | + |
| 2556 | - let right = col_x + col_w + padding + right_strut; | 2562 | + let center = if self.working_area.size.w <= col_w { |
| 2557 | - (left, right) | 2563 | + col_x - left_strut |
| 2558 | - } | 2564 | + } else { |
| 2559 | - }; | 2565 | + col_x - (self.working_area.size.w - col_w) / 2. - left_strut |
| 2566 | + }; | ||
| 2567 | + let is_overflowing = |adj_col_w: Option<f64>| { | ||
| 2568 | + center_on_overflow | ||
| 2569 | + && adj_col_w | ||
| 2570 | + .filter(|adj_col_w| { | ||
| 2571 | + center_on_overflow | ||
| 2572 | + && adj_col_w + 3.0 * gaps + col_w > working_area_width | ||
| 2573 | + }) | ||
| 2574 | + .is_some() | ||
| 2575 | + }; | ||
| 2576 | + | ||
| 2577 | + let left = if is_overflowing(next_col_w) { | ||
| 2578 | + center | ||
| 2579 | + } else { | ||
| 2580 | + col_x - padding - left_strut | ||
| 2581 | + }; | ||
| 2582 | + let right = if is_overflowing(prev_col_w) { | ||
| 2583 | + center + view_width | ||
| 2584 | + } else { | ||
| 2585 | + col_x + col_w + padding + right_strut | ||
| 2586 | + }; | ||
| 2587 | + (left, right) | ||
| 2588 | + } | ||
| 2589 | + }; | ||
| 2560 | 2590 | ||
| 2561 | // Prevent the gesture from snapping further than the first/last column, as this is | 2591 | // Prevent the gesture from snapping further than the first/last column, as this is |
| 2562 | // generally undesired. | 2592 | // generally undesired. |
| 2563 | // | 2593 | // |
| 2564 | // It's ok if leftmost_snap is > rightmost_snap (this happens if the columns on a | 2594 | // It's ok if leftmost_snap is > rightmost_snap (this happens if the columns on a |
| 2565 | // workspace total up to less than the workspace width). | 2595 | // workspace total up to less than the workspace width). |
| 2566 | - let leftmost_snap = snap_points(0., &self.columns[0]).0; | 2596 | + let leftmost_snap = snap_points( |
| 2597 | + 0., | ||
| 2598 | + &self.columns[0], | ||
| 2599 | + None, | ||
| 2600 | + self.columns.get(1).map(|c| c.width()), | ||
| 2601 | + ) | ||
| 2602 | + .0; | ||
| 2567 | let last_col_idx = self.columns.len() - 1; | 2603 | let last_col_idx = self.columns.len() - 1; |
| 2568 | let last_col_x = self | 2604 | let last_col_x = self |
| 2569 | .columns | 2605 | .columns |
| 2570 | .iter() | 2606 | .iter() |
| 2571 | .take(last_col_idx) | 2607 | .take(last_col_idx) |
| 2572 | .fold(0., |col_x, col| col_x + col.width() + gaps); | 2608 | .fold(0., |col_x, col| col_x + col.width() + gaps); |
| 2573 | - let rightmost_snap = | 2609 | + let rightmost_snap = snap_points( |
| 2574 | - snap_points(last_col_x, &self.columns[last_col_idx]).1 - view_width; | 2610 | + last_col_x, |
| 2611 | + &self.columns[last_col_idx], | ||
| 2612 | + last_col_idx | ||
| 2613 | + .checked_sub(1) | ||
| 2614 | + .and_then(|idx| self.columns.get(idx).map(|c| c.width())), | ||
| 2615 | + None, | ||
| 2616 | + ) | ||
| 2617 | + .1 - view_width; | ||
| 2575 | 2618 | ||
| 2576 | snapping_points.push(Snap { | 2619 | snapping_points.push(Snap { |
| 2577 | view_pos: leftmost_snap, | 2620 | view_pos: leftmost_snap, |
| @@ -2601,7 +2644,14 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2601 | 2644 | ||
| 2602 | let mut col_x = 0.; | 2645 | let mut col_x = 0.; |
| 2603 | for (col_idx, col) in self.columns.iter().enumerate() { | 2646 | for (col_idx, col) in self.columns.iter().enumerate() { |
| 2604 | - let (left, right) = snap_points(col_x, col); | 2647 | + let (left, right) = snap_points( |
| 2648 | + col_x, | ||
| 2649 | + col, | ||
| 2650 | + col_idx | ||
| 2651 | + .checked_sub(1) | ||
| 2652 | + .and_then(|idx| self.columns.get(idx).map(|c| c.width())), | ||
| 2653 | + self.columns.get(col_idx + 1).map(|c| c.width()), | ||
| 2654 | + ); | ||
| 2605 | push(col_idx, left, right); | 2655 | push(col_idx, left, right); |
| 2606 | 2656 | ||
| 2607 | col_x += col.width() + gaps; | 2657 | col_x += col.width() + gaps; |