ratatui_toolkit/primitives/resizable_split/methods/
mod.rs

1use ratatui::layout::Rect;
2
3use crate::primitives::resizable_split::{ResizableSplit, SplitDirection};
4
5impl ResizableSplit {
6    pub fn update_divider_position(&mut self, area: Rect) {
7        match self.direction {
8            SplitDirection::Vertical => {
9                let left_width = (area.width as u32 * self.split_percent as u32 / 100) as u16;
10                self.divider_pos = area.x + left_width;
11            }
12            SplitDirection::Horizontal => {
13                let top_height = (area.height as u32 * self.split_percent as u32 / 100) as u16;
14                self.divider_pos = area.y + top_height;
15            }
16        }
17    }
18
19    pub fn is_on_divider(&self, mouse_column: u16, mouse_row: u16, area: Rect) -> bool {
20        match self.direction {
21            SplitDirection::Vertical => {
22                let divider_start = self.divider_pos.saturating_sub(1);
23                let divider_end = (self.divider_pos + 1).min(area.x + area.width.saturating_sub(1));
24                mouse_column >= divider_start && mouse_column <= divider_end
25            }
26            SplitDirection::Horizontal => {
27                let divider_start = self.divider_pos.saturating_sub(1);
28                let divider_end =
29                    (self.divider_pos + 1).min(area.y + area.height.saturating_sub(1));
30                mouse_row >= divider_start && mouse_row <= divider_end
31            }
32        }
33    }
34
35    pub fn update_from_mouse(&mut self, mouse_column: u16, mouse_row: u16, area: Rect) {
36        if !self.is_dragging {
37            return;
38        }
39
40        let new_percent = match self.direction {
41            SplitDirection::Vertical => {
42                let relative_column = mouse_column.saturating_sub(area.x);
43
44                if area.width > 0 {
45                    ((relative_column as u32 * 100) / area.width as u32) as u16
46                } else {
47                    self.split_percent
48                }
49            }
50            SplitDirection::Horizontal => {
51                let relative_row = mouse_row.saturating_sub(area.y);
52
53                if area.height > 0 {
54                    ((relative_row as u32 * 100) / area.height as u32) as u16
55                } else {
56                    self.split_percent
57                }
58            }
59        };
60
61        self.split_percent = new_percent.clamp(self.min_percent, self.max_percent);
62    }
63
64    pub fn render_divider_indicator(&self, _frame: &mut ratatui::Frame, _area: Rect) {
65        // No separator rendering - border colors are changed on the panes themselves
66    }
67}