Refactor state & config structs, various cleanup

This commit is contained in:
Luke Street
2023-08-09 21:53:04 -04:00
parent 94924047b7
commit 91d11c83d6
13 changed files with 736 additions and 876 deletions
+81 -313
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -3,7 +3,6 @@ use std::{collections::BTreeMap, mem::take};
use anyhow::Result; use anyhow::Result;
use crate::{ use crate::{
app::DiffConfig,
editops::{editops_find, LevEditType}, editops::{editops_find, LevEditType},
obj::{ obj::{
mips, ppc, ObjArchitecture, ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjInsArg, mips, ppc, ObjArchitecture, ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjInsArg,
@@ -373,7 +372,7 @@ fn find_section_and_symbol(obj: &ObjInfo, name: &str) -> Option<(usize, usize)>
None None
} }
pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffConfig) -> Result<()> { pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo) -> Result<()> {
for left_section in &mut left.sections { for left_section in &mut left.sections {
if left_section.kind == ObjSectionKind::Code { if left_section.kind == ObjSectionKind::Code {
for left_symbol in &mut left_section.symbols { for left_symbol in &mut left_section.symbols {
-44
View File
@@ -1,44 +0,0 @@
use std::sync::{mpsc::Receiver, Arc, RwLock};
use anyhow::{Error, Result};
use crate::{
app::{AppConfig, DiffConfig},
diff::diff_objs,
jobs::{start_job, update_status, Job, JobResult, JobState, Status},
obj::{elf, ObjInfo},
};
pub struct BinDiffResult {
pub first_obj: ObjInfo,
pub second_obj: ObjInfo,
}
fn run_build(
status: &Status,
cancel: Receiver<()>,
config: Arc<RwLock<AppConfig>>,
) -> Result<Box<BinDiffResult>> {
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
let target_path =
config.left_obj.as_ref().ok_or_else(|| Error::msg("Missing target obj path"))?;
let base_path = config.right_obj.as_ref().ok_or_else(|| Error::msg("Missing base obj path"))?;
update_status(status, "Loading target obj".to_string(), 0, 3, &cancel)?;
let mut left_obj = elf::read(target_path)?;
update_status(status, "Loading base obj".to_string(), 1, 3, &cancel)?;
let mut right_obj = elf::read(base_path)?;
update_status(status, "Performing diff".to_string(), 2, 3, &cancel)?;
diff_objs(&mut left_obj, &mut right_obj, &DiffConfig::default() /* TODO */)?;
update_status(status, "Complete".to_string(), 3, 3, &cancel)?;
Ok(Box::new(BinDiffResult { first_obj: left_obj, second_obj: right_obj }))
}
pub fn start_bindiff(config: Arc<RwLock<AppConfig>>) -> JobState {
start_job("Binary diff", Job::BinDiff, move |status, cancel| {
run_build(status, cancel, config).map(JobResult::BinDiff)
})
}
+1 -7
View File
@@ -9,12 +9,8 @@ use std::{
use anyhow::Result; use anyhow::Result;
use crate::jobs::{ use crate::jobs::{check_update::CheckUpdateResult, objdiff::ObjDiffResult, update::UpdateResult};
bindiff::BinDiffResult, check_update::CheckUpdateResult, objdiff::ObjDiffResult,
update::UpdateResult,
};
pub mod bindiff;
pub mod check_update; pub mod check_update;
pub mod objdiff; pub mod objdiff;
pub mod update; pub mod update;
@@ -22,7 +18,6 @@ pub mod update;
#[derive(Debug, Eq, PartialEq, Copy, Clone)] #[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum Job { pub enum Job {
ObjDiff, ObjDiff,
BinDiff,
CheckUpdate, CheckUpdate,
Update, Update,
} }
@@ -105,7 +100,6 @@ pub struct JobStatus {
pub enum JobResult { pub enum JobResult {
None, None,
ObjDiff(Box<ObjDiffResult>), ObjDiff(Box<ObjDiffResult>),
BinDiff(Box<BinDiffResult>),
CheckUpdate(Box<CheckUpdateResult>), CheckUpdate(Box<CheckUpdateResult>),
Update(Box<UpdateResult>), Update(Box<UpdateResult>),
} }
+4 -5
View File
@@ -9,7 +9,7 @@ use anyhow::{Context, Error, Result};
use time::OffsetDateTime; use time::OffsetDateTime;
use crate::{ use crate::{
app::{AppConfig, DiffConfig}, app::AppConfig,
diff::diff_objs, diff::diff_objs,
jobs::{start_job, update_status, Job, JobResult, JobState, Status}, jobs::{start_job, update_status, Job, JobResult, JobState, Status},
obj::{elf, ObjInfo}, obj::{elf, ObjInfo},
@@ -79,7 +79,6 @@ fn run_build(
status: &Status, status: &Status,
cancel: Receiver<()>, cancel: Receiver<()>,
config: Arc<RwLock<AppConfig>>, config: Arc<RwLock<AppConfig>>,
diff_config: DiffConfig,
) -> Result<Box<ObjDiffResult>> { ) -> Result<Box<ObjDiffResult>> {
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone(); let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
let obj_path = config.obj_path.as_ref().ok_or_else(|| Error::msg("Missing obj path"))?; let obj_path = config.obj_path.as_ref().ok_or_else(|| Error::msg("Missing obj path"))?;
@@ -129,15 +128,15 @@ fn run_build(
if let (Some(first_obj), Some(second_obj)) = (&mut first_obj, &mut second_obj) { if let (Some(first_obj), Some(second_obj)) = (&mut first_obj, &mut second_obj) {
update_status(status, "Performing diff".to_string(), 4, total, &cancel)?; update_status(status, "Performing diff".to_string(), 4, total, &cancel)?;
diff_objs(first_obj, second_obj, &diff_config)?; diff_objs(first_obj, second_obj)?;
} }
update_status(status, "Complete".to_string(), total, total, &cancel)?; update_status(status, "Complete".to_string(), total, total, &cancel)?;
Ok(Box::new(ObjDiffResult { first_status, second_status, first_obj, second_obj, time })) Ok(Box::new(ObjDiffResult { first_status, second_status, first_obj, second_obj, time }))
} }
pub fn start_build(config: Arc<RwLock<AppConfig>>, diff_config: DiffConfig) -> JobState { pub fn start_build(config: Arc<RwLock<AppConfig>>) -> JobState {
start_job("Object diff", Job::ObjDiff, move |status, cancel| { start_job("Object diff", Job::ObjDiff, move |status, cancel| {
run_build(status, cancel, config, diff_config).map(JobResult::ObjDiff) run_build(status, cancel, config).map(JobResult::ObjDiff)
}) })
} }
+103 -18
View File
@@ -1,6 +1,95 @@
use egui::Color32; use egui::{Color32, FontFamily, FontId, TextStyle};
use time::UtcOffset;
use crate::app::ViewState; #[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)]
pub struct Appearance {
pub ui_font: FontId,
pub code_font: FontId,
pub diff_colors: Vec<Color32>,
pub reverse_fn_order: bool,
pub theme: eframe::Theme,
// Applied by theme
#[serde(skip)]
pub text_color: Color32, // GRAY
#[serde(skip)]
pub emphasized_text_color: Color32, // LIGHT_GRAY
#[serde(skip)]
pub deemphasized_text_color: Color32, // DARK_GRAY
#[serde(skip)]
pub highlight_color: Color32, // WHITE
#[serde(skip)]
pub replace_color: Color32, // LIGHT_BLUE
#[serde(skip)]
pub insert_color: Color32, // GREEN
#[serde(skip)]
pub delete_color: Color32, // RED
// Global
#[serde(skip)]
pub utc_offset: UtcOffset,
}
impl Default for Appearance {
fn default() -> Self {
Self {
ui_font: FontId { size: 12.0, family: FontFamily::Proportional },
code_font: FontId { size: 14.0, family: FontFamily::Monospace },
diff_colors: DEFAULT_COLOR_ROTATION.to_vec(),
reverse_fn_order: false,
theme: eframe::Theme::Dark,
text_color: Color32::GRAY,
emphasized_text_color: Color32::LIGHT_GRAY,
deemphasized_text_color: Color32::DARK_GRAY,
highlight_color: Color32::WHITE,
replace_color: Color32::LIGHT_BLUE,
insert_color: Color32::GREEN,
delete_color: Color32::from_rgb(200, 40, 41),
utc_offset: UtcOffset::UTC,
}
}
}
impl Appearance {
pub fn apply(&mut self, style: &egui::Style) -> egui::Style {
let mut style = style.clone();
style.text_styles.insert(TextStyle::Body, FontId {
size: (self.ui_font.size * 0.75).floor(),
family: self.ui_font.family.clone(),
});
style.text_styles.insert(TextStyle::Body, self.ui_font.clone());
style.text_styles.insert(TextStyle::Button, self.ui_font.clone());
style.text_styles.insert(TextStyle::Heading, FontId {
size: (self.ui_font.size * 1.5).floor(),
family: self.ui_font.family.clone(),
});
style.text_styles.insert(TextStyle::Monospace, self.code_font.clone());
match self.theme {
eframe::Theme::Dark => {
style.visuals = egui::Visuals::dark();
self.text_color = Color32::GRAY;
self.emphasized_text_color = Color32::LIGHT_GRAY;
self.deemphasized_text_color = Color32::DARK_GRAY;
self.highlight_color = Color32::WHITE;
self.replace_color = Color32::LIGHT_BLUE;
self.insert_color = Color32::GREEN;
self.delete_color = Color32::from_rgb(200, 40, 41);
}
eframe::Theme::Light => {
style.visuals = egui::Visuals::light();
self.text_color = Color32::GRAY;
self.emphasized_text_color = Color32::DARK_GRAY;
self.deemphasized_text_color = Color32::LIGHT_GRAY;
self.highlight_color = Color32::BLACK;
self.replace_color = Color32::DARK_BLUE;
self.insert_color = Color32::DARK_GREEN;
self.delete_color = Color32::from_rgb(200, 40, 41);
}
}
style
}
}
pub const DEFAULT_COLOR_ROTATION: [Color32; 9] = [ pub const DEFAULT_COLOR_ROTATION: [Color32; 9] = [
Color32::from_rgb(255, 0, 255), Color32::from_rgb(255, 0, 255),
@@ -14,31 +103,27 @@ pub const DEFAULT_COLOR_ROTATION: [Color32; 9] = [
Color32::from_rgb(213, 138, 138), Color32::from_rgb(213, 138, 138),
]; ];
pub fn appearance_window(ctx: &egui::Context, view_state: &mut ViewState) { pub fn appearance_window(ctx: &egui::Context, show: &mut bool, appearance: &mut Appearance) {
egui::Window::new("Appearance").open(&mut view_state.show_view_config).show(ctx, |ui| { egui::Window::new("Appearance").open(show).show(ctx, |ui| {
egui::ComboBox::from_label("Theme") egui::ComboBox::from_label("Theme")
.selected_text(format!("{:?}", view_state.view_config.theme)) .selected_text(format!("{:?}", appearance.theme))
.show_ui(ui, |ui| { .show_ui(ui, |ui| {
ui.selectable_value(&mut view_state.view_config.theme, eframe::Theme::Dark, "Dark"); ui.selectable_value(&mut appearance.theme, eframe::Theme::Dark, "Dark");
ui.selectable_value( ui.selectable_value(&mut appearance.theme, eframe::Theme::Light, "Light");
&mut view_state.view_config.theme,
eframe::Theme::Light,
"Light",
);
}); });
ui.label("UI font:"); ui.label("UI font:");
egui::introspection::font_id_ui(ui, &mut view_state.view_config.ui_font); egui::introspection::font_id_ui(ui, &mut appearance.ui_font);
ui.separator(); ui.separator();
ui.label("Code font:"); ui.label("Code font:");
egui::introspection::font_id_ui(ui, &mut view_state.view_config.code_font); egui::introspection::font_id_ui(ui, &mut appearance.code_font);
ui.separator(); ui.separator();
ui.label("Diff colors:"); ui.label("Diff colors:");
if ui.button("Reset").clicked() { if ui.button("Reset").clicked() {
view_state.view_config.diff_colors = DEFAULT_COLOR_ROTATION.to_vec(); appearance.diff_colors = DEFAULT_COLOR_ROTATION.to_vec();
} }
let mut remove_at: Option<usize> = None; let mut remove_at: Option<usize> = None;
let num_colors = view_state.view_config.diff_colors.len(); let num_colors = appearance.diff_colors.len();
for (idx, color) in view_state.view_config.diff_colors.iter_mut().enumerate() { for (idx, color) in appearance.diff_colors.iter_mut().enumerate() {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.color_edit_button_srgba(color); ui.color_edit_button_srgba(color);
if num_colors > 1 && ui.small_button("-").clicked() { if num_colors > 1 && ui.small_button("-").clicked() {
@@ -47,10 +132,10 @@ pub fn appearance_window(ctx: &egui::Context, view_state: &mut ViewState) {
}); });
} }
if let Some(idx) = remove_at { if let Some(idx) = remove_at {
view_state.view_config.diff_colors.remove(idx); appearance.diff_colors.remove(idx);
} }
if ui.small_button("+").clicked() { if ui.small_button("+").clicked() {
view_state.view_config.diff_colors.push(Color32::BLACK); appearance.diff_colors.push(Color32::BLACK);
} }
}); });
} }
+326 -320
View File
File diff suppressed because it is too large Load Diff
+37 -33
View File
@@ -5,10 +5,13 @@ use egui_extras::{Column, TableBuilder};
use time::format_description; use time::format_description;
use crate::{ use crate::{
app::{SymbolReference, View, ViewConfig, ViewState}, jobs::{Job, JobQueue},
jobs::Job,
obj::{ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjSection}, obj::{ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjSection},
views::write_text, views::{
appearance::Appearance,
symbol_diff::{DiffViewState, SymbolReference, View},
write_text,
},
}; };
const BYTES_PER_ROW: usize = 16; const BYTES_PER_ROW: usize = 16;
@@ -17,29 +20,29 @@ fn find_section<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Opti
obj.sections.iter().find(|section| section.name == selected_symbol.section_name) obj.sections.iter().find(|section| section.name == selected_symbol.section_name)
} }
fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config: &ViewConfig) { fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], appearance: &Appearance) {
if diffs.iter().any(|d| d.kind != ObjDataDiffKind::None) { if diffs.iter().any(|d| d.kind != ObjDataDiffKind::None) {
ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color); ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color);
} }
let mut job = LayoutJob::default(); let mut job = LayoutJob::default();
write_text( write_text(
format!("{address:08X}: ").as_str(), format!("{address:08X}: ").as_str(),
config.text_color, appearance.text_color,
&mut job, &mut job,
config.code_font.clone(), appearance.code_font.clone(),
); );
let mut cur_addr = 0usize; let mut cur_addr = 0usize;
for diff in diffs { for diff in diffs {
let base_color = match diff.kind { let base_color = match diff.kind {
ObjDataDiffKind::None => config.text_color, ObjDataDiffKind::None => appearance.text_color,
ObjDataDiffKind::Replace => config.replace_color, ObjDataDiffKind::Replace => appearance.replace_color,
ObjDataDiffKind::Delete => config.delete_color, ObjDataDiffKind::Delete => appearance.delete_color,
ObjDataDiffKind::Insert => config.insert_color, ObjDataDiffKind::Insert => appearance.insert_color,
}; };
if diff.data.is_empty() { if diff.data.is_empty() {
let mut str = " ".repeat(diff.len); let mut str = " ".repeat(diff.len);
str.push_str(" ".repeat(diff.len / 8).as_str()); str.push_str(" ".repeat(diff.len / 8).as_str());
write_text(str.as_str(), base_color, &mut job, config.code_font.clone()); write_text(str.as_str(), base_color, &mut job, appearance.code_font.clone());
cur_addr += diff.len; cur_addr += diff.len;
} else { } else {
let mut text = String::new(); let mut text = String::new();
@@ -50,7 +53,7 @@ fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config:
text.push(' '); text.push(' ');
} }
} }
write_text(text.as_str(), base_color, &mut job, config.code_font.clone()); write_text(text.as_str(), base_color, &mut job, appearance.code_font.clone());
} }
} }
if cur_addr < BYTES_PER_ROW { if cur_addr < BYTES_PER_ROW {
@@ -58,22 +61,22 @@ fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config:
let mut str = " ".to_string(); let mut str = " ".to_string();
str.push_str(" ".repeat(n).as_str()); str.push_str(" ".repeat(n).as_str());
str.push_str(" ".repeat(n / 8).as_str()); str.push_str(" ".repeat(n / 8).as_str());
write_text(str.as_str(), config.text_color, &mut job, config.code_font.clone()); write_text(str.as_str(), appearance.text_color, &mut job, appearance.code_font.clone());
} }
write_text(" ", config.text_color, &mut job, config.code_font.clone()); write_text(" ", appearance.text_color, &mut job, appearance.code_font.clone());
for diff in diffs { for diff in diffs {
let base_color = match diff.kind { let base_color = match diff.kind {
ObjDataDiffKind::None => config.text_color, ObjDataDiffKind::None => appearance.text_color,
ObjDataDiffKind::Replace => config.replace_color, ObjDataDiffKind::Replace => appearance.replace_color,
ObjDataDiffKind::Delete => config.delete_color, ObjDataDiffKind::Delete => appearance.delete_color,
ObjDataDiffKind::Insert => config.insert_color, ObjDataDiffKind::Insert => appearance.insert_color,
}; };
if diff.data.is_empty() { if diff.data.is_empty() {
write_text( write_text(
" ".repeat(diff.len).as_str(), " ".repeat(diff.len).as_str(),
base_color, base_color,
&mut job, &mut job,
config.code_font.clone(), appearance.code_font.clone(),
); );
} else { } else {
let mut text = String::new(); let mut text = String::new();
@@ -85,7 +88,7 @@ fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config:
text.push('.'); text.push('.');
} }
} }
write_text(text.as_str(), base_color, &mut job, config.code_font.clone()); write_text(text.as_str(), base_color, &mut job, appearance.code_font.clone());
} }
} }
ui.add(Label::new(job).sense(Sense::click())); ui.add(Label::new(job).sense(Sense::click()));
@@ -133,7 +136,7 @@ fn data_table_ui(
left_obj: &ObjInfo, left_obj: &ObjInfo,
right_obj: &ObjInfo, right_obj: &ObjInfo,
selected_symbol: &SymbolReference, selected_symbol: &SymbolReference,
config: &ViewConfig, config: &Appearance,
) -> Option<()> { ) -> Option<()> {
let left_section = find_section(left_obj, selected_symbol)?; let left_section = find_section(left_obj, selected_symbol)?;
let right_section = find_section(right_obj, selected_symbol)?; let right_section = find_section(right_obj, selected_symbol)?;
@@ -161,10 +164,14 @@ fn data_table_ui(
Some(()) Some(())
} }
pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool { pub fn data_diff_ui(
ui: &mut egui::Ui,
jobs: &JobQueue,
state: &mut DiffViewState,
appearance: &Appearance,
) -> bool {
let mut rebuild = false; let mut rebuild = false;
let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) let (Some(result), Some(selected_symbol)) = (&state.build, &state.selected_symbol) else {
else {
return rebuild; return rebuild;
}; };
@@ -183,16 +190,13 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
ui.set_width(column_width); ui.set_width(column_width);
if ui.button("Back").clicked() { if ui.button("Back").clicked() {
view_state.current_view = View::SymbolDiff; state.current_view = View::SymbolDiff;
} }
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.colored_label( ui.colored_label(appearance.highlight_color, &selected_symbol.symbol_name);
view_state.view_config.highlight_color,
&selected_symbol.symbol_name,
);
ui.label("Diff target:"); ui.label("Diff target:");
}); });
}, },
@@ -212,8 +216,8 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
if view_state.jobs.is_running(Job::ObjDiff) { if jobs.is_running(Job::ObjDiff) {
ui.colored_label(view_state.view_config.replace_color, "Building…"); ui.colored_label(appearance.replace_color, "Building…");
} else { } else {
ui.label("Last built:"); ui.label("Last built:");
let format = let format =
@@ -221,7 +225,7 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
ui.label( ui.label(
result result
.time .time
.to_offset(view_state.utc_offset) .to_offset(appearance.utc_offset)
.format(&format) .format(&format)
.unwrap(), .unwrap(),
); );
@@ -251,7 +255,7 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
.resizable(false) .resizable(false)
.auto_shrink([false, false]) .auto_shrink([false, false])
.min_scrolled_height(available_height); .min_scrolled_height(available_height);
data_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config); data_table_ui(table, left_obj, right_obj, selected_symbol, appearance);
} }
rebuild rebuild
+17 -9
View File
@@ -1,17 +1,25 @@
use egui::TextStyle; use egui::TextStyle;
use crate::app::ViewState; use crate::views::appearance::Appearance;
pub fn demangle_window(ctx: &egui::Context, view_state: &mut ViewState) { #[derive(Default)]
egui::Window::new("Demangle").open(&mut view_state.show_demangle).show(ctx, |ui| { pub struct DemangleViewState {
ui.text_edit_singleline(&mut view_state.demangle_text); pub text: String,
}
pub fn demangle_window(
ctx: &egui::Context,
show: &mut bool,
state: &mut DemangleViewState,
appearance: &Appearance,
) {
egui::Window::new("Demangle").open(show).show(ctx, |ui| {
ui.text_edit_singleline(&mut state.text);
ui.add_space(10.0); ui.add_space(10.0);
if let Some(demangled) = if let Some(demangled) = cwdemangle::demangle(&state.text, &Default::default()) {
cwdemangle::demangle(&view_state.demangle_text, &Default::default())
{
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(TextStyle::Monospace); ui.style_mut().override_text_style = Some(TextStyle::Monospace);
ui.colored_label(view_state.view_config.replace_color, &demangled); ui.colored_label(appearance.replace_color, &demangled);
}); });
if ui.button("Copy").clicked() { if ui.button("Copy").clicked() {
ui.output_mut(|output| output.copied_text = demangled); ui.output_mut(|output| output.copied_text = demangled);
@@ -19,7 +27,7 @@ pub fn demangle_window(ctx: &egui::Context, view_state: &mut ViewState) {
} else { } else {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(TextStyle::Monospace); ui.style_mut().override_text_style = Some(TextStyle::Monospace);
ui.colored_label(view_state.view_config.replace_color, "[invalid]"); ui.colored_label(appearance.replace_color, "[invalid]");
}); });
} }
}); });
+95 -75
View File
@@ -8,13 +8,16 @@ use ppc750cl::Argument;
use time::format_description; use time::format_description;
use crate::{ use crate::{
app::{SymbolReference, View, ViewConfig, ViewState}, jobs::{Job, JobQueue},
jobs::Job,
obj::{ obj::{
ObjInfo, ObjIns, ObjInsArg, ObjInsArgDiff, ObjInsDiff, ObjInsDiffKind, ObjReloc, ObjInfo, ObjIns, ObjInsArg, ObjInsArgDiff, ObjInsDiff, ObjInsDiffKind, ObjReloc,
ObjRelocKind, ObjSymbol, ObjRelocKind, ObjSymbol,
}, },
views::{symbol_diff::match_color_for_symbol, write_text}, views::{
appearance::Appearance,
symbol_diff::{match_color_for_symbol, DiffViewState, SymbolReference, View},
write_text,
},
}; };
fn write_reloc_name( fn write_reloc_name(
@@ -22,10 +25,10 @@ fn write_reloc_name(
color: Color32, color: Color32,
job: &mut LayoutJob, job: &mut LayoutJob,
font_id: FontId, font_id: FontId,
config: &ViewConfig, appearance: &Appearance,
) { ) {
let name = reloc.target.demangled_name.as_ref().unwrap_or(&reloc.target.name); let name = reloc.target.demangled_name.as_ref().unwrap_or(&reloc.target.name);
write_text(name, config.emphasized_text_color, job, font_id.clone()); write_text(name, appearance.emphasized_text_color, job, font_id.clone());
match reloc.target.addend.cmp(&0i64) { match reloc.target.addend.cmp(&0i64) {
Ordering::Greater => { Ordering::Greater => {
write_text(&format!("+{:#X}", reloc.target.addend), color, job, font_id) write_text(&format!("+{:#X}", reloc.target.addend), color, job, font_id)
@@ -42,52 +45,52 @@ fn write_reloc(
color: Color32, color: Color32,
job: &mut LayoutJob, job: &mut LayoutJob,
font_id: FontId, font_id: FontId,
config: &ViewConfig, appearance: &Appearance,
) { ) {
match reloc.kind { match reloc.kind {
ObjRelocKind::PpcAddr16Lo => { ObjRelocKind::PpcAddr16Lo => {
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text("@l", color, job, font_id); write_text("@l", color, job, font_id);
} }
ObjRelocKind::PpcAddr16Hi => { ObjRelocKind::PpcAddr16Hi => {
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text("@h", color, job, font_id); write_text("@h", color, job, font_id);
} }
ObjRelocKind::PpcAddr16Ha => { ObjRelocKind::PpcAddr16Ha => {
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text("@ha", color, job, font_id); write_text("@ha", color, job, font_id);
} }
ObjRelocKind::PpcEmbSda21 => { ObjRelocKind::PpcEmbSda21 => {
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text("@sda21", color, job, font_id); write_text("@sda21", color, job, font_id);
} }
ObjRelocKind::MipsHi16 => { ObjRelocKind::MipsHi16 => {
write_text("%hi(", color, job, font_id.clone()); write_text("%hi(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id); write_text(")", color, job, font_id);
} }
ObjRelocKind::MipsLo16 => { ObjRelocKind::MipsLo16 => {
write_text("%lo(", color, job, font_id.clone()); write_text("%lo(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id); write_text(")", color, job, font_id);
} }
ObjRelocKind::MipsGot16 => { ObjRelocKind::MipsGot16 => {
write_text("%got(", color, job, font_id.clone()); write_text("%got(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id); write_text(")", color, job, font_id);
} }
ObjRelocKind::MipsCall16 => { ObjRelocKind::MipsCall16 => {
write_text("%call16(", color, job, font_id.clone()); write_text("%call16(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id); write_text(")", color, job, font_id);
} }
ObjRelocKind::MipsGpRel16 => { ObjRelocKind::MipsGpRel16 => {
write_text("%gp_rel(", color, job, font_id.clone()); write_text("%gp_rel(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone(), config); write_reloc_name(reloc, color, job, font_id.clone(), appearance);
write_text(")", color, job, font_id); write_text(")", color, job, font_id);
} }
ObjRelocKind::PpcRel24 | ObjRelocKind::PpcRel14 | ObjRelocKind::Mips26 => { ObjRelocKind::PpcRel24 | ObjRelocKind::PpcRel14 | ObjRelocKind::Mips26 => {
write_reloc_name(reloc, color, job, font_id, config); write_reloc_name(reloc, color, job, font_id, appearance);
} }
ObjRelocKind::Absolute | ObjRelocKind::MipsGpRel32 => { ObjRelocKind::Absolute | ObjRelocKind::MipsGpRel32 => {
write_text("[INVALID]", color, job, font_id); write_text("[INVALID]", color, job, font_id);
@@ -101,51 +104,51 @@ fn write_ins(
args: &[Option<ObjInsArgDiff>], args: &[Option<ObjInsArgDiff>],
base_addr: u32, base_addr: u32,
job: &mut LayoutJob, job: &mut LayoutJob,
config: &ViewConfig, appearance: &Appearance,
) { ) {
let base_color = match diff_kind { let base_color = match diff_kind {
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => { ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
config.text_color appearance.text_color
} }
ObjInsDiffKind::Replace => config.replace_color, ObjInsDiffKind::Replace => appearance.replace_color,
ObjInsDiffKind::Delete => config.delete_color, ObjInsDiffKind::Delete => appearance.delete_color,
ObjInsDiffKind::Insert => config.insert_color, ObjInsDiffKind::Insert => appearance.insert_color,
}; };
write_text( write_text(
&format!("{:<11}", ins.mnemonic), &format!("{:<11}", ins.mnemonic),
match diff_kind { match diff_kind {
ObjInsDiffKind::OpMismatch => config.replace_color, ObjInsDiffKind::OpMismatch => appearance.replace_color,
_ => base_color, _ => base_color,
}, },
job, job,
config.code_font.clone(), appearance.code_font.clone(),
); );
let mut writing_offset = false; let mut writing_offset = false;
for (i, arg) in ins.args.iter().enumerate() { for (i, arg) in ins.args.iter().enumerate() {
if i == 0 { if i == 0 {
write_text(" ", base_color, job, config.code_font.clone()); write_text(" ", base_color, job, appearance.code_font.clone());
} }
if i > 0 && !writing_offset { if i > 0 && !writing_offset {
write_text(", ", base_color, job, config.code_font.clone()); write_text(", ", base_color, job, appearance.code_font.clone());
} }
let color = if let Some(diff) = args.get(i).and_then(|a| a.as_ref()) { let color = if let Some(diff) = args.get(i).and_then(|a| a.as_ref()) {
config.diff_colors[diff.idx % config.diff_colors.len()] appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
} else { } else {
base_color base_color
}; };
match arg { match arg {
ObjInsArg::PpcArg(arg) => match arg { ObjInsArg::PpcArg(arg) => match arg {
Argument::Offset(val) => { Argument::Offset(val) => {
write_text(&format!("{val}"), color, job, config.code_font.clone()); write_text(&format!("{val}"), color, job, appearance.code_font.clone());
write_text("(", base_color, job, config.code_font.clone()); write_text("(", base_color, job, appearance.code_font.clone());
writing_offset = true; writing_offset = true;
continue; continue;
} }
Argument::Uimm(_) | Argument::Simm(_) => { Argument::Uimm(_) | Argument::Simm(_) => {
write_text(&format!("{arg}"), color, job, config.code_font.clone()); write_text(&format!("{arg}"), color, job, appearance.code_font.clone());
} }
_ => { _ => {
write_text(&format!("{arg}"), color, job, config.code_font.clone()); write_text(&format!("{arg}"), color, job, appearance.code_font.clone());
} }
}, },
ObjInsArg::Reloc => { ObjInsArg::Reloc => {
@@ -153,8 +156,8 @@ fn write_ins(
ins.reloc.as_ref().unwrap(), ins.reloc.as_ref().unwrap(),
base_color, base_color,
job, job,
config.code_font.clone(), appearance.code_font.clone(),
config, appearance,
); );
} }
ObjInsArg::RelocWithBase => { ObjInsArg::RelocWithBase => {
@@ -162,10 +165,10 @@ fn write_ins(
ins.reloc.as_ref().unwrap(), ins.reloc.as_ref().unwrap(),
base_color, base_color,
job, job,
config.code_font.clone(), appearance.code_font.clone(),
config, appearance,
); );
write_text("(", base_color, job, config.code_font.clone()); write_text("(", base_color, job, appearance.code_font.clone());
writing_offset = true; writing_offset = true;
continue; continue;
} }
@@ -174,7 +177,7 @@ fn write_ins(
str.strip_prefix('$').unwrap_or(str), str.strip_prefix('$').unwrap_or(str),
color, color,
job, job,
config.code_font.clone(), appearance.code_font.clone(),
); );
} }
ObjInsArg::MipsArgWithBase(str) => { ObjInsArg::MipsArgWithBase(str) => {
@@ -182,25 +185,25 @@ fn write_ins(
str.strip_prefix('$').unwrap_or(str), str.strip_prefix('$').unwrap_or(str),
color, color,
job, job,
config.code_font.clone(), appearance.code_font.clone(),
); );
write_text("(", base_color, job, config.code_font.clone()); write_text("(", base_color, job, appearance.code_font.clone());
writing_offset = true; writing_offset = true;
continue; continue;
} }
ObjInsArg::BranchOffset(offset) => { ObjInsArg::BranchOffset(offset) => {
let addr = offset + ins.address as i32 - base_addr as i32; let addr = offset + ins.address as i32 - base_addr as i32;
write_text(&format!("{addr:x}"), color, job, config.code_font.clone()); write_text(&format!("{addr:x}"), color, job, appearance.code_font.clone());
} }
} }
if writing_offset { if writing_offset {
write_text(")", base_color, job, config.code_font.clone()); write_text(")", base_color, job, appearance.code_font.clone());
writing_offset = false; writing_offset = false;
} }
} }
} }
fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns, config: &ViewConfig) { fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns, appearance: &Appearance) {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
@@ -226,16 +229,19 @@ fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns, config: &ViewConfig) {
if let Some(reloc) = &ins.reloc { if let Some(reloc) = &ins.reloc {
ui.label(format!("Relocation type: {:?}", reloc.kind)); ui.label(format!("Relocation type: {:?}", reloc.kind));
ui.colored_label(config.highlight_color, format!("Name: {}", reloc.target.name)); ui.colored_label(appearance.highlight_color, format!("Name: {}", reloc.target.name));
if let Some(section) = &reloc.target_section { if let Some(section) = &reloc.target_section {
ui.colored_label(config.highlight_color, format!("Section: {section}")); ui.colored_label(appearance.highlight_color, format!("Section: {section}"));
ui.colored_label( ui.colored_label(
config.highlight_color, appearance.highlight_color,
format!("Address: {:x}", reloc.target.address), format!("Address: {:x}", reloc.target.address),
); );
ui.colored_label(config.highlight_color, format!("Size: {:x}", reloc.target.size)); ui.colored_label(
appearance.highlight_color,
format!("Size: {:x}", reloc.target.size),
);
} else { } else {
ui.colored_label(config.highlight_color, "Extern".to_string()); ui.colored_label(appearance.highlight_color, "Extern".to_string());
} }
} }
}); });
@@ -306,7 +312,12 @@ fn find_symbol<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Optio
}) })
} }
fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, config: &ViewConfig) { fn asm_row_ui(
ui: &mut egui::Ui,
ins_diff: &ObjInsDiff,
symbol: &ObjSymbol,
appearance: &Appearance,
) {
if ins_diff.kind != ObjInsDiffKind::None { if ins_diff.kind != ObjInsDiffKind::None {
ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color); ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color);
} }
@@ -318,45 +329,50 @@ fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, conf
let base_color = match ins_diff.kind { let base_color = match ins_diff.kind {
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => { ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
config.text_color appearance.text_color
} }
ObjInsDiffKind::Replace => config.replace_color, ObjInsDiffKind::Replace => appearance.replace_color,
ObjInsDiffKind::Delete => config.delete_color, ObjInsDiffKind::Delete => appearance.delete_color,
ObjInsDiffKind::Insert => config.insert_color, ObjInsDiffKind::Insert => appearance.insert_color,
}; };
let mut pad = 6; let mut pad = 6;
if let Some(line) = ins.line { if let Some(line) = ins.line {
let line_str = format!("{line} "); let line_str = format!("{line} ");
write_text(&line_str, config.deemphasized_text_color, &mut job, config.code_font.clone()); write_text(
&line_str,
appearance.deemphasized_text_color,
&mut job,
appearance.code_font.clone(),
);
pad = 12 - line_str.len(); pad = 12 - line_str.len();
} }
write_text( write_text(
&format!("{:<1$}", format!("{:x}: ", ins.address - symbol.address as u32), pad), &format!("{:<1$}", format!("{:x}: ", ins.address - symbol.address as u32), pad),
base_color, base_color,
&mut job, &mut job,
config.code_font.clone(), appearance.code_font.clone(),
); );
if let Some(branch) = &ins_diff.branch_from { if let Some(branch) = &ins_diff.branch_from {
write_text( write_text(
"~> ", "~> ",
config.diff_colors[branch.branch_idx % config.diff_colors.len()], appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
&mut job, &mut job,
config.code_font.clone(), appearance.code_font.clone(),
); );
} else { } else {
write_text(" ", base_color, &mut job, config.code_font.clone()); write_text(" ", base_color, &mut job, appearance.code_font.clone());
} }
write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, symbol.address as u32, &mut job, config); write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, symbol.address as u32, &mut job, appearance);
if let Some(branch) = &ins_diff.branch_to { if let Some(branch) = &ins_diff.branch_to {
write_text( write_text(
" ~>", " ~>",
config.diff_colors[branch.branch_idx % config.diff_colors.len()], appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
&mut job, &mut job,
config.code_font.clone(), appearance.code_font.clone(),
); );
} }
ui.add(Label::new(job).sense(Sense::click())) ui.add(Label::new(job).sense(Sense::click()))
.on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins, config)) .on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins, appearance))
.context_menu(|ui| ins_context_menu(ui, ins)); .context_menu(|ui| ins_context_menu(ui, ins));
} }
@@ -365,21 +381,21 @@ fn asm_table_ui(
left_obj: &ObjInfo, left_obj: &ObjInfo,
right_obj: &ObjInfo, right_obj: &ObjInfo,
selected_symbol: &SymbolReference, selected_symbol: &SymbolReference,
config: &ViewConfig, appearance: &Appearance,
) -> Option<()> { ) -> Option<()> {
let left_symbol = find_symbol(left_obj, selected_symbol); let left_symbol = find_symbol(left_obj, selected_symbol);
let right_symbol = find_symbol(right_obj, selected_symbol); let right_symbol = find_symbol(right_obj, selected_symbol);
let instructions_len = left_symbol.or(right_symbol).map(|s| s.instructions.len())?; let instructions_len = left_symbol.or(right_symbol).map(|s| s.instructions.len())?;
table.body(|body| { table.body(|body| {
body.rows(config.code_font.size, instructions_len, |row_index, mut row| { body.rows(appearance.code_font.size, instructions_len, |row_index, mut row| {
row.col(|ui| { row.col(|ui| {
if let Some(symbol) = left_symbol { if let Some(symbol) = left_symbol {
asm_row_ui(ui, &symbol.instructions[row_index], symbol, config); asm_row_ui(ui, &symbol.instructions[row_index], symbol, appearance);
} }
}); });
row.col(|ui| { row.col(|ui| {
if let Some(symbol) = right_symbol { if let Some(symbol) = right_symbol {
asm_row_ui(ui, &symbol.instructions[row_index], symbol, config); asm_row_ui(ui, &symbol.instructions[row_index], symbol, appearance);
} }
}); });
}); });
@@ -387,10 +403,14 @@ fn asm_table_ui(
Some(()) Some(())
} }
pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool { pub fn function_diff_ui(
ui: &mut egui::Ui,
jobs: &JobQueue,
state: &mut DiffViewState,
appearance: &Appearance,
) -> bool {
let mut rebuild = false; let mut rebuild = false;
let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) let (Some(result), Some(selected_symbol)) = (&state.build, &state.selected_symbol) else {
else {
return rebuild; return rebuild;
}; };
@@ -409,15 +429,15 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
ui.set_width(column_width); ui.set_width(column_width);
if ui.button("Back").clicked() { if ui.button("Back").clicked() {
view_state.current_view = View::SymbolDiff; state.current_view = View::SymbolDiff;
} }
let demangled = demangle(&selected_symbol.symbol_name, &Default::default()); let demangled = demangle(&selected_symbol.symbol_name, &Default::default());
let name = demangled.as_deref().unwrap_or(&selected_symbol.symbol_name); let name = demangled.as_deref().unwrap_or(&selected_symbol.symbol_name);
let mut job = LayoutJob::simple( let mut job = LayoutJob::simple(
name.to_string(), name.to_string(),
view_state.view_config.code_font.clone(), appearance.code_font.clone(),
view_state.view_config.highlight_color, appearance.highlight_color,
column_width, column_width,
); );
job.wrap.break_anywhere = true; job.wrap.break_anywhere = true;
@@ -445,8 +465,8 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
if view_state.jobs.is_running(Job::ObjDiff) { if jobs.is_running(Job::ObjDiff) {
ui.colored_label(view_state.view_config.replace_color, "Building…"); ui.colored_label(appearance.replace_color, "Building…");
} else { } else {
ui.label("Last built:"); ui.label("Last built:");
let format = let format =
@@ -454,7 +474,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
ui.label( ui.label(
result result
.time .time
.to_offset(view_state.utc_offset) .to_offset(appearance.utc_offset)
.format(&format) .format(&format)
.unwrap(), .unwrap(),
); );
@@ -471,7 +491,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
.and_then(|symbol| symbol.match_percent) .and_then(|symbol| symbol.match_percent)
{ {
ui.colored_label( ui.colored_label(
match_color_for_symbol(match_percent, &view_state.view_config), match_color_for_symbol(match_percent, appearance),
&format!("{match_percent:.0}%"), &format!("{match_percent:.0}%"),
); );
} else { } else {
@@ -495,7 +515,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
.resizable(false) .resizable(false)
.auto_shrink([false, false]) .auto_shrink([false, false])
.min_scrolled_height(available_height); .min_scrolled_height(available_height);
asm_table_ui(table, left_obj, right_obj, selected_symbol, &view_state.view_config); asm_table_ui(table, left_obj, right_obj, selected_symbol, appearance);
} }
rebuild rebuild
} }
+5 -5
View File
@@ -1,12 +1,12 @@
use egui::{ProgressBar, Widget}; use egui::{ProgressBar, Widget};
use crate::app::ViewState; use crate::{jobs::JobQueue, views::appearance::Appearance};
pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) { pub fn jobs_ui(ui: &mut egui::Ui, jobs: &mut JobQueue, appearance: &Appearance) {
ui.label("Jobs"); ui.label("Jobs");
let mut remove_job: Option<usize> = None; let mut remove_job: Option<usize> = None;
for job in view_state.jobs.iter_mut() { for job in jobs.iter_mut() {
let Ok(status) = job.status.read() else { let Ok(status) = job.status.read() else {
continue; continue;
}; };
@@ -33,7 +33,7 @@ pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
if let Some(err) = &status.error { if let Some(err) = &status.error {
let err_string = err.to_string(); let err_string = err.to_string();
ui.colored_label( ui.colored_label(
view_state.view_config.delete_color, appearance.delete_color,
if err_string.len() > STATUS_LENGTH - 10 { if err_string.len() > STATUS_LENGTH - 10 {
format!("Error: {}", &err_string[0..STATUS_LENGTH - 10]) format!("Error: {}", &err_string[0..STATUS_LENGTH - 10])
} else { } else {
@@ -51,6 +51,6 @@ pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
} }
if let Some(idx) = remove_job { if let Some(idx) = remove_job {
view_state.jobs.remove(idx); jobs.remove(idx);
} }
} }
+1
View File
@@ -8,6 +8,7 @@ pub(crate) mod function_diff;
pub(crate) mod jobs; pub(crate) mod jobs;
pub(crate) mod symbol_diff; pub(crate) mod symbol_diff;
#[inline]
fn write_text(str: &str, color: Color32, job: &mut LayoutJob, font_id: FontId) { fn write_text(str: &str, color: Color32, job: &mut LayoutJob, font_id: FontId) {
job.append(str, 0.0, TextFormat::simple(font_id, color)); job.append(str, 0.0, TextFormat::simple(font_id, color));
} }
+65 -45
View File
@@ -5,19 +5,41 @@ use egui::{
use egui_extras::{Size, StripBuilder}; use egui_extras::{Size, StripBuilder};
use crate::{ use crate::{
app::{SymbolReference, View, ViewConfig, ViewState}, jobs::objdiff::{BuildStatus, ObjDiffResult},
jobs::objdiff::BuildStatus,
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags}, obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
views::write_text, views::{appearance::Appearance, write_text},
}; };
pub fn match_color_for_symbol(match_percent: f32, config: &ViewConfig) -> Color32 { pub struct SymbolReference {
pub symbol_name: String,
pub section_name: String,
}
#[allow(clippy::enum_variant_names)]
#[derive(Default, Eq, PartialEq)]
pub enum View {
#[default]
SymbolDiff,
FunctionDiff,
DataDiff,
}
#[derive(Default)]
pub struct DiffViewState {
pub build: Option<Box<ObjDiffResult>>,
pub current_view: View,
pub highlighted_symbol: Option<String>,
pub selected_symbol: Option<SymbolReference>,
pub search: String,
}
pub fn match_color_for_symbol(match_percent: f32, appearance: &Appearance) -> Color32 {
if match_percent == 100.0 { if match_percent == 100.0 {
config.insert_color appearance.insert_color
} else if match_percent >= 50.0 { } else if match_percent >= 50.0 {
config.replace_color appearance.replace_color
} else { } else {
config.delete_color appearance.delete_color
} }
} }
@@ -39,17 +61,20 @@ fn symbol_context_menu_ui(ui: &mut Ui, symbol: &ObjSymbol) {
}); });
} }
fn symbol_hover_ui(ui: &mut Ui, symbol: &ObjSymbol, config: &ViewConfig) { fn symbol_hover_ui(ui: &mut Ui, symbol: &ObjSymbol, appearance: &Appearance) {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.colored_label(config.highlight_color, format!("Name: {}", symbol.name)); ui.colored_label(appearance.highlight_color, format!("Name: {}", symbol.name));
ui.colored_label(config.highlight_color, format!("Address: {:x}", symbol.address)); ui.colored_label(appearance.highlight_color, format!("Address: {:x}", symbol.address));
if symbol.size_known { if symbol.size_known {
ui.colored_label(config.highlight_color, format!("Size: {:x}", symbol.size)); ui.colored_label(appearance.highlight_color, format!("Size: {:x}", symbol.size));
} else { } else {
ui.colored_label(config.highlight_color, format!("Size: {:x} (assumed)", symbol.size)); ui.colored_label(
appearance.highlight_color,
format!("Size: {:x} (assumed)", symbol.size),
);
} }
}); });
} }
@@ -61,7 +86,7 @@ fn symbol_ui(
highlighted_symbol: &mut Option<String>, highlighted_symbol: &mut Option<String>,
selected_symbol: &mut Option<SymbolReference>, selected_symbol: &mut Option<SymbolReference>,
current_view: &mut View, current_view: &mut View,
config: &ViewConfig, appearance: &Appearance,
) { ) {
let mut job = LayoutJob::default(); let mut job = LayoutJob::default();
let name: &str = let name: &str =
@@ -70,38 +95,38 @@ fn symbol_ui(
if let Some(sym) = highlighted_symbol { if let Some(sym) = highlighted_symbol {
selected = sym == &symbol.name; selected = sym == &symbol.name;
} }
write_text("[", config.text_color, &mut job, config.code_font.clone()); write_text("[", appearance.text_color, &mut job, appearance.code_font.clone());
if symbol.flags.0.contains(ObjSymbolFlags::Common) { if symbol.flags.0.contains(ObjSymbolFlags::Common) {
write_text( write_text(
"c", "c",
config.replace_color, /* Color32::from_rgb(0, 255, 255) */ appearance.replace_color, /* Color32::from_rgb(0, 255, 255) */
&mut job, &mut job,
config.code_font.clone(), appearance.code_font.clone(),
); );
} else if symbol.flags.0.contains(ObjSymbolFlags::Global) { } else if symbol.flags.0.contains(ObjSymbolFlags::Global) {
write_text("g", config.insert_color, &mut job, config.code_font.clone()); write_text("g", appearance.insert_color, &mut job, appearance.code_font.clone());
} else if symbol.flags.0.contains(ObjSymbolFlags::Local) { } else if symbol.flags.0.contains(ObjSymbolFlags::Local) {
write_text("l", config.text_color, &mut job, config.code_font.clone()); write_text("l", appearance.text_color, &mut job, appearance.code_font.clone());
} }
if symbol.flags.0.contains(ObjSymbolFlags::Weak) { if symbol.flags.0.contains(ObjSymbolFlags::Weak) {
write_text("w", config.text_color, &mut job, config.code_font.clone()); write_text("w", appearance.text_color, &mut job, appearance.code_font.clone());
} }
write_text("] ", config.text_color, &mut job, config.code_font.clone()); write_text("] ", appearance.text_color, &mut job, appearance.code_font.clone());
if let Some(match_percent) = symbol.match_percent { if let Some(match_percent) = symbol.match_percent {
write_text("(", config.text_color, &mut job, config.code_font.clone()); write_text("(", appearance.text_color, &mut job, appearance.code_font.clone());
write_text( write_text(
&format!("{match_percent:.0}%"), &format!("{match_percent:.0}%"),
match_color_for_symbol(match_percent, config), match_color_for_symbol(match_percent, appearance),
&mut job, &mut job,
config.code_font.clone(), appearance.code_font.clone(),
); );
write_text(") ", config.text_color, &mut job, config.code_font.clone()); write_text(") ", appearance.text_color, &mut job, appearance.code_font.clone());
} }
write_text(name, config.highlight_color, &mut job, config.code_font.clone()); write_text(name, appearance.highlight_color, &mut job, appearance.code_font.clone());
let response = SelectableLabel::new(selected, job) let response = SelectableLabel::new(selected, job)
.ui(ui) .ui(ui)
.context_menu(|ui| symbol_context_menu_ui(ui, symbol)) .context_menu(|ui| symbol_context_menu_ui(ui, symbol))
.on_hover_ui_at_pointer(|ui| symbol_hover_ui(ui, symbol, config)); .on_hover_ui_at_pointer(|ui| symbol_hover_ui(ui, symbol, appearance));
if response.clicked() { if response.clicked() {
if let Some(section) = section { if let Some(section) = section {
if section.kind == ObjSectionKind::Code { if section.kind == ObjSectionKind::Code {
@@ -141,7 +166,7 @@ fn symbol_list_ui(
selected_symbol: &mut Option<SymbolReference>, selected_symbol: &mut Option<SymbolReference>,
current_view: &mut View, current_view: &mut View,
lower_search: &str, lower_search: &str,
config: &ViewConfig, appearance: &Appearance,
) { ) {
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| { ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
ui.scope(|ui| { ui.scope(|ui| {
@@ -158,7 +183,7 @@ fn symbol_list_ui(
highlighted_symbol, highlighted_symbol,
selected_symbol, selected_symbol,
current_view, current_view,
config, appearance,
); );
} }
}); });
@@ -168,7 +193,7 @@ fn symbol_list_ui(
CollapsingHeader::new(format!("{} ({:x})", section.name, section.size)) CollapsingHeader::new(format!("{} ({:x})", section.name, section.size))
.default_open(true) .default_open(true)
.show(ui, |ui| { .show(ui, |ui| {
if section.kind == ObjSectionKind::Code && config.reverse_fn_order { if section.kind == ObjSectionKind::Code && appearance.reverse_fn_order {
for symbol in section.symbols.iter().rev() { for symbol in section.symbols.iter().rev() {
if !symbol_matches_search(symbol, lower_search) { if !symbol_matches_search(symbol, lower_search) {
continue; continue;
@@ -180,7 +205,7 @@ fn symbol_list_ui(
highlighted_symbol, highlighted_symbol,
selected_symbol, selected_symbol,
current_view, current_view,
config, appearance,
); );
} }
} else { } else {
@@ -195,7 +220,7 @@ fn symbol_list_ui(
highlighted_symbol, highlighted_symbol,
selected_symbol, selected_symbol,
current_view, current_view,
config, appearance,
); );
} }
} }
@@ -205,25 +230,20 @@ fn symbol_list_ui(
}); });
} }
fn build_log_ui(ui: &mut Ui, status: &BuildStatus, config: &ViewConfig) { fn build_log_ui(ui: &mut Ui, status: &BuildStatus, appearance: &Appearance) {
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| { ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.colored_label(config.replace_color, &status.log); ui.colored_label(appearance.replace_color, &status.log);
}); });
}); });
} }
pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) { pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appearance) {
let (Some(result), highlighted_symbol, selected_symbol, current_view, search) = ( let DiffViewState { build, current_view, highlighted_symbol, selected_symbol, search } = state;
&view_state.build, let Some(result) = build else {
&mut view_state.highlighted_symbol,
&mut view_state.selected_symbol,
&mut view_state.current_view,
&mut view_state.search,
) else {
return; return;
}; };
@@ -297,11 +317,11 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
selected_symbol, selected_symbol,
current_view, current_view,
&lower_search, &lower_search,
&view_state.view_config, appearance,
); );
} }
} else { } else {
build_log_ui(ui, &result.first_status, &view_state.view_config); build_log_ui(ui, &result.first_status, appearance);
} }
}); });
}); });
@@ -316,11 +336,11 @@ pub fn symbol_diff_ui(ui: &mut Ui, view_state: &mut ViewState) {
selected_symbol, selected_symbol,
current_view, current_view,
&lower_search, &lower_search,
&view_state.view_config, appearance,
); );
} }
} else { } else {
build_log_ui(ui, &result.second_status, &view_state.view_config); build_log_ui(ui, &result.second_status, appearance);
} }
}); });
}); });