1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Minimal Code Element Test
//!
//! Run with: cargo run -p blinc_app --example code_test --features windowed
use blinc_app::prelude::*;
use blinc_app::windowed::{WindowedApp, WindowedContext};
use blinc_core::Color;
fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.init();
let config = WindowConfig {
title: "Code Test".to_string(),
width: 800,
height: 600,
resizable: true,
..Default::default()
};
WindowedApp::run(config, |ctx| build_ui(ctx))
}
fn build_ui(ctx: &WindowedContext) -> impl ElementBuilder {
let simple_code = "fn main() {\n println!(\"Hello\");\n}";
// Debug: print what's being passed to code()
println!("Code content: {:?}", simple_code);
div()
.w(ctx.width)
.h(ctx.height)
.bg(Color::rgba(0.1, 0.1, 0.15, 1.0))
.flex_col()
.gap(20.0)
.p(32.0)
// Regular text for comparison
.child(
text("Regular text works fine")
.size(16.0)
.color(Color::WHITE),
)
// Simple code without syntax highlighting
.child(
div()
.flex_col()
.gap(4.0)
.child(
text("Simple code (no syntax):")
.size(14.0)
.color(Color::YELLOW),
)
.child(code(simple_code).font_size(14.0).w(400.0).h(100.0)),
)
// Code with syntax highlighting
.child(
div()
.flex_col()
.gap(4.0)
.child(
text("With Rust highlighting:")
.size(14.0)
.color(Color::YELLOW),
)
.child(
code(simple_code)
.syntax(SyntaxConfig::new(RustHighlighter::new()))
.font_size(14.0)
.w(400.0)
.h(100.0),
),
)
// Code with line numbers
.child(
div()
.flex_col()
.gap(4.0)
.child(text("With line numbers:").size(14.0).color(Color::YELLOW))
.child(
code(simple_code)
.syntax(SyntaxConfig::new(RustHighlighter::new()))
.line_numbers(true)
.font_size(14.0)
.w(500.0)
.h(100.0),
),
)
}