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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use crate::components::renderable_content::{
ContentEvent, EventResult, EventType, HoverState, RenderableContent, SensitiveZone,
};
use crate::draw_utils::content_size;
/// TextContent implementation of RenderableContent trait
/// Preserves all existing text rendering logic from draw_utils.rs
pub struct TextContent<'a> {
/// The raw text content to render
text: &'a str,
/// Text foreground color
_fg_color: &'a Option<String>,
/// Text background color
_bg_color: &'a Option<String>,
}
impl<'a> TextContent<'a> {
/// Create new TextContent
pub fn new(text: &'a str, fg_color: &'a Option<String>, bg_color: &'a Option<String>) -> Self {
Self {
text,
_fg_color: fg_color,
_bg_color: bg_color,
}
}
/// Calculate content dimensions using existing logic
fn calculate_dimensions(&self) -> (usize, usize) {
content_size(self.text)
}
}
impl<'a> RenderableContent for TextContent<'a> {
/// Get raw content dimensions using existing content_size logic
fn get_dimensions(&self) -> (usize, usize) {
self.calculate_dimensions()
}
/// Get raw content string
fn get_raw_content(&self) -> String {
self.text.to_string()
}
/// Get box-relative sensitive zones
fn get_box_relative_sensitive_zones(&self) -> Vec<SensitiveZone> {
Vec::new() // Text content typically doesn't have sensitive zones
}
/// Handle content events on text
fn handle_event(&mut self, event: &ContentEvent) -> EventResult {
match event.event_type {
EventType::Click => {
// Text content generally doesn't handle clicks unless it has links
EventResult::NotHandled
}
EventType::KeyPress => {
// Text could handle copy operations, search, etc.
if let Some(key_info) = event.key_info() {
match key_info.key.as_str() {
"c" if key_info.modifiers.contains(
&crate::components::renderable_content::KeyModifier::Ctrl,
) =>
{
// Ctrl+C for copy - could be handled here or at higher level
EventResult::NotHandled
}
"/" | "f"
if key_info.modifiers.contains(
&crate::components::renderable_content::KeyModifier::Ctrl,
) =>
{
// Search functionality
EventResult::NotHandled
}
_ => EventResult::NotHandled,
}
} else {
EventResult::NotHandled
}
}
EventType::Scroll => {
// Scroll events could be handled for text navigation
EventResult::HandledContinue // Let scrollbars handle but continue propagation
}
EventType::MouseMove => {
// Handle mouse movement over text for cursor changes, selection
if let Some(mouse_move) = event.mouse_move_info() {
if mouse_move.is_dragging {
// Text selection via drag
EventResult::NotHandled // Could be handled for text selection
} else {
// Normal movement - change cursor, show position
EventResult::NotHandled
}
} else {
EventResult::NotHandled
}
}
EventType::Hover => {
// Handle hover over text for tooltips, word highlighting
if let Some(hover_info) = event.hover_info() {
match hover_info.state {
HoverState::Enter | HoverState::Move => {
// Could show word definitions, tooltips
EventResult::NotHandled
}
HoverState::Leave => {
// Hide tooltips
EventResult::NotHandled
}
}
} else {
EventResult::NotHandled
}
}
EventType::BoxResize => {
// Text content needs to reflow on resize
EventResult::StateChanged // Trigger re-render with new dimensions
}
EventType::TitleChange => {
// Text content doesn't typically handle title changes
EventResult::NotHandled
}
_ => EventResult::NotHandled,
}
}
}