@@ -2,99 +2,89 @@ use std::{cmp::min, default::Default, mem::take};
22
33use egui:: { text:: LayoutJob , Label , Sense , Widget } ;
44use objdiff_core:: {
5- diff:: { DataDiff , DataDiffKind , DataRelocationDiff } ,
5+ diff:: {
6+ data:: resolve_relocation,
7+ display:: { relocation_context, relocation_hover, ContextItem , HoverItem } ,
8+ DataDiff , DataDiffKind , DataRelocationDiff ,
9+ } ,
610 obj:: Object ,
711} ;
812
13+ use super :: diff:: { context_menu_items_ui, hover_items_ui} ;
914use crate :: views:: { appearance:: Appearance , write_text} ;
1015
1116pub ( crate ) const BYTES_PER_ROW : usize = 16 ;
1217
18+ fn data_row_hover ( obj : & Object , diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ) -> Vec < HoverItem > {
19+ let mut out = Vec :: new ( ) ;
20+ let reloc_diffs = diffs. iter ( ) . flat_map ( |( _, reloc_diffs) | reloc_diffs) ;
21+ let mut prev_reloc = None ;
22+ for reloc_diff in reloc_diffs {
23+ let reloc = & reloc_diff. reloc ;
24+ if prev_reloc == Some ( reloc) {
25+ // Avoid showing consecutive duplicate relocations.
26+ // We do this because a single relocation can span across multiple diffs if the
27+ // bytes in the relocation changed (e.g. first byte is added, second is unchanged).
28+ continue ;
29+ }
30+ prev_reloc = Some ( reloc) ;
31+
32+ // TODO: Change hover text color depending on Insert/Delete/Replace kind
33+ // let color = get_color_for_diff_kind(reloc_diff.kind, appearance);
34+
35+ let reloc = resolve_relocation ( obj, reloc) ;
36+ out. append ( & mut relocation_hover ( obj, reloc) ) ;
37+ }
38+ out
39+ }
40+
41+ fn data_row_context (
42+ obj : & Object ,
43+ diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
44+ ) -> Vec < ContextItem > {
45+ let mut out = Vec :: new ( ) ;
46+ let reloc_diffs = diffs. iter ( ) . flat_map ( |( _, reloc_diffs) | reloc_diffs) ;
47+ let mut prev_reloc = None ;
48+ for reloc_diff in reloc_diffs {
49+ let reloc = & reloc_diff. reloc ;
50+ if prev_reloc == Some ( reloc) {
51+ // Avoid showing consecutive duplicate relocations.
52+ // We do this because a single relocation can span across multiple diffs if the
53+ // bytes in the relocation changed (e.g. first byte is added, second is unchanged).
54+ continue ;
55+ }
56+ prev_reloc = Some ( reloc) ;
57+
58+ let reloc = resolve_relocation ( obj, reloc) ;
59+ out. append ( & mut relocation_context ( obj, reloc, None ) ) ;
60+ }
61+ out
62+ }
63+
1364fn data_row_hover_ui (
1465 ui : & mut egui:: Ui ,
15- _obj : & Object ,
16- _diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
17- _appearance : & Appearance ,
66+ obj : & Object ,
67+ diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
68+ appearance : & Appearance ,
1869) {
1970 ui. scope ( |ui| {
2071 ui. style_mut ( ) . override_text_style = Some ( egui:: TextStyle :: Monospace ) ;
2172 ui. style_mut ( ) . wrap_mode = Some ( egui:: TextWrapMode :: Extend ) ;
22-
23- // TODO
24- // let reloc_diffs = diffs.iter().flat_map(|(_, reloc_diffs)| reloc_diffs);
25- // let mut prev_reloc = None;
26- // for reloc_diff in reloc_diffs {
27- // let reloc = &reloc_diff.reloc;
28- // if prev_reloc == Some(reloc) {
29- // // Avoid showing consecutive duplicate relocations.
30- // // We do this because a single relocation can span across multiple diffs if the
31- // // bytes in the relocation changed (e.g. first byte is added, second is unchanged).
32- // continue;
33- // }
34- // prev_reloc = Some(reloc);
35- //
36- // let color = get_color_for_diff_kind(reloc_diff.kind, appearance);
37- //
38- // // TODO: Most of this code is copy-pasted from ins_hover_ui.
39- // // Try to separate this out into a shared function.
40- // ui.label(format!("Relocation type: {}", obj.arch.display_reloc(reloc.flags)));
41- // ui.label(format!("Relocation address: {:x}", reloc.address));
42- // let addend_str = match reloc.addend.cmp(&0i64) {
43- // Ordering::Greater => format!("+{:x}", reloc.addend),
44- // Ordering::Less => format!("-{:x}", -reloc.addend),
45- // _ => "".to_string(),
46- // };
47- // ui.colored_label(color, format!("Name: {}{}", reloc.target.name, addend_str));
48- // if let Some(orig_section_index) = reloc.target.orig_section_index {
49- // if let Some(section) =
50- // obj.sections.iter().find(|s| s.orig_index == orig_section_index)
51- // {
52- // ui.colored_label(color, format!("Section: {}", section.name));
53- // }
54- // ui.colored_label(
55- // color,
56- // format!("Address: {:x}{}", reloc.target.address, addend_str),
57- // );
58- // ui.colored_label(color, format!("Size: {:x}", reloc.target.size));
59- // if reloc.addend >= 0 && reloc.target.bytes.len() > reloc.addend as usize {}
60- // } else {
61- // ui.colored_label(color, "Extern".to_string());
62- // }
63- // }
73+ hover_items_ui ( ui, data_row_hover ( obj, diffs) , appearance) ;
6474 } ) ;
6575}
6676
67- fn data_row_context_menu ( ui : & mut egui:: Ui , _diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ) {
77+ fn data_row_context_menu (
78+ ui : & mut egui:: Ui ,
79+ obj : & Object ,
80+ diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
81+ column : usize ,
82+ appearance : & Appearance ,
83+ ) {
6884 ui. scope ( |ui| {
6985 ui. style_mut ( ) . override_text_style = Some ( egui:: TextStyle :: Monospace ) ;
7086 ui. style_mut ( ) . wrap_mode = Some ( egui:: TextWrapMode :: Extend ) ;
71-
72- // TODO
73- // let reloc_diffs = diffs.iter().flat_map(|(_, reloc_diffs)| reloc_diffs);
74- // let mut prev_reloc = None;
75- // for reloc_diff in reloc_diffs {
76- // let reloc = &reloc_diff.reloc;
77- // if prev_reloc == Some(reloc) {
78- // // Avoid showing consecutive duplicate relocations.
79- // // We do this because a single relocation can span across multiple diffs if the
80- // // bytes in the relocation changed (e.g. first byte is added, second is unchanged).
81- // continue;
82- // }
83- // prev_reloc = Some(reloc);
84- //
85- // // TODO: This code is copy-pasted from ins_context_menu.
86- // // Try to separate this out into a shared function.
87- // if let Some(name) = &reloc.target.demangled_name {
88- // if ui.button(format!("Copy \"{name}\"")).clicked() {
89- // ui.output_mut(|output| output.copied_text.clone_from(name));
90- // ui.close_menu();
91- // }
92- // }
93- // if ui.button(format!("Copy \"{}\"", reloc.target.name)).clicked() {
94- // ui.output_mut(|output| output.copied_text.clone_from(&reloc.target.name));
95- // ui.close_menu();
96- // }
97- // }
87+ context_menu_items_ui ( ui, data_row_context ( obj, diffs) , column, appearance) ;
9888 } ) ;
9989}
10090
@@ -113,6 +103,7 @@ pub(crate) fn data_row_ui(
113103 address : usize ,
114104 diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
115105 appearance : & Appearance ,
106+ column : usize ,
116107) {
117108 if diffs. iter ( ) . any ( |( dd, rds) | {
118109 dd. kind != DataDiffKind :: None || rds. iter ( ) . any ( |rd| rd. kind != DataDiffKind :: None )
@@ -191,9 +182,8 @@ pub(crate) fn data_row_ui(
191182
192183 let response = Label :: new ( job) . sense ( Sense :: click ( ) ) . ui ( ui) ;
193184 if let Some ( obj) = obj {
194- response
195- . on_hover_ui_at_pointer ( |ui| data_row_hover_ui ( ui, obj, diffs, appearance) )
196- . context_menu ( |ui| data_row_context_menu ( ui, diffs) ) ;
185+ response. context_menu ( |ui| data_row_context_menu ( ui, obj, diffs, column, appearance) ) ;
186+ response. on_hover_ui_at_pointer ( |ui| data_row_hover_ui ( ui, obj, diffs, appearance) ) ;
197187 }
198188}
199189
0 commit comments