ratatui_toolkit/primitives/menu_bar/methods/with_theme.rs
1//! Method to apply an AppTheme to the MenuBar.
2
3use crate::primitives::menu_bar::MenuBar;
4use crate::services::theme::AppTheme;
5use ratatui::style::{Modifier, Style};
6
7impl MenuBar {
8 /// Applies theme colors to the menu bar.
9 ///
10 /// This method configures all menu bar styles based on the provided theme,
11 /// ensuring consistent styling across the application.
12 ///
13 /// # Arguments
14 ///
15 /// * `theme` - The application theme to apply
16 ///
17 /// # Returns
18 ///
19 /// Self with theme colors applied for method chaining.
20 ///
21 /// # Example
22 ///
23 /// ```rust,no_run
24 /// use ratatui_toolkit::{MenuBar, MenuItem, AppTheme};
25 ///
26 /// let theme = AppTheme::default();
27 /// let menu_bar = MenuBar::new(vec![
28 /// MenuItem::new("File", 0),
29 /// MenuItem::new("Edit", 1),
30 /// ])
31 /// .with_theme(&theme);
32 /// ```
33 pub fn with_theme(mut self, theme: &AppTheme) -> Self {
34 self.normal_style = Style::default().fg(theme.text);
35 self.selected_style = Style::default()
36 .fg(theme.primary)
37 .add_modifier(Modifier::BOLD);
38 self.hover_style = Style::default().fg(theme.secondary);
39 self.selected_hover_style = Style::default()
40 .fg(theme.primary)
41 .add_modifier(Modifier::BOLD);
42 self
43 }
44}