ratatui_toolkit/widgets/markdown_widget/widget/constructors/
new.rs

1//! Constructor for MarkdownWidget.
2
3use crate::widgets::markdown_widget::extensions::scrollbar::ScrollbarConfig;
4use crate::widgets::markdown_widget::extensions::toc::TocConfig;
5use crate::widgets::markdown_widget::state::{
6    CacheState, CollapseState, DisplaySettings, DoubleClickState, ExpandableState, GitStatsState,
7    ScrollState, SelectionState, SourceState, VimState,
8};
9use crate::widgets::markdown_widget::widget::enums::MarkdownWidgetMode;
10use crate::widgets::markdown_widget::widget::MarkdownWidget;
11
12impl<'a> MarkdownWidget<'a> {
13    /// Create a new MarkdownWidget with the given content and state managers.
14    ///
15    /// # Arguments
16    ///
17    /// * `content` - The markdown content to render
18    /// * `scroll` - Scroll state (position, viewport, current line)
19    /// * `source` - Content source state
20    /// * `cache` - Render cache state
21    /// * `display` - Display settings (line numbers, themes)
22    /// * `collapse` - Section collapse state
23    /// * `expandable` - Expandable content state
24    /// * `git_stats_state` - Git stats state
25    /// * `vim` - Vim keybinding state
26    /// * `selection` - Selection state for text selection/copy
27    /// * `double_click` - Double-click state for detection
28    ///
29    /// # Returns
30    ///
31    /// A new `MarkdownWidget` instance.
32    #[allow(clippy::too_many_arguments)]
33    pub fn new(
34        content: &'a str,
35        scroll: &'a mut ScrollState,
36        source: &'a mut SourceState,
37        cache: &'a mut CacheState,
38        display: &'a DisplaySettings,
39        collapse: &'a mut CollapseState,
40        expandable: &'a mut ExpandableState,
41        git_stats_state: &'a mut GitStatsState,
42        vim: &'a mut VimState,
43        selection: &'a mut SelectionState,
44        double_click: &'a mut DoubleClickState,
45    ) -> Self {
46        Self {
47            content,
48            scroll,
49            source,
50            cache,
51            display,
52            collapse,
53            expandable,
54            git_stats_state,
55            vim,
56            selection,
57            double_click,
58            toc_state: None,
59            is_resizing: false,
60            mode: MarkdownWidgetMode::Normal,
61            show_statusline: true,
62            show_scrollbar: false,
63            scrollbar_config: ScrollbarConfig::default(),
64            selection_active: false,
65            git_stats: None,
66            show_toc: false,
67            toc_config: TocConfig::default(),
68            toc_hovered: false,
69            toc_hovered_entry: None,
70            toc_scroll_offset: 0,
71            rendered_lines: Vec::new(),
72            app_theme: None,
73            last_double_click: None,
74            filter: None,
75            filter_mode: false,
76            bordered: false,
77            has_pane: true,
78            pane: None,
79            pane_title: None,
80            pane_color: None,
81        }
82    }
83}