Module defaultitem

Source
Expand description

Default item implementation and delegate for list components.

This module provides the standard item type and delegate implementation for the list component. The DefaultItem is a simple item with a title and description, while DefaultDelegate handles the rendering and interaction logic for these items.

§Filter Highlighting Architecture

This module implements a sophisticated filter highlighting system that avoids common ANSI rendering issues. The key insight is that lipgloss styles with padding/borders cause spacing problems when applied to individual text segments.

§The Problem

When highlighting individual characters in filtered text, naively applying styles with padding results in extra spaces between segments:

  • Input: “Nutella” with ‘N’ highlighted
  • Broken: “│ N utella” (space between N and utella)
  • Correct: “│ Nutella” (seamless text)

§The Solution

  1. Segment-Based Highlighting: Group consecutive match indices to minimize ANSI sequences
  2. Clean Styles: Use styles without padding/borders for apply_character_highlighting
  3. Manual Layout: Apply borders and padding manually after highlighting is complete

§Visual States

  • Selected Items: Left border (│) + 1 space + highlighted text
  • Unselected Items: 2 spaces + highlighted text (no border)
  • Dimmed Items: Faded colors when filter input is empty

This approach ensures perfect text rendering while maintaining the visual hierarchy.

§Default Item Structure

The DefaultItem represents a basic list item with:

  • A title (main text)
  • A description (secondary text, optional display)

§Default Delegate

The DefaultDelegate handles:

  • Rendering items with different visual states (normal, selected, dimmed)
  • Managing item height and spacing
  • Complex filter highlighting with seamless text rendering

§Styling

The DefaultItemStyles provides comprehensive styling options:

  • Normal state styles for title and description
  • Selected state styles with borders and highlighting
  • Dimmed state styles for filtered-out items
  • Filter match highlighting styles

§Example

use bubbletea_widgets::list::{DefaultItem, DefaultDelegate};

let item = DefaultItem::new("Task 1", "Complete the documentation");
let delegate = DefaultDelegate::new();

Structs§

DefaultDelegate
A delegate for rendering DefaultItem instances in list components.
DefaultItem
A simple list item with title and description text.
DefaultItemStyles
Styling configuration for default list items in various visual states.