ratatui_toolkit/widgets/markdown_widget/extensions/toc/
mod.rs

1//! Table of Contents widget for markdown document navigation.
2//!
3//! Provides a compact or expanded view of document headings for quick navigation.
4//! In compact mode, shows heading indicators as horizontal lines.
5//! In expanded mode, shows full heading text with indentation.
6//!
7//! # Features
8//!
9//! - Compact mode: horizontal lines indicating heading positions and levels
10//! - Expanded mode: full heading text with hierarchy indentation
11//! - Current heading highlight (blue in expanded, bright in compact)
12//! - Hover highlight for items
13//! - Click-to-scroll navigation
14//!
15//! # Mouse Capture Requirement
16//!
17//! For TOC click navigation and hover interactions to work, you must enable
18//! mouse capture with crossterm:
19//!
20//! ```rust,ignore
21//! use crossterm::event::{EnableMouseCapture, DisableMouseCapture};
22//! execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
23//! ```
24//!
25//! Without `EnableMouseCapture`, click events will not be received.
26//!
27//! # Architecture
28//!
29//! The Toc extension is a UI widget only - it receives `&TocState` as a parameter
30//! and ONLY handles rendering. State mutations happen through TocState methods.
31
32pub mod constructors;
33pub mod enums;
34mod methods;
35mod traits;
36
37pub use constructors::*;
38pub use enums::TocConfig;
39pub use enums::*;
40
41use crate::widgets::markdown_widget::state::toc_state::TocState;
42
43/// Table of Contents widget for markdown navigation.
44///
45/// Shows document headings in either compact (lines) or expanded (text) mode.
46/// Supports hover interactions and click-to-scroll navigation.
47///
48/// This is a UI-only widget that receives `&TocState` for state access.
49/// State mutations happen through `TocState` methods, not here.
50///
51/// # Example
52///
53/// ```rust,no_run
54/// use ratatui_toolkit::markdown_widget::extensions::toc::{Toc, TocConfig};
55/// use ratatui_toolkit::markdown_widget::state::toc_state::TocState;
56///
57/// let mut toc_state = TocState::new();
58/// let toc = Toc::new(&toc_state)
59///     .config(TocConfig::default())
60///     .expanded(true);
61/// ```
62#[derive(Debug)]
63pub struct Toc<'a> {
64    /// Reference to the TOC state (entries, scroll, hover).
65    pub(crate) toc_state: &'a TocState,
66    /// Configuration for appearance.
67    pub(crate) config: TocConfig,
68    /// Whether the TOC is in expanded mode.
69    pub(crate) expanded: bool,
70}