mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-08 21:17:59 +00:00
Reimplement colorized data relocation hover diffs (#182)
* Reimplement colorized data relocation hover diffs * Fix objdiff-wasm build Data diffing doesn't seem to be fully implemented in objdiff-wasm yet, so just putting placeholders in so it compiles. * Reloc hover: Add separators, override special color too
This commit is contained in:
@@ -5,7 +5,7 @@ use objdiff_core::{
|
||||
diff::{
|
||||
DataDiff, DataDiffKind, DataRelocationDiff,
|
||||
data::resolve_relocation,
|
||||
display::{ContextItem, HoverItem, relocation_context, relocation_hover},
|
||||
display::{ContextItem, HoverItem, HoverItemColor, relocation_context, relocation_hover},
|
||||
},
|
||||
obj::Object,
|
||||
};
|
||||
@@ -19,6 +19,7 @@ fn data_row_hover(obj: &Object, diffs: &[(DataDiff, Vec<DataRelocationDiff>)]) -
|
||||
let mut out = Vec::new();
|
||||
let reloc_diffs = diffs.iter().flat_map(|(_, reloc_diffs)| reloc_diffs);
|
||||
let mut prev_reloc = None;
|
||||
let mut first = true;
|
||||
for reloc_diff in reloc_diffs {
|
||||
let reloc = &reloc_diff.reloc;
|
||||
if prev_reloc == Some(reloc) {
|
||||
@@ -29,11 +30,16 @@ fn data_row_hover(obj: &Object, diffs: &[(DataDiff, Vec<DataRelocationDiff>)]) -
|
||||
}
|
||||
prev_reloc = Some(reloc);
|
||||
|
||||
// TODO: Change hover text color depending on Insert/Delete/Replace kind
|
||||
// let color = get_color_for_diff_kind(reloc_diff.kind, appearance);
|
||||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
out.push(HoverItem::Separator);
|
||||
}
|
||||
|
||||
let color = get_hover_item_color_for_diff_kind(reloc_diff.kind);
|
||||
|
||||
let reloc = resolve_relocation(&obj.symbols, reloc);
|
||||
out.append(&mut relocation_hover(obj, reloc));
|
||||
out.append(&mut relocation_hover(obj, reloc, Some(color)));
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -97,6 +103,15 @@ fn get_color_for_diff_kind(diff_kind: DataDiffKind, appearance: &Appearance) ->
|
||||
}
|
||||
}
|
||||
|
||||
fn get_hover_item_color_for_diff_kind(diff_kind: DataDiffKind) -> HoverItemColor {
|
||||
match diff_kind {
|
||||
DataDiffKind::None => HoverItemColor::Normal,
|
||||
DataDiffKind::Replace => HoverItemColor::Special,
|
||||
DataDiffKind::Delete => HoverItemColor::Delete,
|
||||
DataDiffKind::Insert => HoverItemColor::Insert,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn data_row_ui(
|
||||
ui: &mut egui::Ui,
|
||||
obj: Option<&Object>,
|
||||
|
||||
@@ -795,6 +795,8 @@ pub fn hover_items_ui(ui: &mut Ui, items: Vec<HoverItem>, appearance: &Appearanc
|
||||
if !label.is_empty() {
|
||||
let label_color = match color {
|
||||
HoverItemColor::Special => appearance.replace_color,
|
||||
HoverItemColor::Delete => appearance.delete_color,
|
||||
HoverItemColor::Insert => appearance.insert_color,
|
||||
_ => appearance.highlight_color,
|
||||
};
|
||||
write_text(&label, label_color, &mut job, appearance.code_font.clone());
|
||||
|
||||
@@ -512,7 +512,7 @@ pub fn symbol_hover_ui(
|
||||
ui.scope(|ui| {
|
||||
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
|
||||
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap);
|
||||
hover_items_ui(ui, symbol_hover(ctx.obj, symbol_idx, 0), appearance);
|
||||
hover_items_ui(ui, symbol_hover(ctx.obj, symbol_idx, 0, None), appearance);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user