ratatui_toolkit/primitives/menu_bar/methods/apply_theme.rs
1//! Method to apply an AppTheme to an existing MenuBar in place.
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 in place.
9 ///
10 /// Unlike `with_theme` which consumes self, this method updates
11 /// the menu bar's styles without consuming it. Useful for updating
12 /// the theme dynamically at runtime.
13 ///
14 /// # Arguments
15 ///
16 /// * `theme` - The application theme to apply
17 ///
18 /// # Example
19 ///
20 /// ```rust,no_run
21 /// use ratatui_toolkit::{MenuBar, MenuItem, AppTheme};
22 ///
23 /// let theme = AppTheme::default();
24 /// let mut menu_bar = MenuBar::new(vec![
25 /// MenuItem::new("File", 0),
26 /// MenuItem::new("Edit", 1),
27 /// ]);
28 /// menu_bar.apply_theme(&theme);
29 /// ```
30 pub fn apply_theme(&mut self, theme: &AppTheme) {
31 self.normal_style = Style::default().fg(theme.text);
32 self.selected_style = Style::default()
33 .fg(theme.primary)
34 .add_modifier(Modifier::BOLD);
35 self.hover_style = Style::default().fg(theme.secondary);
36 self.selected_hover_style = Style::default()
37 .fg(theme.primary)
38 .add_modifier(Modifier::BOLD);
39 }
40}