1
1
use std:: default:: Default ;
2
2
3
- use egui:: { text:: LayoutJob , Align , Label , Layout , Response , Sense , Vec2 , Widget } ;
3
+ use egui:: { epaint :: color , text:: LayoutJob , Align , Label , Layout , Response , Sense , Vec2 , Widget } ;
4
4
use egui_extras:: { Column , TableBuilder , TableRow } ;
5
5
use objdiff_core:: {
6
6
arch:: ObjArch ,
@@ -17,9 +17,54 @@ use crate::views::{
17
17
symbol_diff:: { match_color_for_symbol, DiffViewState , SymbolRefByName , View } ,
18
18
} ;
19
19
20
+ #[ derive( Copy , Clone , Eq , PartialEq ) ]
21
+ enum ColumnId {
22
+ Left ,
23
+ Right ,
24
+ }
25
+
20
26
#[ derive( Default ) ]
21
27
pub struct FunctionViewState {
22
- pub highlight : HighlightKind ,
28
+ pub left_highlight : HighlightKind ,
29
+ pub right_highlight : HighlightKind ,
30
+ }
31
+
32
+ impl FunctionViewState {
33
+ pub fn highlight ( & self , column : ColumnId ) -> & HighlightKind {
34
+ match column {
35
+ ColumnId :: Left => & self . left_highlight ,
36
+ ColumnId :: Right => & self . right_highlight ,
37
+ }
38
+ }
39
+
40
+ pub fn set_highlight ( & mut self , column : ColumnId , highlight : HighlightKind ) {
41
+ match column {
42
+ ColumnId :: Left => {
43
+ if highlight == self . left_highlight {
44
+ if highlight == self . right_highlight {
45
+ self . left_highlight = HighlightKind :: None ;
46
+ self . right_highlight = HighlightKind :: None ;
47
+ } else {
48
+ self . right_highlight = self . left_highlight . clone ( ) ;
49
+ }
50
+ } else {
51
+ self . left_highlight = highlight;
52
+ }
53
+ }
54
+ ColumnId :: Right => {
55
+ if highlight == self . right_highlight {
56
+ if highlight == self . left_highlight {
57
+ self . left_highlight = HighlightKind :: None ;
58
+ self . right_highlight = HighlightKind :: None ;
59
+ } else {
60
+ self . left_highlight = self . right_highlight . clone ( ) ;
61
+ }
62
+ } else {
63
+ self . right_highlight = highlight;
64
+ }
65
+ }
66
+ }
67
+ }
23
68
}
24
69
25
70
fn ins_hover_ui (
@@ -179,6 +224,7 @@ fn diff_text_ui(
179
224
ins_diff : & ObjInsDiff ,
180
225
appearance : & Appearance ,
181
226
ins_view_state : & mut FunctionViewState ,
227
+ column : ColumnId ,
182
228
space_width : f32 ,
183
229
response_cb : impl Fn ( Response ) -> Response ,
184
230
) {
@@ -243,7 +289,7 @@ fn diff_text_ui(
243
289
}
244
290
245
291
let len = label_text. len ( ) ;
246
- let highlight = ins_view_state. highlight == text;
292
+ let highlight = * ins_view_state. highlight ( column ) == text;
247
293
let mut response = Label :: new ( LayoutJob :: single_section (
248
294
label_text,
249
295
appearance. code_text_format ( base_color, highlight) ,
@@ -252,11 +298,7 @@ fn diff_text_ui(
252
298
. ui ( ui) ;
253
299
response = response_cb ( response) ;
254
300
if response. clicked ( ) {
255
- if highlight {
256
- ins_view_state. highlight = HighlightKind :: None ;
257
- } else {
258
- ins_view_state. highlight = text. into ( ) ;
259
- }
301
+ ins_view_state. set_highlight ( column, text. into ( ) ) ;
260
302
}
261
303
if len < pad_to {
262
304
ui. add_space ( ( pad_to - len) as f32 * space_width) ;
@@ -269,6 +311,7 @@ fn asm_row_ui(
269
311
symbol : & ObjSymbol ,
270
312
appearance : & Appearance ,
271
313
ins_view_state : & mut FunctionViewState ,
314
+ column : ColumnId ,
272
315
response_cb : impl Fn ( Response ) -> Response ,
273
316
) {
274
317
ui. spacing_mut ( ) . item_spacing . x = 0.0 ;
@@ -278,7 +321,16 @@ fn asm_row_ui(
278
321
}
279
322
let space_width = ui. fonts ( |f| f. glyph_width ( & appearance. code_font , ' ' ) ) ;
280
323
display_diff ( ins_diff, symbol. address , |text| {
281
- diff_text_ui ( ui, text, ins_diff, appearance, ins_view_state, space_width, & response_cb) ;
324
+ diff_text_ui (
325
+ ui,
326
+ text,
327
+ ins_diff,
328
+ appearance,
329
+ ins_view_state,
330
+ column,
331
+ space_width,
332
+ & response_cb,
333
+ ) ;
282
334
Ok :: < _ , ( ) > ( ( ) )
283
335
} )
284
336
. unwrap ( ) ;
@@ -290,6 +342,7 @@ fn asm_col_ui(
290
342
symbol_ref : SymbolRef ,
291
343
appearance : & Appearance ,
292
344
ins_view_state : & mut FunctionViewState ,
345
+ column : ColumnId ,
293
346
) {
294
347
let ( section, symbol) = obj. 0 . section_symbol ( symbol_ref) ;
295
348
let section = section. unwrap ( ) ;
@@ -305,7 +358,7 @@ fn asm_col_ui(
305
358
}
306
359
} ;
307
360
let ( _, response) = row. col ( |ui| {
308
- asm_row_ui ( ui, ins_diff, symbol, appearance, ins_view_state, response_cb) ;
361
+ asm_row_ui ( ui, ins_diff, symbol, appearance, ins_view_state, column , response_cb) ;
309
362
} ) ;
310
363
response_cb ( response) ;
311
364
}
@@ -344,12 +397,26 @@ fn asm_table_ui(
344
397
table. body ( |body| {
345
398
body. rows ( appearance. code_font . size , instructions_len, |mut row| {
346
399
if let ( Some ( left_obj) , Some ( left_symbol_ref) ) = ( left_obj, left_symbol) {
347
- asm_col_ui ( & mut row, left_obj, left_symbol_ref, appearance, ins_view_state) ;
400
+ asm_col_ui (
401
+ & mut row,
402
+ left_obj,
403
+ left_symbol_ref,
404
+ appearance,
405
+ ins_view_state,
406
+ ColumnId :: Left ,
407
+ ) ;
348
408
} else {
349
409
empty_col_ui ( & mut row) ;
350
410
}
351
411
if let ( Some ( right_obj) , Some ( right_symbol_ref) ) = ( right_obj, right_symbol) {
352
- asm_col_ui ( & mut row, right_obj, right_symbol_ref, appearance, ins_view_state) ;
412
+ asm_col_ui (
413
+ & mut row,
414
+ right_obj,
415
+ right_symbol_ref,
416
+ appearance,
417
+ ins_view_state,
418
+ ColumnId :: Right ,
419
+ ) ;
353
420
} else {
354
421
empty_col_ui ( & mut row) ;
355
422
}
0 commit comments