Skip to main content

Module code

Module code 

Source
Expand description

Code block widget with syntax highlighting

A code display/editing widget that supports:

  • Syntax highlighting via regex-based token matching
  • Optional line numbers in the gutter
  • Read-only by default, editable with .edit(true)
  • All Div layout methods via Deref

§Example

use blinc_layout::prelude::*;
use blinc_layout::syntax::{SyntaxConfig, RustHighlighter};

// Read-only code block
code(r#"fn main() { println!("Hello"); }"#)
    .syntax(SyntaxConfig::new(RustHighlighter::new()))
    .line_numbers(true)
    .font_size(14.0)
    .rounded(8.0)

// Editable code block with change callback
code("let x = 42;")
    .edit(true)
    .on_change(|new_content| {
        println!("Content changed: {}", new_content);
    })

Structs§

Code
Code block widget
CodeConfig
Code block configuration

Functions§

code
Create a code block with the given content
pre
Create a preformatted text block (alias for code)