rust fmt
Browse files
+8 −11 src/layout/grid.rs
| @@ -24,7 +24,6 @@ impl Layout for GridLayout { | ||
| 24 | 24 | return Vec::new(); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - // Single window takes full screen | |
| 28 | 27 | if window_count == 1 { |
| 29 | 28 | let x = gaps.outer_horizontal as i32; |
| 30 | 29 | let y = gaps.outer_vertical as i32; |
| @@ -39,16 +38,13 @@ impl Layout for GridLayout { | ||
| 39 | 38 | }]; |
| 40 | 39 | } |
| 41 | 40 | |
| 42 | - // Calculate grid dimensions using "favor rows" approach | |
| 43 | - // cols = ceil(sqrt(n)) | |
| 44 | - // rows = ceil(n / cols) | |
| 45 | 41 | let cols = (window_count as f64).sqrt().ceil() as usize; |
| 46 | 42 | let rows = (window_count as f64 / cols as f64).ceil() as usize; |
| 47 | 43 | |
| 48 | 44 | let mut geometries = Vec::new(); |
| 49 | 45 | |
| 50 | - // Calculate dimensions with gaps | |
| 51 | - let total_horizontal_gaps = gaps.outer_horizontal * 2 + gaps.inner_horizontal * (cols as u32 - 1); | |
| 46 | + let total_horizontal_gaps = | |
| 47 | + gaps.outer_horizontal * 2 + gaps.inner_horizontal * (cols as u32 - 1); | |
| 52 | 48 | let total_vertical_gaps = gaps.outer_vertical * 2 + gaps.inner_vertical * (rows as u32 - 1); |
| 53 | 49 | |
| 54 | 50 | let cell_width = screen_width.saturating_sub(total_horizontal_gaps) / cols as u32; |
| @@ -58,21 +54,22 @@ impl Layout for GridLayout { | ||
| 58 | 54 | let row = index / cols; |
| 59 | 55 | let col = index % cols; |
| 60 | 56 | |
| 61 | - // Check if this is the last row | |
| 62 | 57 | let is_last_row = row == rows - 1; |
| 63 | 58 | let windows_in_last_row = window_count - (rows - 1) * cols; |
| 64 | 59 | |
| 65 | 60 | let (x, y, width, height) = if is_last_row && windows_in_last_row < cols { |
| 66 | - // Last row with fewer windows - make them wider | |
| 67 | 61 | let last_row_col = index % cols; |
| 68 | - let last_row_cell_width = screen_width.saturating_sub(total_horizontal_gaps.saturating_sub(gaps.inner_horizontal * (cols as u32 - windows_in_last_row as u32))) / windows_in_last_row as u32; | |
| 62 | + let last_row_cell_width = | |
| 63 | + screen_width.saturating_sub(total_horizontal_gaps.saturating_sub( | |
| 64 | + gaps.inner_horizontal * (cols as u32 - windows_in_last_row as u32), | |
| 65 | + )) / windows_in_last_row as u32; | |
| 69 | 66 | |
| 70 | - let x = gaps.outer_horizontal + last_row_col as u32 * (last_row_cell_width + gaps.inner_horizontal); | |
| 67 | + let x = gaps.outer_horizontal | |
| 68 | + + last_row_col as u32 * (last_row_cell_width + gaps.inner_horizontal); | |
| 71 | 69 | let y = gaps.outer_vertical + row as u32 * (cell_height + gaps.inner_vertical); |
| 72 | 70 | |
| 73 | 71 | (x as i32, y as i32, last_row_cell_width, cell_height) |
| 74 | 72 | } else { |
| 75 | - // Normal grid cell | |
| 76 | 73 | let x = gaps.outer_horizontal + col as u32 * (cell_width + gaps.inner_horizontal); |
| 77 | 74 | let y = gaps.outer_vertical + row as u32 * (cell_height + gaps.inner_vertical); |
| 78 | 75 |