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