ratatui_toolkit/widgets/code_diff/widget/methods/resize_sidebar.rs
1//! Method to resize the sidebar.
2
3use crate::widgets::code_diff::code_diff::CodeDiff;
4
5impl CodeDiff {
6 /// Adjusts the sidebar width by a delta percentage.
7 ///
8 /// Positive delta increases width, negative decreases.
9 /// The width is clamped to the ResizableSplit's min/max values.
10 ///
11 /// # Arguments
12 ///
13 /// * `delta` - The change in width percentage (positive = wider, negative = narrower)
14 ///
15 /// # Example
16 ///
17 /// ```rust
18 /// use ratatui_toolkit::code_diff::{CodeDiff, DiffConfig};
19 ///
20 /// let mut diff = CodeDiff::new()
21 /// .with_config(DiffConfig::new().sidebar_enabled(true));
22 ///
23 /// diff.resize_sidebar(5); // Make 5% wider
24 /// diff.resize_sidebar(-3); // Make 3% narrower
25 /// ```
26 pub fn resize_sidebar(&mut self, delta: i16) {
27 let current = self.sidebar_split.split_percent as i16;
28 let new_width = (current + delta)
29 .max(self.sidebar_split.min_percent as i16)
30 .min(self.sidebar_split.max_percent as i16) as u16;
31 self.sidebar_split.split_percent = new_width;
32 }
33}