layout: Add window heights to columns
Browse files at this commit8056dd0c7ecc3abd0afea988a74eb8664ebe7c8aParent: 45b10771 changed file +21 -0
- src/layout.rs +21 -0
src/layout.rsmodified+21 -0
| @@ -281,6 +281,15 @@ impl From<PresetWidth> for ColumnWidth { | |||
| 281 | } | 281 | } |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | +/// Height of a window in a column. | ||
| 285 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 286 | +pub enum WindowHeight { | ||
| 287 | + /// Automatically computed height, evenly distributed across the column. | ||
| 288 | + Auto, | ||
| 289 | + /// Fixed height in logical pixels. | ||
| 290 | + Fixed(i32), | ||
| 291 | +} | ||
| 292 | + | ||
| 284 | #[derive(Debug)] | 293 | #[derive(Debug)] |
| 285 | struct Column<W: LayoutElement> { | 294 | struct Column<W: LayoutElement> { |
| 286 | /// Windows in this column. | 295 | /// Windows in this column. |
| @@ -288,6 +297,11 @@ struct Column<W: LayoutElement> { | |||
| 288 | /// Must be non-empty. | 297 | /// Must be non-empty. |
| 289 | windows: Vec<W>, | 298 | windows: Vec<W>, |
| 290 | 299 | ||
| 300 | + /// Heights of the windows. | ||
| 301 | + /// | ||
| 302 | + /// Must have the same number of elements as `windows`. | ||
| 303 | + heights: Vec<WindowHeight>, | ||
| 304 | + | ||
| 291 | /// Index of the currently active window. | 305 | /// Index of the currently active window. |
| 292 | active_window_idx: usize, | 306 | active_window_idx: usize, |
| 293 | 307 | ||
| @@ -2168,6 +2182,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2168 | 2182 | ||
| 2169 | let window_idx = column.windows.iter().position(|win| win == window).unwrap(); | 2183 | let window_idx = column.windows.iter().position(|win| win == window).unwrap(); |
| 2170 | column.windows.remove(window_idx); | 2184 | column.windows.remove(window_idx); |
| 2185 | + column.heights.remove(window_idx); | ||
| 2171 | if column.windows.is_empty() { | 2186 | if column.windows.is_empty() { |
| 2172 | if column_idx + 1 == self.active_column_idx { | 2187 | if column_idx + 1 == self.active_column_idx { |
| 2173 | // The previous column, that we were going to activate upon removal of the active | 2188 | // The previous column, that we were going to activate upon removal of the active |
| @@ -2447,6 +2462,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2447 | let target_window_was_focused = | 2462 | let target_window_was_focused = |
| 2448 | self.active_column_idx == col_idx && col.active_window_idx == win_idx; | 2463 | self.active_column_idx == col_idx && col.active_window_idx == win_idx; |
| 2449 | let window = col.windows.remove(win_idx); | 2464 | let window = col.windows.remove(win_idx); |
| 2465 | + col.heights.remove(win_idx); | ||
| 2450 | col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1); | 2466 | col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1); |
| 2451 | col.update_window_sizes(); | 2467 | col.update_window_sizes(); |
| 2452 | let width = col.width; | 2468 | let width = col.width; |
| @@ -2589,6 +2605,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2589 | ) -> Self { | 2605 | ) -> Self { |
| 2590 | let mut rv = Self { | 2606 | let mut rv = Self { |
| 2591 | windows: vec![], | 2607 | windows: vec![], |
| 2608 | + heights: vec![], | ||
| 2592 | active_window_idx: 0, | 2609 | active_window_idx: 0, |
| 2593 | width, | 2610 | width, |
| 2594 | is_fullscreen: false, | 2611 | is_fullscreen: false, |
| @@ -2655,6 +2672,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2655 | fn add_window(&mut self, window: W) { | 2672 | fn add_window(&mut self, window: W) { |
| 2656 | self.is_fullscreen = false; | 2673 | self.is_fullscreen = false; |
| 2657 | self.windows.push(window); | 2674 | self.windows.push(window); |
| 2675 | + self.heights.push(WindowHeight::Auto); | ||
| 2658 | self.update_window_sizes(); | 2676 | self.update_window_sizes(); |
| 2659 | } | 2677 | } |
| 2660 | 2678 | ||
| @@ -2725,6 +2743,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2725 | } | 2743 | } |
| 2726 | 2744 | ||
| 2727 | self.windows.swap(self.active_window_idx, new_idx); | 2745 | self.windows.swap(self.active_window_idx, new_idx); |
| 2746 | + self.heights.swap(self.active_window_idx, new_idx); | ||
| 2728 | self.active_window_idx = new_idx; | 2747 | self.active_window_idx = new_idx; |
| 2729 | } | 2748 | } |
| 2730 | 2749 | ||
| @@ -2735,6 +2754,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2735 | } | 2754 | } |
| 2736 | 2755 | ||
| 2737 | self.windows.swap(self.active_window_idx, new_idx); | 2756 | self.windows.swap(self.active_window_idx, new_idx); |
| 2757 | + self.heights.swap(self.active_window_idx, new_idx); | ||
| 2738 | self.active_window_idx = new_idx; | 2758 | self.active_window_idx = new_idx; |
| 2739 | } | 2759 | } |
| 2740 | 2760 | ||
| @@ -2742,6 +2762,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2742 | fn verify_invariants(&self) { | 2762 | fn verify_invariants(&self) { |
| 2743 | assert!(!self.windows.is_empty(), "columns can't be empty"); | 2763 | assert!(!self.windows.is_empty(), "columns can't be empty"); |
| 2744 | assert!(self.active_window_idx < self.windows.len()); | 2764 | assert!(self.active_window_idx < self.windows.len()); |
| 2765 | + assert_eq!(self.windows.len(), self.heights.len()); | ||
| 2745 | 2766 | ||
| 2746 | if self.is_fullscreen { | 2767 | if self.is_fullscreen { |
| 2747 | assert_eq!(self.windows.len(), 1); | 2768 | assert_eq!(self.windows.len(), 1); |