scrolling: Extract tab_indicator_area()
Browse files at this commit96a3ded2ec74954e9432f4b84bc8e125851dfb9eParent: a21196e1 changed file +29 -25
- src/layout/scrolling.rs +29 -25
src/layout/scrolling.rsmodified+29 -25
| @@ -3470,30 +3470,6 @@ impl<W: LayoutElement> Column<W> { | |||
| 3470 | tile.update_render_elements(is_active, tile_view_rect); | 3470 | tile.update_render_elements(is_active, tile_view_rect); |
| 3471 | } | 3471 | } |
| 3472 | 3472 | ||
| 3473 | - // We'd like to use the active tile's animated size for the tab indicator, however we need | ||
| 3474 | - // to be mindful of the case where the active tile is smaller than some other tile in the | ||
| 3475 | - // column. The column assumes the size of the largest tile. | ||
| 3476 | - // | ||
| 3477 | - // We expect users to mainly resize tabbed columns by width, so matching the animated size | ||
| 3478 | - // is more important here. Besides, we always try to resize all windows in a column to the | ||
| 3479 | - // same width when possible, and also the animation for going into tabbed mode doesn't move | ||
| 3480 | - // tiles horizontally as much. | ||
| 3481 | - // | ||
| 3482 | - // For height though, it's a different story. First, users probably aren't resizing a | ||
| 3483 | - // tabbed column by height. Second, we don't match windows by height, so it's easy to have | ||
| 3484 | - // a smaller active tile than the rest of the column, e.g. by adding a fixed-size dialog. | ||
| 3485 | - // Then, switching to that dialog and back should ideally keep the tab indicator position | ||
| 3486 | - // fixed. Third, the animation for making a column tabbed moves tiles vertically, and using | ||
| 3487 | - // the active tile's animated size in this case only works for the topmost tile, and looks | ||
| 3488 | - // broken otherwise. | ||
| 3489 | - let mut max_height = 0.; | ||
| 3490 | - for tile in &self.tiles { | ||
| 3491 | - max_height = f64::max(max_height, tile.tile_size().h); | ||
| 3492 | - } | ||
| 3493 | - | ||
| 3494 | - let tile = &self.tiles[active_idx]; | ||
| 3495 | - let area_size = Size::from((tile.animated_tile_size().w, max_height)); | ||
| 3496 | - | ||
| 3497 | let config = self.tab_indicator.config(); | 3473 | let config = self.tab_indicator.config(); |
| 3498 | let offsets = self.tile_offsets_iter(self.data.iter().copied()); | 3474 | let offsets = self.tile_offsets_iter(self.data.iter().copied()); |
| 3499 | let tabs = zip(&self.tiles, offsets) | 3475 | let tabs = zip(&self.tiles, offsets) |
| @@ -3512,7 +3488,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 3512 | 3488 | ||
| 3513 | self.tab_indicator.update_render_elements( | 3489 | self.tab_indicator.update_render_elements( |
| 3514 | enabled, | 3490 | enabled, |
| 3515 | - Rectangle::new(self.tiles_origin(), area_size), | 3491 | + self.tab_indicator_area(), |
| 3516 | view_rect, | 3492 | view_rect, |
| 3517 | self.tiles.len(), | 3493 | self.tiles.len(), |
| 3518 | tabs, | 3494 | tabs, |
| @@ -4506,6 +4482,34 @@ impl<W: LayoutElement> Column<W> { | |||
| 4506 | zip(tiles, offsets) | 4482 | zip(tiles, offsets) |
| 4507 | } | 4483 | } |
| 4508 | 4484 | ||
| 4485 | + fn tab_indicator_area(&self) -> Rectangle<f64, Logical> { | ||
| 4486 | + // We'd like to use the active tile's animated size for the tab indicator, however we need | ||
| 4487 | + // to be mindful of the case where the active tile is smaller than some other tile in the | ||
| 4488 | + // column. The column assumes the size of the largest tile. | ||
| 4489 | + // | ||
| 4490 | + // We expect users to mainly resize tabbed columns by width, so matching the animated size | ||
| 4491 | + // is more important here. Besides, we always try to resize all windows in a column to the | ||
| 4492 | + // same width when possible, and also the animation for going into tabbed mode doesn't move | ||
| 4493 | + // tiles horizontally as much. | ||
| 4494 | + // | ||
| 4495 | + // For height though, it's a different story. First, users probably aren't resizing a | ||
| 4496 | + // tabbed column by height. Second, we don't match windows by height, so it's easy to have | ||
| 4497 | + // a smaller active tile than the rest of the column, e.g. by adding a fixed-size dialog. | ||
| 4498 | + // Then, switching to that dialog and back should ideally keep the tab indicator position | ||
| 4499 | + // fixed. Third, the animation for making a column tabbed moves tiles vertically, and using | ||
| 4500 | + // the active tile's animated size in this case only works for the topmost tile, and looks | ||
| 4501 | + // broken otherwise. | ||
| 4502 | + let mut max_height = 0.; | ||
| 4503 | + for tile in &self.tiles { | ||
| 4504 | + max_height = f64::max(max_height, tile.tile_size().h); | ||
| 4505 | + } | ||
| 4506 | + | ||
| 4507 | + let tile = &self.tiles[self.active_tile_idx]; | ||
| 4508 | + let area_size = Size::from((tile.animated_tile_size().w, max_height)); | ||
| 4509 | + | ||
| 4510 | + Rectangle::new(self.tiles_origin(), area_size) | ||
| 4511 | + } | ||
| 4512 | + | ||
| 4509 | #[cfg(test)] | 4513 | #[cfg(test)] |
| 4510 | fn verify_invariants(&self) { | 4514 | fn verify_invariants(&self) { |
| 4511 | assert!(!self.tiles.is_empty(), "columns can't be empty"); | 4515 | assert!(!self.tiles.is_empty(), "columns can't be empty"); |