pub struct Renderer { /* private fields */ }
Expand description
The main tree rendering engine.
Renderer
is responsible for converting tree node structures into styled
text output. It handles complex features like:
- Multi-line content with proper indentation
- Custom enumerators and indenters
- Style inheritance and override resolution
- Alignment of custom enumerators
- Branch continuation across container nodes
§Examples
use lipgloss_tree::{Renderer, Children};
use lipgloss_tree::renderer::TreeStyle;
use lipgloss::Style;
let renderer = Renderer::new()
.style(TreeStyle::default())
.enumerator(|children, i| {
if i == children.length() - 1 { "└──".to_string() }
else { "├──".to_string() }
});
Implementations§
Source§impl Renderer
impl Renderer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new renderer with default configuration.
The default renderer uses:
- Standard box-drawing characters for branches (├──, └──)
- Standard indentation (│ for continuing, spaces for last)
- Default styling with padding after enumerators
§Examples
use lipgloss_tree::Renderer;
let renderer = Renderer::new();
Sourcepub fn style(self, style: TreeStyle) -> Self
pub fn style(self, style: TreeStyle) -> Self
Sets the styling configuration for this renderer.
This replaces the entire TreeStyle
, affecting how enumerators,
items, and the root are styled.
§Arguments
style
- The newTreeStyle
configuration to use
§Examples
use lipgloss_tree::Renderer;
use lipgloss_tree::renderer::TreeStyle;
use lipgloss::Style;
let custom_style = TreeStyle {
root: Style::new().bold(true),
..TreeStyle::default()
};
let renderer = Renderer::new().style(custom_style);
Sourcepub fn enumerator(self, enumerator: Enumerator) -> Self
pub fn enumerator(self, enumerator: Enumerator) -> Self
Sets the enumerator function for this renderer.
The enumerator function generates the branch characters (like ├──, └──) based on the child’s position in its parent’s children collection.
§Arguments
enumerator
- Function that takes(children, index)
and returns a string
§Examples
use lipgloss_tree::{Renderer, Children};
let renderer = Renderer::new()
.enumerator(|children, i| {
if i == children.length() - 1 {
"╰──".to_string() // Rounded last branch
} else {
"├──".to_string() // Standard continuing branch
}
});
Sourcepub fn indenter(self, indenter: Indenter) -> Self
pub fn indenter(self, indenter: Indenter) -> Self
Sets the indenter function for this renderer.
The indenter function generates indentation strings for child content that appears below parent nodes, providing the visual connection between parent and nested children.
§Arguments
indenter
- Function that takes(children, index)
and returns indentation string
§Examples
use lipgloss_tree::{Renderer, Children};
let renderer = Renderer::new()
.indenter(|children, i| {
if i == children.length() - 1 {
" ".to_string() // Spaces for last child
} else {
"│ ".to_string() // Vertical line for continuing
}
});
Sourcepub fn render(&self, node: &dyn Node, root: bool, prefix: &str) -> String
pub fn render(&self, node: &dyn Node, root: bool, prefix: &str) -> String
Renders a tree node and its children to a formatted string.
This is the main rendering method that converts a tree structure into styled text output. It handles complex scenarios like multi-line content, style inheritance, custom enumerators, and proper indentation.
§Arguments
node
- The tree node to renderroot
- Whether this is the root node (affects root style application)prefix
- String prefix to prepend to each line (for nested rendering)
§Returns
A formatted string representation of the tree with proper styling and indentation
§Examples
use lipgloss_tree::{Renderer, Tree};
let tree = Tree::new()
.root("My Tree")
.child(vec!["Item 1".into(), "Item 2".into()]);
let renderer = Renderer::new();
let output = renderer.render(&tree, true, "");
println!("{}", output);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Renderer
impl !RefUnwindSafe for Renderer
impl Send for Renderer
impl Sync for Renderer
impl Unpin for Renderer
impl !UnwindSafe for Renderer
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters
when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle
.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other
into Self
, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T
.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters
when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self
into T
, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors
fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more