pub struct Toc<'a> { /* private fields */ }Expand description
Table of Contents widget for markdown navigation.
Shows document headings in either compact (lines) or expanded (text) mode. Supports hover interactions and click-to-scroll navigation.
This is a UI-only widget that receives &TocState for state access.
State mutations happen through TocState methods, not here.
§Example
use ratatui_toolkit::markdown_widget::extensions::toc::{Toc, TocConfig};
use ratatui_toolkit::markdown_widget::state::toc_state::TocState;
let mut toc_state = TocState::new();
let toc = Toc::new(&toc_state)
.config(TocConfig::default())
.expanded(true);Implementations§
Source§impl<'a> Toc<'a>
impl<'a> Toc<'a>
Sourcepub fn new(toc_state: &'a TocState) -> Self
pub fn new(toc_state: &'a TocState) -> Self
Create a new TOC widget from TocState.
The Toc widget is a UI-only component that receives state via reference. State mutations happen through TocState methods, not the Toc widget.
§Arguments
toc_state- Reference to the TocState containing entries, scroll, and hover state.
§Returns
A new Toc instance ready for rendering.
§Example
use ratatui_toolkit::markdown_widget::extensions::toc::Toc;
use ratatui_toolkit::markdown_widget::state::toc_state::TocState;
let toc_state = TocState::new();
let toc = Toc::new(&toc_state);Source§impl<'a> Toc<'a>
impl<'a> Toc<'a>
Source§impl<'a> Toc<'a>
impl<'a> Toc<'a>
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Get the number of entries in the TOC.
Delegates to the underlying TocState.
Sourcepub fn click_to_line(&self, entry_index: usize) -> Option<usize>
pub fn click_to_line(&self, entry_index: usize) -> Option<usize>
Source§impl<'a> Toc<'a>
impl<'a> Toc<'a>
Source§impl<'a> Toc<'a>
impl<'a> Toc<'a>
Sourcepub fn required_compact_height(
content: &str,
line_spacing: u8,
show_border: bool,
) -> u16
pub fn required_compact_height( content: &str, line_spacing: u8, show_border: bool, ) -> u16
Calculate the required height for compact mode.
With Braille markers, we have 4 vertical dots per cell. Height = ceil(entries * spacing / 4) + border_height.
§Arguments
content- The markdown content to scan.line_spacing- Spacing between lines in dot units.show_border- Whether the border is shown.
§Returns
The required height in rows.
Source§impl<'a> Toc<'a>
impl<'a> Toc<'a>
Sourcepub fn required_expanded_width(content: &str, show_border: bool) -> u16
pub fn required_expanded_width(content: &str, show_border: bool) -> u16
Calculate the required width to display all headings without truncation.
Takes into account:
- Indentation based on heading level (2 chars per level)
- Actual text width using Unicode width
- Padding (left and right)
- Border if enabled
§Arguments
content- The markdown content to scan.show_border- Whether the border is shown.
§Returns
The required width in columns.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Toc<'a>
impl<'a> RefUnwindSafe for Toc<'a>
impl<'a> Send for Toc<'a>
impl<'a> Sync for Toc<'a>
impl<'a> Unpin for Toc<'a>
impl<'a> UnwindSafe for Toc<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more