car_browser/perception/
formatting.rs1use super::ui_map::UiMap;
7
8pub struct UiMapFormatter {
10 pub max_elements: usize,
12 pub include_bounds: bool,
14 pub include_states: bool,
16 pub interactive_only: bool,
18 pub max_name_length: usize,
20}
21
22impl UiMapFormatter {
23 pub fn new() -> Self {
25 Self {
26 max_elements: 100,
27 include_bounds: true,
28 include_states: true,
29 interactive_only: false,
30 max_name_length: 50,
31 }
32 }
33
34 pub fn compact() -> Self {
36 Self {
37 max_elements: 40,
38 include_bounds: true,
39 include_states: true,
40 interactive_only: true,
41 max_name_length: 30,
42 }
43 }
44
45 pub fn format(&self, ui_map: &UiMap) -> String {
47 if self.interactive_only && ui_map.elements.len() > self.max_elements {
50 let mut output = String::new();
51 let elements = ui_map.interactive_elements();
52 for element in elements.iter().take(self.max_elements) {
53 use std::fmt::Write;
54 let role_str = element.role.to_hash_string();
55 let name_str = element.display_label(self.max_name_length);
56 let _ = writeln!(output, "[{}] {}{}", element.id, role_str, name_str);
57 }
58 output
59 } else {
60 ui_map.format_compact()
61 }
62 }
63}
64
65impl Default for UiMapFormatter {
66 fn default() -> Self {
67 Self::new()
68 }
69}