Restore the active pane magnification feature

Mikayla created

Change summary

crates/workspace/src/pane_group.rs | 65 ++++++++++++++++++++++---------
1 file changed, 45 insertions(+), 20 deletions(-)

Detailed changes

crates/workspace/src/pane_group.rs 🔗

@@ -579,12 +579,15 @@ mod element {
         Size, Style, WeakView, WindowContext,
     };
     use parking_lot::Mutex;
+    use settings::Settings;
     use smallvec::SmallVec;
     use ui::prelude::*;
     use util::ResultExt;
 
     use crate::Workspace;
 
+    use crate::WorkspaceSettings;
+
     use super::{HANDLE_HITBOX_SIZE, HORIZONTAL_MIN_SIZE, VERTICAL_MIN_SIZE};
 
     const DIVIDER_SIZE: f32 = 1.0;
@@ -834,20 +837,39 @@ mod element {
             debug_assert!(flexes.len() == len);
             debug_assert!(flex_values_in_bounds(flexes.as_slice()));
 
+            let magnification_value = WorkspaceSettings::get(None, cx).active_pane_magnification;
+            let active_pane_magnification = if magnification_value == 1. {
+                None
+            } else {
+                Some(magnification_value)
+            };
+
+            let total_flex = if let Some(flex) = active_pane_magnification {
+                self.children.len() as f32 - 1. + flex
+            } else {
+                len as f32
+            };
+
             let mut origin = bounds.origin;
-            let space_per_flex = bounds.size.along(self.axis) / len as f32;
+            let space_per_flex = bounds.size.along(self.axis) / total_flex;
 
             let mut bounding_boxes = self.bounding_boxes.lock();
             bounding_boxes.clear();
 
             for (ix, child) in self.children.iter_mut().enumerate() {
-                //todo!(active_pane_magnification)
-                // If using active pane magnification, need to switch to using
-                // 1 for all non-active panes, and then the magnification for the
-                // active pane.
+                let child_flex = active_pane_magnification
+                    .map(|magnification| {
+                        if self.active_pane_ix == Some(ix) {
+                            magnification
+                        } else {
+                            1.
+                        }
+                    })
+                    .unwrap_or_else(|| flexes[ix]);
+
                 let child_size = bounds
                     .size
-                    .apply_along(self.axis, |_| space_per_flex * flexes[ix]);
+                    .apply_along(self.axis, |_| space_per_flex * child_flex);
 
                 let child_bounds = Bounds {
                     origin,
@@ -857,20 +879,23 @@ mod element {
                 cx.with_z_index(0, |cx| {
                     child.draw(origin, child_size.into(), cx);
                 });
-                cx.with_z_index(1, |cx| {
-                    if ix < len - 1 {
-                        Self::push_handle(
-                            self.flexes.clone(),
-                            state.clone(),
-                            self.axis,
-                            ix,
-                            child_bounds,
-                            bounds,
-                            self.workspace.clone(),
-                            cx,
-                        );
-                    }
-                });
+
+                if active_pane_magnification.is_none() {
+                    cx.with_z_index(1, |cx| {
+                        if ix < len - 1 {
+                            Self::push_handle(
+                                self.flexes.clone(),
+                                state.clone(),
+                                self.axis,
+                                ix,
+                                child_bounds,
+                                bounds,
+                                self.workspace.clone(),
+                                cx,
+                            );
+                        }
+                    });
+                }
 
                 origin = origin.apply_along(self.axis, |val| val + child_size.along(self.axis));
             }