| | @@ -11,6 +11,22 @@ pub struct SharedBrowserView { |
| 11 | 11 | scroll_to_selection: bool, |
| 12 | 12 | restore_key: Option<String>, |
| 13 | 13 | sort_alpha: bool, |
| 14 | + /// Cached all_structs — recomputed only when schema changes |
| 15 | + cached_all: Vec<SharedStruct>, |
| 16 | + cached_all_key: usize, |
| 17 | + /// Cached entries — recomputed only when path changes |
| 18 | + entries_cache_key: Vec<String>, |
| 19 | + cached_current_entries: Vec<Entry>, |
| 20 | + cached_parent_entries: Option<Vec<Entry>>, |
| 21 | + /// Cached values column data: (path, selection_label) -> flattened rows |
| 22 | + values_cache_key: (Vec<String>, String), |
| 23 | + values_rows: Vec<ValueRow>, |
| 24 | +} |
| 25 | + |
| 26 | +/// Pre-flattened row for the values column (file headers + values). |
| 27 | +enum ValueRow { |
| 28 | + FileHeader(String), // display filename |
| 29 | + Value { text: String, color: egui::Color32, count: Option<usize> }, |
| 14 | 30 | } |
| 15 | 31 | |
| 16 | 32 | /// An entry at a given level of the schema tree. |
| | @@ -30,12 +46,23 @@ impl SharedBrowserView { |
| 30 | 46 | scroll_to_selection: false, |
| 31 | 47 | restore_key: None, |
| 32 | 48 | sort_alpha: false, |
| 49 | + cached_all: Vec::new(), |
| 50 | + cached_all_key: usize::MAX, // force initial rebuild |
| 51 | + entries_cache_key: vec!["__invalid__".to_string()], // force initial rebuild |
| 52 | + cached_current_entries: Vec::new(), |
| 53 | + cached_parent_entries: None, |
| 54 | + values_cache_key: (Vec::new(), String::new()), |
| 55 | + values_rows: Vec::new(), |
| 33 | 56 | } |
| 34 | 57 | } |
| 35 | 58 | |
| 36 | 59 | pub fn invalidate(&mut self) { |
| 37 | 60 | self.path.clear(); |
| 38 | 61 | self.selection = 0; |
| 62 | + self.cached_all_key = usize::MAX; |
| 63 | + self.entries_cache_key = vec!["__invalid__".to_string()]; |
| 64 | + self.values_cache_key = (Vec::new(), String::new()); |
| 65 | + self.values_rows.clear(); |
| 39 | 66 | } |
| 40 | 67 | |
| 41 | 68 | pub fn show( |
| | @@ -55,43 +82,56 @@ impl SharedBrowserView { |
| 55 | 82 | return; |
| 56 | 83 | } |
| 57 | 84 | |
| 58 | | - // Build entries for current level and parent level |
| 59 | | - let mut current_entries = build_entries_at_path(&self.path, schema); |
| 60 | | - if self.sort_alpha && self.path.len() == 1 { |
| 61 | | - current_entries.sort_by(|a, b| a.label.cmp(&b.label)); |
| 85 | + // Cache all_structs — only recompute when schema changes |
| 86 | + let schema_key = schema.structs.len() + schema.unique_structs.len(); |
| 87 | + if self.cached_all_key != schema_key { |
| 88 | + self.cached_all = schema.all_structs(); |
| 89 | + self.cached_all_key = schema_key; |
| 90 | + } |
| 91 | + let all = &self.cached_all; |
| 92 | + |
| 93 | + // Build entries — cached, only recompute when path changes |
| 94 | + if self.entries_cache_key != self.path { |
| 95 | + self.cached_current_entries = build_entries_at_path(&self.path, schema, all); |
| 96 | + if self.sort_alpha && self.path.len() == 1 { |
| 97 | + self.cached_current_entries.sort_by(|a, b| a.label.cmp(&b.label)); |
| 98 | + } |
| 99 | + self.cached_parent_entries = if self.path.is_empty() { |
| 100 | + None |
| 101 | + } else { |
| 102 | + Some(build_entries_at_path( |
| 103 | + &self.path[..self.path.len() - 1], |
| 104 | + schema, |
| 105 | + all, |
| 106 | + )) |
| 107 | + }; |
| 108 | + self.entries_cache_key = self.path.clone(); |
| 62 | 109 | } |
| 63 | | - let parent_entries = if self.path.is_empty() { |
| 64 | | - None |
| 65 | | - } else { |
| 66 | | - Some(build_entries_at_path( |
| 67 | | - &self.path[..self.path.len() - 1], |
| 68 | | - schema, |
| 69 | | - )) |
| 70 | | - }; |
| 71 | 110 | |
| 72 | 111 | // Restore selection by key after going back |
| 73 | 112 | if let Some(key) = self.restore_key.take() { |
| 74 | | - if let Some(idx) = current_entries.iter().position(|e| e.label == key) { |
| 113 | + if let Some(idx) = self.cached_current_entries.iter().position(|e| e.label == key) { |
| 75 | 114 | self.selection = idx; |
| 76 | 115 | } |
| 77 | 116 | } |
| 78 | 117 | |
| 79 | 118 | // Clamp selection |
| 80 | | - if !current_entries.is_empty() && self.selection >= current_entries.len() { |
| 81 | | - self.selection = current_entries.len().saturating_sub(1); |
| 119 | + if !self.cached_current_entries.is_empty() && self.selection >= self.cached_current_entries.len() { |
| 120 | + self.selection = self.cached_current_entries.len().saturating_sub(1); |
| 82 | 121 | } |
| 83 | 122 | |
| 84 | 123 | // Keyboard navigation |
| 85 | 124 | let action = crate::widgets::read_miller_keys(ui, false); |
| 86 | | - if crate::widgets::apply_selection(&mut self.selection, action, current_entries.len()) { |
| 125 | + if crate::widgets::apply_selection(&mut self.selection, action, self.cached_current_entries.len()) { |
| 87 | 126 | self.scroll_to_selection = true; |
| 88 | 127 | } |
| 89 | 128 | if action == crate::widgets::MillerAction::Enter { |
| 90 | | - if let Some(entry) = current_entries.get(self.selection) { |
| 129 | + if let Some(entry) = self.cached_current_entries.get(self.selection) { |
| 91 | 130 | if entry.is_container { |
| 92 | 131 | self.path.push(entry.label.clone()); |
| 93 | 132 | self.selection = 0; |
| 94 | 133 | self.scroll_to_selection = true; |
| 134 | + self.entries_cache_key.clear(); // force rebuild next frame |
| 95 | 135 | } |
| 96 | 136 | } |
| 97 | 137 | } |
| | @@ -99,26 +139,30 @@ impl SharedBrowserView { |
| 99 | 139 | let popped = self.path.pop().unwrap(); |
| 100 | 140 | self.restore_key = Some(popped); |
| 101 | 141 | self.scroll_to_selection = true; |
| 142 | + self.entries_cache_key.clear(); // force rebuild next frame |
| 102 | 143 | } |
| 103 | 144 | |
| 104 | 145 | // 'A' toggles alphabetical sort on the structs pane |
| 105 | 146 | let toggle_sort = ui.input(|i| i.key_pressed(egui::Key::A)); |
| 106 | 147 | if toggle_sort && self.path.len() == 1 { |
| 107 | | - let selected_label = current_entries.get(self.selection).map(|e| e.label.clone()); |
| 148 | + let selected_label = self.cached_current_entries.get(self.selection).map(|e| e.label.clone()); |
| 108 | 149 | self.sort_alpha = !self.sort_alpha; |
| 109 | | - // Re-sort in place |
| 150 | + // Invalidate + rebuild |
| 151 | + self.entries_cache_key.clear(); |
| 152 | + self.cached_current_entries = build_entries_at_path(&self.path, schema, all); |
| 110 | 153 | if self.sort_alpha { |
| 111 | | - current_entries.sort_by(|a, b| a.label.cmp(&b.label)); |
| 112 | | - } else { |
| 113 | | - current_entries = build_entries_at_path(&self.path, schema); |
| 154 | + self.cached_current_entries.sort_by(|a, b| a.label.cmp(&b.label)); |
| 114 | 155 | } |
| 115 | | - // Restore selection to the same struct after reordering |
| 156 | + self.entries_cache_key = self.path.clone(); |
| 116 | 157 | if let Some(label) = selected_label { |
| 117 | | - if let Some(idx) = current_entries.iter().position(|e| e.label == label) { |
| 158 | + if let Some(idx) = self.cached_current_entries.iter().position(|e| e.label == label) { |
| 118 | 159 | self.selection = idx; |
| 119 | 160 | } |
| 120 | 161 | } |
| 121 | 162 | } |
| 163 | + // Re-borrow after potential mutation |
| 164 | + let current_entries = &self.cached_current_entries; |
| 165 | + let parent_entries = &self.cached_parent_entries; |
| 122 | 166 | |
| 123 | 167 | // --- Three-column miller layout --- |
| 124 | 168 | let avail = ui.available_rect_before_wrap(); |
| | @@ -176,12 +220,22 @@ impl SharedBrowserView { |
| 176 | 220 | ui.set_height(col_height); |
| 177 | 221 | render_pane_title(ui, &right_title); |
| 178 | 222 | if let Some(entry) = current_entries.get(self.selection) { |
| 223 | + // Cache the expensive value collection + flattening |
| 224 | + let cache_key = (self.path.clone(), entry.label.clone()); |
| 225 | + if self.values_cache_key != cache_key { |
| 226 | + self.values_rows = build_value_rows( |
| 227 | + &self.path, &entry.label, schema, &all, files, |
| 228 | + ); |
| 229 | + self.values_cache_key = cache_key; |
| 230 | + } |
| 231 | + |
| 179 | 232 | if let Some(nav) = render_values_column( |
| 180 | 233 | ui, |
| 181 | 234 | &self.path, |
| 182 | 235 | &entry.label, |
| 183 | 236 | schema, |
| 184 | | - files, |
| 237 | + &all, |
| 238 | + &self.values_rows, |
| 185 | 239 | col_height, |
| 186 | 240 | ) { |
| 187 | 241 | type_nav = Some(nav); |
| | @@ -215,7 +269,7 @@ impl SharedBrowserView { |
| 215 | 269 | } |
| 216 | 270 | |
| 217 | 271 | /// Build the list of entries at a given path in the schema tree. |
| 218 | | -fn build_entries_at_path(path: &[String], schema: &SchemaOverview) -> Vec<Entry> { |
| 272 | +fn build_entries_at_path(path: &[String], schema: &SchemaOverview, all: &[SharedStruct]) -> Vec<Entry> { |
| 219 | 273 | match path.len() { |
| 220 | 274 | 0 => { |
| 221 | 275 | // Root: show "Shared" and "Unique" categories |
| | @@ -269,11 +323,8 @@ fn build_entries_at_path(path: &[String], schema: &SchemaOverview) -> Vec<Entry> |
| 269 | 323 | return Vec::new(); |
| 270 | 324 | }; |
| 271 | 325 | |
| 272 | | - // Use all structs (shared + unique) for type resolution and display |
| 273 | | - let all = schema.all_structs(); |
| 274 | | - |
| 275 | 326 | // Walk remaining path segments to find the current type |
| 276 | | - let current_type = resolve_type_at_path(&root_struct.fields, &path[2..], &all); |
| 327 | + let current_type = resolve_type_at_path(&root_struct.fields, &path[2..], all); |
| 277 | 328 | |
| 278 | 329 | match current_type { |
| 279 | 330 | Some(fields) => fields |
| | @@ -556,12 +607,132 @@ fn render_current_column( |
| 556 | 607 | |
| 557 | 608 | /// Render the right column showing all values found for the selected entry. |
| 558 | 609 | /// Returns an optional navigation path if the user clicks a type link. |
| 610 | +/// Build pre-flattened rows for the values column (expensive — cached). |
| 611 | +fn build_value_rows( |
| 612 | + path: &[String], |
| 613 | + selected_label: &str, |
| 614 | + schema: &SchemaOverview, |
| 615 | + all: &[SharedStruct], |
| 616 | + files: &[(String, serde_json::Value)], |
| 617 | +) -> Vec<ValueRow> { |
| 618 | + if path.len() < 2 { |
| 619 | + return Vec::new(); |
| 620 | + } |
| 621 | + let structs = match path[0].as_str() { |
| 622 | + "Shared" => &schema.structs, |
| 623 | + "Unique" => &schema.unique_structs, |
| 624 | + _ => return Vec::new(), |
| 625 | + }; |
| 626 | + let Some(root_struct) = structs.iter().find(|s| s.name == path[1]) else { |
| 627 | + return Vec::new(); |
| 628 | + }; |
| 629 | + |
| 630 | + let selected_field_type = resolve_type_at_path(&root_struct.fields, &path[2..], all) |
| 631 | + .and_then(|fields| fields.get(selected_label).cloned()); |
| 632 | + let is_primitive = selected_field_type |
| 633 | + .as_ref() |
| 634 | + .map(|t| !is_navigable_type(t, all)) |
| 635 | + .unwrap_or(true); |
| 636 | + |
| 637 | + let raw_values = collect_values_for_field(path, selected_label, schema, all, files); |
| 638 | + |
| 639 | + // Group by file |
| 640 | + let mut per_file: Vec<(&str, Vec<&str>)> = Vec::new(); |
| 641 | + for (val, filename) in &raw_values { |
| 642 | + if let Some(entry) = per_file.last_mut().filter(|(f, _)| *f == filename.as_str()) { |
| 643 | + entry.1.push(val.as_str()); |
| 644 | + } else { |
| 645 | + per_file.push((filename.as_str(), vec![val.as_str()])); |
| 646 | + } |
| 647 | + } |
| 648 | + |
| 649 | + let mut rows = Vec::new(); |
| 650 | + for (filename, values) in &per_file { |
| 651 | + let display_name = filename.strip_suffix(".json").unwrap_or(filename); |
| 652 | + rows.push(ValueRow::FileHeader(format!("── {} ──", display_name))); |
| 653 | + |
| 654 | + if is_primitive { |
| 655 | + let mut counts: Vec<(&str, usize)> = Vec::new(); |
| 656 | + for val in values { |
| 657 | + if let Some(entry) = counts.iter_mut().find(|(v, _)| *v == *val) { |
| 658 | + entry.1 += 1; |
| 659 | + } else { |
| 660 | + counts.push((val, 1)); |
| 661 | + } |
| 662 | + } |
| 663 | + counts.sort_by(|a, b| b.1.cmp(&a.1)); |
| 664 | + for (val_str, count) in counts { |
| 665 | + let display = if val_str.len() > 60 { |
| 666 | + format!("{}…", &val_str[..57]) |
| 667 | + } else { |
| 668 | + val_str.to_string() |
| 669 | + }; |
| 670 | + let color = value_color(val_str); |
| 671 | + rows.push(ValueRow::Value { |
| 672 | + text: display, |
| 673 | + color, |
| 674 | + count: if count > 1 { Some(count) } else { None }, |
| 675 | + }); |
| 676 | + } |
| 677 | + } else { |
| 678 | + for val_str in values { |
| 679 | + let display = if val_str.len() > 80 { |
| 680 | + format!("{}…", &val_str[..77]) |
| 681 | + } else { |
| 682 | + val_str.to_string() |
| 683 | + }; |
| 684 | + let color = value_color(val_str); |
| 685 | + rows.push(ValueRow::Value { text: display, color, count: None }); |
| 686 | + } |
| 687 | + } |
| 688 | + } |
| 689 | + rows |
| 690 | +} |
| 691 | + |
| 692 | +/// Collect all field values across files (expensive — should be cached). |
| 693 | +fn collect_values_for_field( |
| 694 | + path: &[String], |
| 695 | + selected_label: &str, |
| 696 | + schema: &SchemaOverview, |
| 697 | + all: &[SharedStruct], |
| 698 | + files: &[(String, serde_json::Value)], |
| 699 | +) -> Vec<(String, String)> { |
| 700 | + if path.len() < 2 { |
| 701 | + return Vec::new(); |
| 702 | + } |
| 703 | + let structs = match path[0].as_str() { |
| 704 | + "Shared" => &schema.structs, |
| 705 | + "Unique" => &schema.unique_structs, |
| 706 | + _ => return Vec::new(), |
| 707 | + }; |
| 708 | + let Some(root_struct) = structs.iter().find(|s| s.name == path[1]) else { |
| 709 | + return Vec::new(); |
| 710 | + }; |
| 711 | + let mut field_path: Vec<&str> = path[2..].iter().map(|s| s.as_str()).collect(); |
| 712 | + field_path.push(selected_label); |
| 713 | + let field_keys: Vec<&str> = root_struct.fields.keys().map(|k| k.as_str()).collect(); |
| 714 | + |
| 715 | + let mut all_values: Vec<(String, String)> = Vec::new(); |
| 716 | + for (filename, value) in files { |
| 717 | + if !root_struct.source_files.contains(filename) { |
| 718 | + continue; |
| 719 | + } |
| 720 | + let mut values: Vec<String> = Vec::new(); |
| 721 | + collect_nested_field_values(value, &field_keys, &field_path, &mut values); |
| 722 | + for v in values { |
| 723 | + all_values.push((v, filename.clone())); |
| 724 | + } |
| 725 | + } |
| 726 | + all_values |
| 727 | +} |
| 728 | + |
| 559 | 729 | fn render_values_column( |
| 560 | 730 | ui: &mut Ui, |
| 561 | 731 | path: &[String], |
| 562 | 732 | selected_label: &str, |
| 563 | 733 | schema: &SchemaOverview, |
| 564 | | - files: &[(String, serde_json::Value)], |
| 734 | + all: &[SharedStruct], |
| 735 | + rows: &[ValueRow], |
| 565 | 736 | height: f32, |
| 566 | 737 | ) -> Option<Vec<String>> { |
| 567 | 738 | let mut nav_target: Option<Vec<String>> = None; |
| | @@ -581,12 +752,14 @@ fn render_values_column( |
| 581 | 752 | ); |
| 582 | 753 | ui.add_space(4.0); |
| 583 | 754 | |
| 755 | + let row_height = ui.text_style_height(&egui::TextStyle::Monospace) + 6.0; |
| 584 | 756 | egui::ScrollArea::vertical() |
| 585 | 757 | .id_salt("shared_values") |
| 586 | 758 | .auto_shrink(false) |
| 587 | 759 | .max_height(height - 24.0) |
| 588 | | - .show(ui, |ui| { |
| 589 | | - for s in structs { |
| 760 | + .show_rows(ui, row_height, structs.len(), |ui, range| { |
| 761 | + for i in range { |
| 762 | + let s = &structs[i]; |
| 590 | 763 | ui.horizontal(|ui| { |
| 591 | 764 | ui.label( |
| 592 | 765 | RichText::new(egui_phosphor::regular::BRACKETS_CURLY) |
| | @@ -639,13 +812,15 @@ fn render_values_column( |
| 639 | 812 | ); |
| 640 | 813 | ui.add_space(4.0); |
| 641 | 814 | |
| 815 | + let fields_vec: Vec<(&String, &InferredType)> = s.fields.iter().collect(); |
| 816 | + let row_height = ui.text_style_height(&egui::TextStyle::Monospace) + 6.0; |
| 642 | 817 | egui::ScrollArea::vertical() |
| 643 | 818 | .id_salt("shared_values") |
| 644 | 819 | .auto_shrink(false) |
| 645 | 820 | .max_height(height - 40.0) |
| 646 | | - .show(ui, |ui| { |
| 647 | | - let all = schema.all_structs(); |
| 648 | | - for (idx, (name, typ)) in s.fields.iter().enumerate() { |
| 821 | + .show_rows(ui, row_height, fields_vec.len(), |ui, range| { |
| 822 | + for idx in range { |
| 823 | + let (name, typ) = fields_vec[idx]; |
| 649 | 824 | let short = typ.short_name(&all); |
| 650 | 825 | let color = crate::theme::type_color(&short); |
| 651 | 826 | let is_nav = is_navigable_type(typ, &all); |
| | @@ -712,7 +887,7 @@ fn render_values_column( |
| 712 | 887 | }); |
| 713 | 888 | } |
| 714 | 889 | _ => { |
| 715 | | - // Inside a struct — selected is a field name, show all values across files |
| 890 | + // Inside a struct — show pre-flattened value rows with virtual scrolling |
| 716 | 891 | let structs = match path[0].as_str() { |
| 717 | 892 | "Shared" => &schema.structs, |
| 718 | 893 | "Unique" => &schema.unique_structs, |
| | @@ -722,26 +897,14 @@ fn render_values_column( |
| 722 | 897 | return None; |
| 723 | 898 | }; |
| 724 | 899 | |
| 725 | | - // Build the full field path from path[2..] + selected_label |
| 726 | | - let mut field_path: Vec<&str> = path[2..].iter().map(|s| s.as_str()).collect(); |
| 727 | | - field_path.push(selected_label); |
| 728 | | - |
| 729 | | - let all = schema.all_structs(); |
| 730 | | - |
| 731 | | - // Get the type of the selected field |
| 732 | | - let selected_field_type = resolve_type_at_path(&root_struct.fields, &path[2..], &all) |
| 900 | + let selected_field_type = resolve_type_at_path(&root_struct.fields, &path[2..], all) |
| 733 | 901 | .and_then(|fields| fields.get(selected_label).cloned()); |
| 734 | 902 | |
| 735 | 903 | let field_type_str = selected_field_type |
| 736 | 904 | .as_ref() |
| 737 | | - .map(|t| t.short_name(&all)) |
| 905 | + .map(|t| t.short_name(all)) |
| 738 | 906 | .unwrap_or_default(); |
| 739 | 907 | |
| 740 | | - let is_primitive = selected_field_type |
| 741 | | - .as_ref() |
| 742 | | - .map(|t| !is_navigable_type(t, &all)) |
| 743 | | - .unwrap_or(true); |
| 744 | | - |
| 745 | 908 | ui.label( |
| 746 | 909 | RichText::new(format!("{}: {}", selected_label, field_type_str)) |
| 747 | 910 | .color(CatppuccinMocha::BLUE) |
| | @@ -749,100 +912,34 @@ fn render_values_column( |
| 749 | 912 | ); |
| 750 | 913 | ui.add_space(4.0); |
| 751 | 914 | |
| 752 | | - // Collect field keys for shape matching |
| 753 | | - let field_keys: Vec<&str> = root_struct.fields.keys().map(|k| k.as_str()).collect(); |
| 754 | | - |
| 755 | | - // Collect all values across all files |
| 756 | | - let mut all_values: Vec<(String, String)> = Vec::new(); // (value, filename) |
| 757 | | - for (filename, value) in files { |
| 758 | | - if !root_struct.source_files.contains(filename) { |
| 759 | | - continue; |
| 760 | | - } |
| 761 | | - let mut values: Vec<String> = Vec::new(); |
| 762 | | - collect_nested_field_values(value, &field_keys, &field_path, &mut values); |
| 763 | | - for v in values { |
| 764 | | - all_values.push((v, filename.clone())); |
| 765 | | - } |
| 766 | | - } |
| 767 | | - |
| 768 | | - // Group values per file for display |
| 769 | | - let mut per_file: Vec<(&str, Vec<&str>)> = Vec::new(); |
| 770 | | - for (val, filename) in &all_values { |
| 771 | | - if let Some(entry) = per_file.last_mut().filter(|(f, _)| *f == filename.as_str()) { |
| 772 | | - entry.1.push(val.as_str()); |
| 773 | | - } else { |
| 774 | | - per_file.push((filename.as_str(), vec![val.as_str()])); |
| 775 | | - } |
| 776 | | - } |
| 777 | | - |
| 915 | + let row_height = ui.text_style_height(&egui::TextStyle::Monospace) + 4.0; |
| 778 | 916 | egui::ScrollArea::vertical() |
| 779 | 917 | .id_salt("shared_values") |
| 780 | 918 | .auto_shrink(false) |
| 781 | 919 | .max_height(height - 24.0) |
| 782 | | - .show(ui, |ui| { |
| 783 | | - for (filename, values) in &per_file { |
| 784 | | - let display_name = filename.strip_suffix(".json").unwrap_or(filename); |
| 785 | | - |
| 786 | | - // File separator header |
| 787 | | - ui.add_space(2.0); |
| 788 | | - ui.horizontal(|ui| { |
| 789 | | - let sep_rect = ui.available_rect_before_wrap(); |
| 790 | | - let y = sep_rect.center().y; |
| 791 | | - let left = sep_rect.left(); |
| 792 | | - |
| 793 | | - ui.painter().line_segment( |
| 794 | | - [egui::pos2(left, y), egui::pos2(left + 8.0, y)], |
| 795 | | - egui::Stroke::new(1.0, CatppuccinMocha::SURFACE2), |
| 796 | | - ); |
| 797 | | - |
| 798 | | - ui.add_space(10.0); |
| 799 | | - ui.label( |
| 800 | | - RichText::new(display_name) |
| 801 | | - .color(CatppuccinMocha::YELLOW) |
| 802 | | - .family(egui::FontFamily::Monospace) |
| 803 | | - .size(11.0), |
| 804 | | - ); |
| 805 | | - |
| 806 | | - let after = ui.available_rect_before_wrap(); |
| 807 | | - ui.painter().line_segment( |
| 808 | | - [egui::pos2(after.left(), y), egui::pos2(after.right(), y)], |
| 809 | | - egui::Stroke::new(1.0, CatppuccinMocha::SURFACE2), |
| 810 | | - ); |
| 811 | | - }); |
| 812 | | - ui.add_space(2.0); |
| 813 | | - |
| 814 | | - if is_primitive { |
| 815 | | - // Group identical values within this file |
| 816 | | - let mut counts: Vec<(&str, usize)> = Vec::new(); |
| 817 | | - for val in values { |
| 818 | | - if let Some(entry) = counts.iter_mut().find(|(v, _)| *v == *val) { |
| 819 | | - entry.1 += 1; |
| 820 | | - } else { |
| 821 | | - counts.push((val, 1)); |
| 822 | | - } |
| 920 | + .show_rows(ui, row_height, rows.len(), |ui, range| { |
| 921 | + for i in range { |
| 922 | + match &rows[i] { |
| 923 | + ValueRow::FileHeader(name) => { |
| 924 | + ui.label( |
| 925 | + RichText::new(name) |
| 926 | + .color(CatppuccinMocha::YELLOW) |
| 927 | + .family(egui::FontFamily::Monospace) |
| 928 | + .size(11.0), |
| 929 | + ); |
| 823 | 930 | } |
| 824 | | - counts.sort_by(|a, b| b.1.cmp(&a.1)); |
| 825 | | - |
| 826 | | - for (val_str, count) in &counts { |
| 827 | | - let display = if val_str.len() > 60 { |
| 828 | | - format!("{}…", &val_str[..57]) |
| 829 | | - } else { |
| 830 | | - val_str.to_string() |
| 831 | | - }; |
| 832 | | - |
| 833 | | - let color = value_color(val_str); |
| 834 | | - |
| 931 | + ValueRow::Value { text, color, count } => { |
| 835 | 932 | ui.horizontal(|ui| { |
| 836 | 933 | ui.add_space(4.0); |
| 837 | 934 | ui.label( |
| 838 | | - RichText::new(&display) |
| 839 | | - .color(color) |
| 935 | + RichText::new(text) |
| 936 | + .color(*color) |
| 840 | 937 | .family(egui::FontFamily::Monospace) |
| 841 | 938 | .size(11.0), |
| 842 | 939 | ); |
| 843 | | - if *count > 1 { |
| 940 | + if let Some(c) = count { |
| 844 | 941 | ui.label( |
| 845 | | - RichText::new(format!("×{}", count)) |
| 942 | + RichText::new(format!("×{}", c)) |
| 846 | 943 | .color(CatppuccinMocha::OVERLAY0) |
| 847 | 944 | .family(egui::FontFamily::Monospace) |
| 848 | 945 | .size(10.0), |
| | @@ -850,27 +947,6 @@ fn render_values_column( |
| 850 | 947 | } |
| 851 | 948 | }); |
| 852 | 949 | } |
| 853 | | - } else { |
| 854 | | - // Non-primitive: list each value |
| 855 | | - for val_str in values { |
| 856 | | - let display = if val_str.len() > 80 { |
| 857 | | - format!("{}…", &val_str[..77]) |
| 858 | | - } else { |
| 859 | | - val_str.to_string() |
| 860 | | - }; |
| 861 | | - |
| 862 | | - let color = value_color(val_str); |
| 863 | | - |
| 864 | | - ui.horizontal(|ui| { |
| 865 | | - ui.add_space(4.0); |
| 866 | | - ui.label( |
| 867 | | - RichText::new(&display) |
| 868 | | - .color(color) |
| 869 | | - .family(egui::FontFamily::Monospace) |
| 870 | | - .size(11.0), |
| 871 | | - ); |
| 872 | | - }); |
| 873 | | - } |
| 874 | 950 | } |
| 875 | 951 | } |
| 876 | 952 | }); |