ratatui_toolkit/widgets/code_diff/widget/constructors/with_config.rs
1use crate::primitives::resizable_split::ResizableSplit;
2use crate::widgets::code_diff::code_diff::CodeDiff;
3use crate::widgets::code_diff::diff_config::DiffConfig;
4
5impl CodeDiff {
6 /// Sets the configuration for this diff widget.
7 ///
8 /// This also updates the sidebar state based on the new config:
9 /// - `show_sidebar` is set from `config.sidebar_enabled`
10 /// - `sidebar_width_percent` is set from `config.sidebar_default_width`
11 ///
12 /// # Arguments
13 ///
14 /// * `config` - The display configuration to use
15 ///
16 /// # Returns
17 ///
18 /// Self for method chaining
19 ///
20 /// # Example
21 ///
22 /// ```rust
23 /// use ratatui_toolkit::code_diff::{CodeDiff, DiffConfig};
24 ///
25 /// let config = DiffConfig::new()
26 /// .show_line_numbers(false)
27 /// .sidebar_enabled(true);
28 /// let diff = CodeDiff::new().with_config(config);
29 /// ```
30 pub fn with_config(mut self, config: DiffConfig) -> Self {
31 // Update sidebar state from config
32 self.show_sidebar = config.sidebar_enabled;
33 // Create new ResizableSplit with config values
34 let mut sidebar_split = ResizableSplit::new(config.sidebar_default_width);
35 sidebar_split.min_percent = config.sidebar_min_width;
36 sidebar_split.max_percent = config.sidebar_max_width;
37 self.sidebar_split = sidebar_split;
38 self.config = config;
39 self
40 }
41}