ratatui_toolkit/widgets/code_diff/widget/methods/set_scroll.rs
1use crate::widgets::code_diff::code_diff::CodeDiff;
2
3impl CodeDiff {
4 /// Sets the scroll offset to a specific value.
5 ///
6 /// The offset is clamped to valid bounds.
7 ///
8 /// # Arguments
9 ///
10 /// * `offset` - The scroll offset to set
11 ///
12 /// # Example
13 ///
14 /// ```rust
15 /// use ratatui_toolkit::code_diff::CodeDiff;
16 ///
17 /// let mut diff = CodeDiff::new();
18 /// diff.set_scroll(10);
19 /// ```
20 pub fn set_scroll(&mut self, offset: usize) {
21 let max_scroll = self.total_lines();
22 self.scroll_offset = offset.min(max_scroll);
23 }
24}