@@ -2,99 +2,90 @@ use std::{cmp::min, default::Default, mem::take};
2
2
3
3
use egui:: { text:: LayoutJob , Label , Sense , Widget } ;
4
4
use 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
+ } ,
6
10
obj:: Object ,
7
11
} ;
8
12
13
+ use super :: diff:: { context_menu_items_ui, hover_items_ui} ;
9
14
use crate :: views:: { appearance:: Appearance , write_text} ;
10
15
11
16
pub ( crate ) const BYTES_PER_ROW : usize = 16 ;
12
17
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
+
39
+ out
40
+ }
41
+
42
+ fn data_row_context (
43
+ obj : & Object ,
44
+ diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
45
+ ) -> Vec < ContextItem > {
46
+ let mut out = Vec :: new ( ) ;
47
+ let reloc_diffs = diffs. iter ( ) . flat_map ( |( _, reloc_diffs) | reloc_diffs) ;
48
+ let mut prev_reloc = None ;
49
+ for reloc_diff in reloc_diffs {
50
+ let reloc = & reloc_diff. reloc ;
51
+ if prev_reloc == Some ( reloc) {
52
+ // Avoid showing consecutive duplicate relocations.
53
+ // We do this because a single relocation can span across multiple diffs if the
54
+ // bytes in the relocation changed (e.g. first byte is added, second is unchanged).
55
+ continue ;
56
+ }
57
+ prev_reloc = Some ( reloc) ;
58
+
59
+ let reloc = resolve_relocation ( obj, reloc) ;
60
+ out. append ( & mut relocation_context ( obj, reloc, None ) ) ;
61
+ }
62
+ out
63
+ }
64
+
13
65
fn data_row_hover_ui (
14
66
ui : & mut egui:: Ui ,
15
- _obj : & Object ,
16
- _diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
17
- _appearance : & Appearance ,
67
+ obj : & Object ,
68
+ diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
69
+ appearance : & Appearance ,
18
70
) {
19
71
ui. scope ( |ui| {
20
72
ui. style_mut ( ) . override_text_style = Some ( egui:: TextStyle :: Monospace ) ;
21
73
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
- // }
74
+ hover_items_ui ( ui, data_row_hover ( obj, diffs) , appearance) ;
64
75
} ) ;
65
76
}
66
77
67
- fn data_row_context_menu ( ui : & mut egui:: Ui , _diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ) {
78
+ fn data_row_context_menu (
79
+ ui : & mut egui:: Ui ,
80
+ obj : & Object ,
81
+ diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
82
+ column : usize ,
83
+ appearance : & Appearance ,
84
+ ) {
68
85
ui. scope ( |ui| {
69
86
ui. style_mut ( ) . override_text_style = Some ( egui:: TextStyle :: Monospace ) ;
70
87
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
- // }
88
+ context_menu_items_ui ( ui, data_row_context ( obj, diffs) , column, appearance) ;
98
89
} ) ;
99
90
}
100
91
@@ -113,6 +104,7 @@ pub(crate) fn data_row_ui(
113
104
address : usize ,
114
105
diffs : & [ ( DataDiff , Vec < DataRelocationDiff > ) ] ,
115
106
appearance : & Appearance ,
107
+ column : usize ,
116
108
) {
117
109
if diffs. iter ( ) . any ( |( dd, rds) | {
118
110
dd. kind != DataDiffKind :: None || rds. iter ( ) . any ( |rd| rd. kind != DataDiffKind :: None )
@@ -191,9 +183,8 @@ pub(crate) fn data_row_ui(
191
183
192
184
let response = Label :: new ( job) . sense ( Sense :: click ( ) ) . ui ( ui) ;
193
185
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) ) ;
186
+ response. context_menu ( |ui| data_row_context_menu ( ui, obj, diffs, column, appearance) ) ;
187
+ response. on_hover_ui_at_pointer ( |ui| data_row_hover_ui ( ui, obj, diffs, appearance) ) ;
197
188
}
198
189
}
199
190
0 commit comments