ratatui_toolkit/widgets/code_diff/widget/constructors/
with_theme.rs

1//! Builder method for setting the theme.
2
3use crate::services::theme::AppTheme;
4use crate::widgets::code_diff::code_diff::CodeDiff;
5
6impl CodeDiff {
7    /// Sets the application theme for styling.
8    ///
9    /// This method applies the theme colors to the diff widget, including
10    /// borders, backgrounds, and text colors.
11    ///
12    /// # Arguments
13    ///
14    /// * `theme` - The application theme to use
15    ///
16    /// # Returns
17    ///
18    /// Self for method chaining
19    ///
20    /// # Example
21    ///
22    /// ```rust
23    /// use ratatui_toolkit::code_diff::CodeDiff;
24    /// use ratatui_toolkit::services::theme::AppTheme;
25    ///
26    /// let theme = AppTheme::default();
27    /// let diff = CodeDiff::new().with_theme(&theme);
28    /// ```
29    #[must_use]
30    pub fn with_theme(mut self, theme: &AppTheme) -> Self {
31        self.theme = theme.clone();
32        self.file_tree = self.file_tree.with_theme(theme);
33        self
34    }
35
36    /// Applies a theme to the existing widget (non-consuming).
37    ///
38    /// # Arguments
39    ///
40    /// * `theme` - The application theme to apply
41    pub fn apply_theme(&mut self, theme: &AppTheme) {
42        self.theme = theme.clone();
43        self.file_tree.apply_theme(theme);
44    }
45}